fix(HistoryNodes): Fix mailserver management UI controllers

Fixes #14982
This commit is contained in:
Andrey Bocharnikov 2024-06-04 16:55:08 +04:00 committed by Jonathan Rainville
parent c4928cfe40
commit 3345a9cc48
12 changed files with 149 additions and 85 deletions

View File

@ -33,6 +33,7 @@ type MailserverAvailableSignal* = ref object of Signal
type MailserverChangedSignal* = ref object of Signal
address*: string
id*: string
type MailserverNotWorkingSignal* = ref object of Signal
@ -84,6 +85,7 @@ proc fromEvent*(T: type MailserverChangedSignal, jsonSignal: JsonNode): Mailserv
result = MailserverChangedSignal()
result.signalType = SignalType.MailserverChanged
result.address = jsonSignal["event"]{"address"}.getStr()
result.id = jsonSignal["event"]{"id"}.getStr()
proc fromEvent*(T: type MailserverNotWorkingSignal, jsonSignal: JsonNode): MailserverNotWorkingSignal =
result = MailserverNotWorkingSignal()

View File

@ -34,19 +34,24 @@ proc delete*(self: Controller) =
proc init*(self: Controller) =
self.events.on(SIGNAL_ACTIVE_MAILSERVER_CHANGED) do(e: Args):
var args = ActiveMailserverChangedArgs(e)
self.delegate.onActiveMailserverChanged(args.nodeAddress)
self.delegate.onActiveMailserverChanged()
self.events.on(SIGNAL_PINNED_MAILSERVER_CHANGED) do(e: Args):
self.delegate.onPinnedMailserverChanged()
proc getAllMailservers*(self: Controller): seq[tuple[name: string, nodeAddress: string]] =
return self.mailserversService.getAllMailservers()
proc getPinnedMailserver*(self: Controller): string =
proc getPinnedMailserverId*(self: Controller): string =
let fleet = self.nodeConfigurationService.getFleet()
self.settingsService.getPinnedMailserver(fleet)
self.settingsService.getPinnedMailserverId(fleet)
proc pinMailserver*(self: Controller, mailserverID: string) =
proc setPinnedMailserverId*(self: Controller, mailserverID: string) =
let fleet = self.nodeConfigurationService.getFleet()
discard self.settingsService.pinMailserver(mailserverID, fleet)
discard self.settingsService.setPinnedMailserverId(mailserverID, fleet)
proc getActiveMailserverId*(self: Controller): string =
return self.mailserversService.getActiveMailserverId()
proc saveNewMailserver*(self: Controller, name: string, nodeAddress: string) =
discard self.mailserversService.saveMailserver(name, nodeAddress)
@ -58,4 +63,4 @@ proc getUseMailservers*(self: Controller): bool =
return self.settingsService.getUseMailservers()
proc setUseMailservers*(self: Controller, value: bool): bool =
return self.settingsService.saveUseMailservers(value)
return self.settingsService.toggleUseMailservers(value)

View File

@ -15,7 +15,10 @@ method isLoaded*(self: AccessInterface): bool {.base.} =
method getModuleAsVariant*(self: AccessInterface): QVariant {.base.} =
raise newException(ValueError, "No implementation available")
method onActiveMailserverChanged*(self: AccessInterface, nodeAddress: string) {.base.} =
method onActiveMailserverChanged*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method onPinnedMailserverChanged*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method viewDidLoad*(self: AccessInterface) {.base.} =
@ -24,10 +27,13 @@ method viewDidLoad*(self: AccessInterface) {.base.} =
method isAutomaticSelection*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")
method getMailserverNameForNodeAddress*(self: AccessInterface, nodeAddress: string): string {.base.} =
method getActiveMailserverId*(self: AccessInterface): string {.base.} =
raise newException(ValueError, "No implementation available")
method setActiveMailserver*(self: AccessInterface, mailserverID: string) {.base.} =
method getPinnedMailserverId*(self: AccessInterface): string {.base.} =
raise newException(ValueError, "No implementation available")
method setPinnedMailserverId*(self: AccessInterface, mailserverID: string) {.base.} =
raise newException(ValueError, "No implementation available")
method saveNewMailserver*(self: AccessInterface, name: string, nodeAddress: string) {.base.} =

