From f14717da189123bcef9d0ebd52fb8864aa4aa365 Mon Sep 17 00:00:00 2001 From: Pascal Precht <445106+PascalPrecht@users.noreply.github.com> Date: Tue, 17 May 2022 16:09:22 +0200 Subject: [PATCH] feat: handling `mailserver.not.working` signal This makes Status Desktop aware of the `mailserver.not.working` signal. When emitted by status-go, desktop will show a popup that informs the user about the connection failure. Furthermore, users can then decide to either retry (same as just closing the popup as retrying already happens by default), or pick another pinned mailserver, for which they'll get redirected to the messaging settings panel. Closes #5166 --- .../signals/remote_signals/mailserver.nim | 6 +++ .../signals/remote_signals/signal_type.nim | 1 + src/app/modules/main/controller.nim | 3 ++ src/app/modules/main/io_interface.nim | 3 ++ src/app/modules/main/module.nim | 3 ++ src/app/modules/main/view.nim | 5 ++ .../service/mailservers/service.nim | 5 ++ src/backend/signals.nim | 1 + ui/app/mainui/AppMain.qml | 48 +++++++++++++++++++ 9 files changed, 75 insertions(+) diff --git a/src/app/core/signals/remote_signals/mailserver.nim b/src/app/core/signals/remote_signals/mailserver.nim index 926cc96bfa..95479b24e6 100644 --- a/src/app/core/signals/remote_signals/mailserver.nim +++ b/src/app/core/signals/remote_signals/mailserver.nim @@ -36,6 +36,8 @@ type MailserverAvailableSignal* = ref object of Signal type MailserverChangedSignal* = ref object of Signal address*: string +type MailserverNotWorkingSignal* = ref object of Signal + proc fromEvent*(T: type MailserverRequestCompletedSignal, jsonSignal: JsonNode): MailserverRequestCompletedSignal = result = MailserverRequestCompletedSignal() result.signalType = SignalType.MailserverRequestCompleted @@ -86,3 +88,7 @@ proc fromEvent*(T: type MailserverChangedSignal, jsonSignal: JsonNode): Mailserv result = MailserverChangedSignal() result.signalType = SignalType.MailserverChanged result.address = jsonSignal["event"]{"address"}.getStr() + +proc fromEvent*(T: type MailserverNotWorkingSignal, jsonSignal: JsonNode): MailserverNotWorkingSignal = + result = MailserverNotWorkingSignal() + result.signalType = SignalType.MailseverNotWorking diff --git a/src/app/core/signals/remote_signals/signal_type.nim b/src/app/core/signals/remote_signals/signal_type.nim index 5da4d0828c..16ff444107 100644 --- a/src/app/core/signals/remote_signals/signal_type.nim +++ b/src/app/core/signals/remote_signals/signal_type.nim @@ -29,6 +29,7 @@ type SignalType* {.pure.} = enum KeycardConnected = "keycard.connected" MailserverAvailable = "mailserver.available" MailserverChanged = "mailserver.changed" + MailserverNotWorking = "mailserver.not.working" HistoryArchivesProtocolEnabled = "community.historyArchivesProtocolEnabled" HistoryArchivesProtocolDisabled = "community.historyArchivesProtocolDisabled" CreatingHistoryArchives = "community.creatingHistoryArchives" diff --git a/src/app/modules/main/controller.nim b/src/app/modules/main/controller.nim index 08e14aadfa..5d04919ffa 100644 --- a/src/app/modules/main/controller.nim +++ b/src/app/modules/main/controller.nim @@ -81,6 +81,9 @@ proc init*(self: Controller) = # requestAllHistoricMessagesResult # requestMissingCommunityInfos + self.events.on(SIGNAL_MAILSERVER_NOT_WORKING) do(e: Args): + self.delegate.emitMailserverNotWorking() + if(defined(macosx)): let account = self.accountsService.getLoggedInAccount() singletonInstance.localAccountSettings.setFileName(account.name) diff --git a/src/app/modules/main/io_interface.nim b/src/app/modules/main/io_interface.nim index 38fff913b8..7923300200 100644 --- a/src/app/modules/main/io_interface.nim +++ b/src/app/modules/main/io_interface.nim @@ -90,6 +90,9 @@ method emitStoringPasswordError*(self: AccessInterface, errorDescription: string method emitStoringPasswordSuccess*(self: AccessInterface) {.base.} = raise newException(ValueError, "No implementation available") +method emitMailserverNotWorking*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") + method activeSectionSet*(self: AccessInterface, sectionId: string) {.base.} = raise newException(ValueError, "No implementation available") diff --git a/src/app/modules/main/module.nim b/src/app/modules/main/module.nim index 6fdd7f6a53..3bfbc9eb7f 100644 --- a/src/app/modules/main/module.nim +++ b/src/app/modules/main/module.nim @@ -444,6 +444,9 @@ method emitStoringPasswordError*[T](self: Module[T], errorDescription: string) = method emitStoringPasswordSuccess*[T](self: Module[T]) = self.view.emitStoringPasswordSuccess() +method emitMailserverNotWorking*[T](self: Module[T]) = + self.view.emitMailserverNotWorking() + method getActiveSectionId*[T](self: Module[T]): string = return self.controller.getActiveSectionId() diff --git a/src/app/modules/main/view.nim b/src/app/modules/main/view.nim index f28c37f403..76893f0c63 100644 --- a/src/app/modules/main/view.nim +++ b/src/app/modules/main/view.nim @@ -94,6 +94,11 @@ QtObject: proc emitStoringPasswordSuccess*(self: View) = self.storingPasswordSuccess() + proc mailserverNotWorking*(self:View) {.signal.} + + proc emitMailservernotWorking*(self: View) = + self.mailserverNotWorking() + proc activeSection*(self: View): ActiveSection = return self.activeSection diff --git a/src/app_service/service/mailservers/service.nim b/src/app_service/service/mailservers/service.nim index 6a43989615..203e9df9d2 100644 --- a/src/app_service/service/mailservers/service.nim +++ b/src/app_service/service/mailservers/service.nim @@ -28,6 +28,7 @@ type # Signals which may be emitted by this service: const SIGNAL_ACTIVE_MAILSERVER_CHANGED* = "activeMailserverChanged" const SIGNAL_MAILSERVER_AVAILABLE* = "mailserverAvailable" +const SIGNAL_MAILSERVER_NOT_WORKING* = "mailserverNotWorking" const requestMoreMessagesTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} = let arg = decode[RequestMoreMessagesTaskArg](argEncoded) @@ -109,6 +110,10 @@ QtObject: let data = MailserverAvailableArgs() self.events.emit(SIGNAL_MAILSERVER_AVAILABLE, data) + self.events.on(SignalType.MailserverNotWorking.event) do(e: Args): + info "mailserver not working" + self.events.emit(SIGNAL_MAILSERVER_NOT_WORKING, Args()) + self.events.on(SignalType.HistoryRequestStarted.event) do(e: Args): let h = HistoryRequestStartedSignal(e) info "history request started", requestId=h.requestId, numBatches=h.numBatches diff --git a/src/backend/signals.nim b/src/backend/signals.nim index 3b02d8018c..2f733f5198 100644 --- a/src/backend/signals.nim +++ b/src/backend/signals.nim @@ -32,6 +32,7 @@ proc decode*(jsonSignal: JsonNode): Signal = of SignalType.KeycardConnected: KeycardConnectedSignal.fromEvent(jsonSignal) of SignalType.MailserverAvailable: MailserverAvailableSignal.fromEvent(jsonSignal) of SignalType.MailserverChanged: MailserverChangedSignal.fromEvent(jsonSignal) + of SignalType.MailserverNotWorking: MailserverNotWorkingSignal.fromEvent(jsonSignal) of SignalType.HistoryArchivesProtocolEnabled: historyArchivesProtocolEnabledFromEvent(jsonSignal) of SignalType.HistoryArchivesProtocolDisabled: historyArchivesProtocolDisabledFromEvent(jsonSignal) of SignalType.CreatingHistoryArchives: creatingHistoryArchivesFromEvent(jsonSignal) diff --git a/ui/app/mainui/AppMain.qml b/ui/app/mainui/AppMain.qml index d6af5c5c18..2431c32179 100644 --- a/ui/app/mainui/AppMain.qml +++ b/ui/app/mainui/AppMain.qml @@ -626,8 +626,56 @@ Item { } } } + + Connections { + target: rootStore.mainModuleInst + onMailserverNotWorking: { + Global.openPopup(mailserverNotWorkingPopupComponent); + } + } } + Component { + id: mailserverNotWorkingPopupComponent + StatusModal { + id: msNotWorkingPopup + anchors.centerIn: parent + header.title: qsTr("Can not connect to mailserver") + onClosed: { + destroy() + } + + contentItem: Item { + width: msNotWorkingPopup.width + implicitHeight: 100 + + StatusBaseText { + text: qsTr("The mailserver you're connecting to is unavailable.") + color: Theme.palette.directColor1 + anchors.centerIn: parent + } + } + + rightButtons: [ + StatusButton { + text: qsTr("Pick another") + onClicked: { + Global.changeAppSectionBySectionType(Constants.appSection.profile, Constants.settingsSubsection.messaging) + msNotWorkingPopup.close() + } + }, + StatusButton { + text: qsTr("Retry") + onClicked: { + // Retrying already happens automatically, so doing nothing + // here is the same as retrying... + msNotWorkingPopup.close() + } + } + ] + } + } + Component { id: chooseBrowserPopupComponent ChooseBrowserPopup {