aboutsummaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2020-07-25 18:40:31 +0300
committerTulir Asokan <tulir@maunium.net>2020-07-25 18:40:31 +0300
commitead7e0bf1d9c584224c1738b32ad26e314957220 (patch)
treefb5c4fe731dc40b864417c59b48741466595248b /ui
parent341f8829d67b197ece20fe1cb0da929486665853 (diff)
Make verification modal wait for confirmation
Diffstat (limited to 'ui')
-rw-r--r--ui/commands.go18
-rw-r--r--ui/verification-modal.go58
2 files changed, 58 insertions, 18 deletions
diff --git a/ui/commands.go b/ui/commands.go
index a10445f..a6309fd 100644
--- a/ui/commands.go
+++ b/ui/commands.go
@@ -498,18 +498,20 @@ func cmdVerify(cmd *Command) {
if device == nil {
return
}
+ if device.Trust == crypto.TrustStateVerified {
+ cmd.Reply("That device is already verified")
+ return
+ }
if len(cmd.Args) == 2 {
mach := cmd.Matrix.Crypto().(*crypto.OlmMachine)
- timeout := 60 * time.Second
- err := mach.NewSASVerificationWith(device, "", timeout, true)
+ mach.DefaultSASTimeout = 120 * time.Second
+ modal := NewVerificationModal(cmd.MainView, device, mach.DefaultSASTimeout)
+ cmd.MainView.ShowModal(modal)
+ err := mach.NewSimpleSASVerificationWith(device, modal)
if err != nil {
cmd.Reply("Failed to start interactive verification: %v", err)
return
}
- modal := NewVerificationModal(cmd.MainView, device, timeout)
- mach.VerifySASEmojisMatch = modal.VerifyEmojisMatch
- mach.VerifySASNumbersMatch = modal.VerifyNumbersMatch
- cmd.MainView.ShowModal(modal)
} else {
fingerprint := strings.Join(cmd.Args[2:], "")
if string(device.SigningKey) != fingerprint {
@@ -547,6 +549,10 @@ func cmdBlacklist(cmd *Command) {
if device == nil {
return
}
+ if device.Trust == crypto.TrustStateBlacklisted {
+ cmd.Reply("That device is already blacklisted")
+ return
+ }
action := "blacklisted"
if device.Trust == crypto.TrustStateVerified {
action = "unverified and blacklisted"
diff --git a/ui/verification-modal.go b/ui/verification-modal.go
index fd77777..e47006e 100644
--- a/ui/verification-modal.go
+++ b/ui/verification-modal.go
@@ -27,6 +27,7 @@ import (
"maunium.net/go/gomuks/debug"
"maunium.net/go/mautrix/crypto"
+ "maunium.net/go/mautrix/event"
)
type EmojiView struct {
@@ -59,6 +60,8 @@ func (e *EmojiView) Draw(screen mauview.Screen) {
type VerificationModal struct {
mauview.Component
+ device *crypto.DeviceIdentity
+
container *mauview.Box
waitingBar *mauview.ProgressBar
@@ -68,6 +71,7 @@ type VerificationModal struct {
stopWaiting chan struct{}
confirmChan chan bool
+ done bool
parent *MainView
}
@@ -75,8 +79,10 @@ type VerificationModal struct {
func NewVerificationModal(mainView *MainView, device *crypto.DeviceIdentity, timeout time.Duration) *VerificationModal {
vm := &VerificationModal{
parent: mainView,
+ device: device,
stopWaiting: make(chan struct{}),
confirmChan: make(chan bool),
+ done: false,
}
progress := int(timeout.Seconds())
@@ -115,8 +121,6 @@ func (vm *VerificationModal) decrementWaitingBar(progress int) {
select {
case <-time.Tick(time.Second):
if progress <= 0 {
- vm.parent.HideModal()
- vm.parent.parent.Render()
return
}
progress--
@@ -124,13 +128,14 @@ func (vm *VerificationModal) decrementWaitingBar(progress int) {
vm.parent.parent.Render()
case <-vm.stopWaiting:
vm.waitingBar.SetIndeterminate(true)
- break
+ vm.parent.parent.app.SetRedrawTicker(100 * time.Millisecond)
+ return
}
}
}
-func (vm *VerificationModal) VerifyEmojisMatch(emojis [7]crypto.VerificationEmoji, _ *crypto.DeviceIdentity) bool {
- vm.infoText.SetText("Check if the other device is showing the same emojis as below, then type \"yes\" to accept, or \"no\" to reject")
+func (vm *VerificationModal) VerifyEmojisMatch(emojis [7]crypto.VerificationEmoji) bool {
+ vm.infoText.SetText("Check if the other device is showing the\nsame emojis as below, then type \"yes\" to\naccept, or \"no\" to reject")
vm.inputBar.
SetTextColor(tcell.ColorWhite).
SetBackgroundColor(tcell.ColorDarkCyan).
@@ -140,14 +145,14 @@ func (vm *VerificationModal) VerifyEmojisMatch(emojis [7]crypto.VerificationEmoj
vm.parent.parent.Render()
vm.stopWaiting <- struct{}{}
confirm := <-vm.confirmChan
- // TODO this should hook into cancel/success of the verification and display a success message instead of just closing
- vm.parent.HideModal()
+ vm.emojiText.Emojis = nil
+ vm.infoText.SetText(fmt.Sprintf("Waiting for %s to accept", vm.device.UserID))
vm.parent.parent.Render()
return confirm
}
-func (vm *VerificationModal) VerifyNumbersMatch(numbers [3]uint, _ *crypto.DeviceIdentity) bool {
- vm.infoText.SetText("Check if the other device is showing the same numbers as below, then type \"yes\" to accept, or \"no\" to reject")
+func (vm *VerificationModal) VerifyNumbersMatch(numbers [3]uint) bool {
+ vm.infoText.SetText("Check if the other device is showing the\nsame numbers as below, then type \"yes\" to\naccept, or \"no\" to reject")
vm.inputBar.
SetTextColor(tcell.ColorWhite).
SetBackgroundColor(tcell.ColorDarkCyan).
@@ -157,14 +162,42 @@ func (vm *VerificationModal) VerifyNumbersMatch(numbers [3]uint, _ *crypto.Devic
vm.parent.parent.Render()
vm.stopWaiting <- struct{}{}
confirm := <-vm.confirmChan
- // TODO this should hook into cancel/success of the verification and display a success message instead of just closing
- vm.parent.HideModal()
+ vm.emojiText.Numbers = nil
+ vm.infoText.SetText(fmt.Sprintf("Waiting for %s to accept", vm.device.UserID))
vm.parent.parent.Render()
return confirm
}
+func (vm *VerificationModal) OnCancel(cancelledByUs bool, reason string, _ event.VerificationCancelCode) {
+ vm.waitingBar.SetIndeterminate(false).SetMax(100).SetProgress(100)
+ vm.parent.parent.app.SetRedrawTicker(1 * time.Minute)
+ if cancelledByUs {
+ vm.infoText.SetText(fmt.Sprintf("Verification failed: %s", reason))
+ } else {
+ vm.infoText.SetText(fmt.Sprintf("Verification cancelled by %s: %s", vm.device.UserID, reason))
+ }
+ vm.inputBar.SetPlaceholder("Press enter to close dialog")
+ vm.done = true
+ vm.parent.parent.Render()
+}
+
+func (vm *VerificationModal) OnSuccess() {
+ vm.waitingBar.SetIndeterminate(false).SetMax(100).SetProgress(100)
+ vm.parent.parent.app.SetRedrawTicker(1 * time.Minute)
+ vm.infoText.SetText(fmt.Sprintf("Successfully verified %s (%s) of %s", vm.device.Name, vm.device.DeviceID, vm.device.UserID))
+ vm.inputBar.SetPlaceholder("Press enter to close dialog")
+ vm.done = true
+ vm.parent.parent.Render()
+}
+
func (vm *VerificationModal) OnKeyEvent(event mauview.KeyEvent) bool {
- if vm.emojiText.Emojis == nil && vm.emojiText.Numbers == nil {
+ if vm.done {
+ if event.Key() == tcell.KeyEnter || event.Key() == tcell.KeyEsc {
+ vm.parent.HideModal()
+ return true
+ }
+ return false
+ } else if vm.emojiText.Emojis == nil && vm.emojiText.Numbers == nil {
debug.Print("Ignoring pre-emoji key event")
return false
}
@@ -177,6 +210,7 @@ func (vm *VerificationModal) OnKeyEvent(event mauview.KeyEvent) bool {
debug.Print("Rejecting verification")
vm.confirmChan <- false
}
+ vm.inputBar.SetTextAndMoveCursor("")
return true
} else {
return vm.inputBar.OnKeyEvent(event)