View File

@ -63,19 +63,23 @@ method getModuleAsVariant*(self: Module): QVariant =
return self.viewVariant
method isAutomaticSelection*(self: Module): bool =
return self.controller.getPinnedMailserver().len == 0
return self.controller.getPinnedMailserverId().len == 0
method onActiveMailserverChanged*(self: Module, nodeAddress: string) =
self.view.onActiveMailserverSet(nodeAddress)
method onActiveMailserverChanged*(self: Module) =
self.view.onActiveMailserverSet()
method getMailserverNameForNodeAddress*(self: Module, nodeAddress: string): string =
let name = self.view.model().getNameForNodeAddress(nodeAddress)
if(name.len > 0):
return name
return "---"
method onPinnedMailserverChanged*(self: Module) =
self.view.onPinnedMailserverSet()
method setActiveMailserver*(self: Module, mailserverID: string) =
self.controller.pinMailserver(mailserverID)
method setPinnedMailserverId*(self: Module, mailserverID: string) =
self.controller.setPinnedMailserverId(mailserverID)
method getPinnedMailserverId*(self: Module): string =
return self.controller.getPinnedMailserverId()
method getActiveMailserverId*(self: Module): string =
let res = self.controller.getActiveMailserverId()
return res
method saveNewMailserver*(self: Module, name: string, nodeAddress: string) =
self.controller.saveNewMailserver(name, nodeAddress)
@ -90,5 +94,5 @@ method getUseMailservers*(self: Module): bool =
return self.controller.getUseMailservers()
method setUseMailservers*(self: Module, value: bool) =
if (self.controller.setUseMailservers(value)):
if self.controller.setUseMailservers(value):
self.view.useMailserversChanged()

View File

@ -5,7 +5,6 @@ QtObject:
type
View* = ref object of QObject
delegate: io_interface.AccessInterface
activeMailserver: string
model: Model
modelVariant: QVariant
@ -18,7 +17,6 @@ QtObject:
new(result, delete)
result.QObject.setup
result.delegate = delegate
result.activeMailserver = ""
result.model = newModel()
result.modelVariant = newQVariant(result.model)
@ -31,33 +29,49 @@ QtObject:
proc modelChanged*(self: View) {.signal.}
proc getModel(self: View): QVariant {.slot.} =
return self.modelVariant
QtProperty[QVariant] model:
read = getModel
notify = modelChanged
proc isAutomaticSelection(self: View): bool {.slot.} =
return self.delegate.isAutomaticSelection()
QtProperty[bool] automaticSelection:
read = isAutomaticSelection
notify = pinnedMailserverIdChanged
proc activeMailserverChanged*(self: View) {.signal.}
proc getActiveMailserver(self: View): string {.slot.} =
return self.activeMailserver
QtProperty[string] activeMailserver:
read = getActiveMailserver
notify = activeMailserverChanged
proc activeMailserverIdChanged*(self: View) {.signal.}
proc setActiveMailserver(self: View, mailserverID: string) {.slot.} =
self.delegate.setActiveMailserver(mailserverID)
proc getActiveMailserverId(self: View): string {.slot.} =
let res = self.delegate.getActiveMailserverId()
return res
proc onActiveMailserverSet*(self: View, nodeAddress: string) =
if(self.activeMailserver == nodeAddress):
QtProperty[string] activeMailserverId:
read = getActiveMailserverId
notify = activeMailserverIdChanged
proc onActiveMailserverSet*(self: View) =
self.activeMailserverIdChanged()
proc pinnedMailserverIdChanged*(self: View) {.signal.}
proc getPinnedMailserverId(self: View): string {.slot.} =
let res = self.delegate.getPinnedMailserverId()
return res
QtProperty[string] pinnedMailserverId:
read = getPinnedMailserverId
write = setPinnedMailserverId
notify = pinnedMailserverIdChanged
proc setPinnedMailserverId(self: View, mailserverID: string) {.slot.} =
if mailserverID == self.getPinnedMailserverId():
return
self.activeMailserver = nodeAddress
self.activeMailserverChanged()
self.delegate.setPinnedMailserverId(mailserverID)
proc getMailserverNameForNodeAddress*(self: View, nodeAddress: string): string {.slot.} =
self.delegate.getMailserverNameForNodeAddress(nodeAddress)
proc onPinnedMailserverSet*(self: View) =
self.pinnedMailserverIdChanged()
proc saveNewMailserver(self: View, name: string, address: string) {.slot.} =
self.delegate.saveNewMailserver(name, address)
@ -71,6 +85,8 @@ QtObject:
return self.delegate.getUseMailservers()
proc setUseMailservers*(self: View, value: bool) {.slot.} =
if value == self.delegate.getUseMailservers():
return
self.delegate.setUseMailservers(value)
QtProperty[bool] useMailservers:

View File

@ -23,6 +23,7 @@ logScope:
type
ActiveMailserverChangedArgs* = ref object of Args
nodeAddress*: string
nodeId*: string
MailserverAvailableArgs* = ref object of Args
@ -80,6 +81,7 @@ QtObject:
settingsService: settings_service.Service
nodeConfigurationService: node_configuration_service.Service
fleetConfiguration: FleetConfiguration
activeMailserverData: ActiveMailserverChangedArgs
# Forward declaration:
proc doConnect(self: Service)
@ -101,6 +103,7 @@ QtObject:
result.settingsService = settingsService
result.nodeConfigurationService = nodeConfigurationService
result.fleetConfiguration = fleetConfiguration
result.activeMailserverData = ActiveMailserverChangedArgs(nodeAddress: "", nodeId: "")
proc init*(self: Service) =
self.doConnect()
@ -118,10 +121,10 @@ QtObject:
let mailserverName = "Test Mailserver"
self.mailservers.add((name: mailserverName, nodeAddress: TEST_PEER_ENR))
let mailserverID = self.saveMailserver(mailserverName, TEST_PEER_ENR)
discard self.settingsService.pinMailserver(mailserverId, fleet)
discard self.settingsService.setPinnedMailserverId(mailserverId, fleet)
if MAILSERVER_ID != "":
discard self.settingsService.pinMailserver(MAILSERVER_ID, fleet)
discard self.settingsService.setPinnedMailserverId(MAILSERVER_ID, fleet)
proc requestMoreMessages*(self: Service, chatId: string) =
let arg = RequestMoreMessagesTaskArg(
@ -144,13 +147,14 @@ QtObject:
self.events.on(SignalType.MailserverChanged.event) do(e: Args):
let receivedData = MailserverChangedSignal(e)
let address = receivedData.address
let id = receivedData.id
if address == "":
info "removing active mailserver"
else:
info "active mailserver changed", node=address
let data = ActiveMailserverChangedArgs(nodeAddress: address)
self.events.emit(SIGNAL_ACTIVE_MAILSERVER_CHANGED, data)
info "active mailserver changed", node=address, id = id
self.activeMailserverData = ActiveMailserverChangedArgs(nodeAddress: address, nodeId: id)
self.events.emit(SIGNAL_ACTIVE_MAILSERVER_CHANGED, self.activeMailserverData)
self.events.on(SignalType.MailserverAvailable.event) do(e: Args):
info "mailserver available"
@ -179,7 +183,6 @@ QtObject:
let h = HistoryRequestSuccessSignal(e)
info "history request success", requestId=h.requestId, peerId=h.peerId
proc initMailservers(self: Service) =
let fleet = self.nodeConfigurationService.getFleet()
let mailservers = self.fleetConfiguration.getMailservers(fleet)
@ -188,6 +191,9 @@ QtObject:
info "initMailservers", topics="mailserver-interaction", name, nodeAddress
self.mailservers.add((name: name, nodeAddress: nodeAddress))
proc getActiveMailserverId*(self: Service): string =
return self.activeMailserverData.nodeId
proc fetchMailservers(self: Service) =
try:
let response = status_mailservers.getMailservers()
@ -235,7 +241,3 @@ QtObject:
# slot: "onActiveMailserverResult"
# )
#mailserverWorker.start(task)
proc onActiveMailserverResult*(self: Service, response: string) {.slot.} =
let fleet = self.nodeConfigurationService.getFleet()
discard self.settingsService.pinMailserver(response, fleet)

View File

@ -255,6 +255,6 @@ proc pinnedMailserverToJsonNode*(mailserver: PinnedMailserver): JsonNode =
"waku.test": mailserver.wakuTest,
"status.test": mailserver.statusTest,
"status.prod": mailserver.statusProd,
"shard.test": mailserver.shardsTest,
"shards.test": mailserver.shardsTest,
"sharding.staging": mailserver.shardsStaging,
}

View File

@ -1,9 +1,10 @@
import NimQml, chronicles, json, strutils, sequtils, tables
import app_service/common/types as common_types
import app/core/eventemitter
import app/core/fleets/fleet_configuration
import app/core/signals/types
import app_service/common/types as common_types
import backend/mailservers as status_mailservers
import backend/settings as status_settings
import backend/status_update as status_update
@ -26,6 +27,7 @@ const SIGNAL_MNEMONIC_REMOVED* = "mnemonicRemoved"
const SIGNAL_CURRENT_USER_STATUS_UPDATED* = "currentUserStatusUpdated"
const SIGNAL_PROFILE_MIGRATION_NEEDED_UPDATED* = "profileMigrationNeededUpdated"
const SIGNAL_URL_UNFURLING_MODE_UPDATED* = "urlUnfurlingModeUpdated"
const SIGNAL_PINNED_MAILSERVER_CHANGED* = "pinnedMailserverChanged"
logScope:
topics = "settings-service"
@ -328,11 +330,18 @@ QtObject:
proc getAppearance*(self: Service): int =
self.settings.appearance
proc saveUseMailservers*(self: Service, value: bool): bool =
if(self.saveSetting(KEY_USE_MAILSERVERS, value)):
self.settings.useMailservers = value
return true
proc toggleUseMailservers*(self: Service, value: bool): bool =
try:
let response = status_mailservers.toggleUseMailservers(value)
if not response.error.isNil:
error "error saving use mailservers: ", errDescription = response.error.message
return false
self.settings.useMailservers = value
except Exception as e:
let errDesription = e.msg
error "saving use mailservers error: ", errDesription
return false
return true
proc getUseMailservers*(self: Service): bool =
self.settings.useMailservers
@ -390,36 +399,52 @@ QtObject:
proc getCurrentUserStatus*(self: Service): CurrentUserStatus =
self.settings.currentUserStatus
proc getPinnedMailserver*(self: Service, fleet: Fleet): string =
if (fleet == Fleet.WakuSandbox):
proc getPinnedMailserverId*(self: Service, fleet: Fleet): string =
case fleet:
of Fleet.WakuSandbox:
return self.settings.pinnedMailserver.wakuSandbox
elif (fleet == Fleet.WakuTest):
of Fleet.WakuTest:
return self.settings.pinnedMailserver.wakuTest
elif (fleet == Fleet.ShardsTest):
of Fleet.ShardsTest:
return self.settings.pinnedMailserver.shardsTest
elif (fleet == Fleet.ShardsStaging):
of Fleet.ShardsStaging:
return self.settings.pinnedMailserver.shardsStaging
else:
return ""
proc pinMailserver*(self: Service, mailserverID: string, fleet: Fleet): bool =
proc setPinnedMailserverId*(self: Service, mailserverID: string, fleet: Fleet): bool =
if fleet == Fleet.Undefined:
return false
var newMailserverJsonObj = self.settings.pinnedMailserver.pinnedMailserverToJsonNode()
newMailserverJsonObj[$fleet] = %* mailserverID
if(self.saveSetting(KEY_PINNED_MAILSERVERS, newMailserverJsonObj)):
if (fleet == Fleet.WakuSandbox):
self.settings.pinnedMailserver.wakuSandbox = mailserverID
elif (fleet == Fleet.WakuTest):
self.settings.pinnedMailserver.wakuTest = mailserverID
elif (fleet == Fleet.ShardsTest):
self.settings.pinnedMailserver.shardsTest = mailserverID
elif (fleet == Fleet.ShardsStaging):
self.settings.pinnedMailserver.shardsStaging = mailserverID
return true
try:
let response = status_mailservers.setPinnedMailservers(newMailserverJsonObj)
if not response.error.isNil:
error "error saving pinned mailserver: ", errDescription = response.error.message
return false
case fleet:
of Fleet.WakuSandbox:
self.settings.pinnedMailserver.wakuSandbox = mailserverID
of Fleet.WakuTest:
self.settings.pinnedMailserver.wakuTest = mailserverID
of Fleet.ShardsTest:
self.settings.pinnedMailserver.shardsTest = mailserverID
of Fleet.ShardsStaging:
self.settings.pinnedMailserver.shardsStaging = mailserverID
else:
return false
except Exception as e:
let errDesription = e.msg
error "saving pinned mailserver error: ", errDesription
return false
self.events.emit(SIGNAL_PINNED_MAILSERVER_CHANGED, Args())
return true
proc unpinMailserver*(self: Service, fleet: Fleet): bool =
return self.pinMailserver("", fleet)
return self.setPinnedMailserverId("", fleet)
proc saveNodeConfiguration*(self: Service, value: JsonNode): bool =
if(self.saveSetting(KEY_NODE_CONFIG, value)):

View File

@ -20,6 +20,12 @@ proc saveMailserver*(id: string, name: string, enode: string, fleet: string):
proc getMailservers*(): RpcResponse[JsonNode] =
result = core.callPrivateRPC("mailservers_getMailservers")
proc setPinnedMailservers*(mailservers: JsonNode): RpcResponse[JsonNode] =
result = core.callPrivateRPC("setPinnedMailservers".prefix, %*[ mailservers ])
proc toggleUseMailservers*(value: bool): RpcResponse[JsonNode] =
result = core.callPrivateRPC("toggleUseMailservers".prefix, %*[ value ])
proc syncChatFromSyncedFrom*(chatId: string): RpcResponse[JsonNode] =
let payload = %*[chatId]
result = core.callPrivateRPC("syncChatFromSyncedFrom".prefix, payload)

View File

@ -100,10 +100,10 @@ StatusModal {
StatusRadioButton {
id: nodeRadioBtn
ButtonGroup.group: nodesButtonGroup
checked: model.nodeAddress === root.messagingStore.activeMailserver
checked: model.name === root.messagingStore.pinnedMailserverId
onCheckedChanged: {
if (checked) {
root.messagingStore.setActiveMailserver(model.name)
root.messagingStore.setPinnedMailserverId(model.name)
}
}
}

View File

@ -19,14 +19,12 @@ QtObject {
// Module Properties
property bool automaticMailserverSelection: syncModule.automaticSelection
property string activeMailserver: syncModule.activeMailserver
property string activeMailserverId: syncModule.activeMailserverId
property string pinnedMailserverId: syncModule.pinnedMailserverId
function getMailserverNameForNodeAddress(nodeAddress) {
return root.syncModule.getMailserverNameForNodeAddress(nodeAddress)
}
function setActiveMailserver(mailserverID) {
root.syncModule.setActiveMailserver(mailserverID)
function setPinnedMailserverId(mailserverID) {
root.syncModule.setPinnedMailserverId(mailserverID)
}
function saveNewMailserver(name, nodeAddress) {

View File

@ -314,7 +314,7 @@ SettingsContentBase {
anchors.leftMargin: Style.current.padding
anchors.rightMargin: Style.current.padding
title: qsTr("History nodes")
label: root.messagingStore.getMailserverNameForNodeAddress(root.messagingStore.activeMailserver)
label: root.messagingStore.activeMailserverId || "---"
components: [
StatusIcon {
icon: "next"