diff --git a/src/app/profile/core.nim b/src/app/profile/core.nim index 6885caf26d..bf223ac0d1 100644 --- a/src/app/profile/core.nim +++ b/src/app/profile/core.nim @@ -59,6 +59,10 @@ proc init*(self: ProfileController, account: Account) = let mailserver = MailServer(name: name, endpoint: endpoint) self.view.mailservers.add(mailserver) + for mailserver in status_settings.getMailservers().getElems(): + let mailserver = MailServer(name: mailserver["name"].getStr(), endpoint: mailserver["address"].getStr()) + self.view.mailservers.add(mailserver) + let contacts = self.status.contacts.getContacts() self.status.chat.updateContacts(contacts) self.view.contacts.setContactList(contacts) diff --git a/src/app/profile/views/mailservers.nim b/src/app/profile/views/mailservers.nim index ff675e775a..ea0db941ef 100644 --- a/src/app/profile/views/mailservers.nim +++ b/src/app/profile/views/mailservers.nim @@ -59,3 +59,7 @@ QtObject: status_settings.pinMailserver() else: status_settings.pinMailserver(self.status.mailservers.getActiveMailserver()) + + proc save(self: MailserversView, name: string, address: string) {.slot.} = + status_settings.saveMailserver(name, address) + self.mailserversList.add(Mailserver(name: name, endpoint: address)) \ No newline at end of file diff --git a/src/status/libstatus/settings.nim b/src/status/libstatus/settings.nim index aa42086068..7b29953f21 100644 --- a/src/status/libstatus/settings.nim +++ b/src/status/libstatus/settings.nim @@ -2,6 +2,7 @@ import core, ./types, ../signals/types as statusgo_types, ./accounts/constants, import json, tables, sugar, sequtils, strutils import json_serialization import locks +import uuids var settingsLock {.global.}: Lock initLock(settingsLock) @@ -78,5 +79,22 @@ proc getPinnedMailserver*(): string = proc pinMailserver*(enode: string = "") = let pinnedMailservers = getSetting[JsonNode](Setting.PinnedMailservers, %*{}) let fleet = getSetting[string](Setting.Fleet, $Fleet.PROD) + pinnedMailservers[fleet] = newJString(enode) discard saveSetting(Setting.PinnedMailservers, pinnedMailservers) + +proc saveMailserver*(name, enode: string) = + let fleet = getSetting[string](Setting.Fleet, $Fleet.PROD) + let result = callPrivateRPC("mailservers_addMailserver", %* [ + %*{ + "id": $genUUID(), + "name": name, + "address": enode, + "fleet": $fleet + } + ]).parseJSON()["result"] + +proc getMailservers*():JsonNode = + let fleet = getSetting[string](Setting.Fleet, $Fleet.PROD) + result = callPrivateRPC("mailservers_getMailservers").parseJSON()["result"] + diff --git a/src/status/mailservers.nim b/src/status/mailservers.nim index 79131b5e93..31829d936a 100644 --- a/src/status/mailservers.nim +++ b/src/status/mailservers.nim @@ -247,6 +247,7 @@ proc checkConnection() {.thread.} = let pinnedMailserver = status_settings.getPinnedMailserver() if pinnedMailserver != "" and mailserverModel.getActiveMailserver() != pinnedMailserver: # connect to current mailserver from the settings + mailserverModel.mailservers.add(pinnedMailserver) mailserverModel.connect(pinnedMailserver) else: # or setup a random mailserver: @@ -259,5 +260,7 @@ proc checkConnection() {.thread.} = proc init*(self: MailserverModel) = debug "MailserverModel::init()" self.mailservers = toSeq(self.fleet.config.getMailservers(status_settings.getFleet()).values) + for mailserver in status_settings.getMailservers().getElems(): + self.mailservers.add(mailserver["address"].getStr()) connThread.createThread(checkConnection) \ No newline at end of file diff --git a/ui/app/AppLayouts/Profile/Sections/SyncContainer.qml b/ui/app/AppLayouts/Profile/Sections/SyncContainer.qml index a1933cfe39..8988884d9c 100644 --- a/ui/app/AppLayouts/Profile/Sections/SyncContainer.qml +++ b/ui/app/AppLayouts/Profile/Sections/SyncContainer.qml @@ -36,25 +36,135 @@ Item { } } + Item { + id: addMailserver + width: parent.width + height: addButton.height + anchors.top: element4.bottom + anchors.topMargin: Style.current.padding + anchors.left: parent.left + anchors.leftMargin: 24 + + StatusRoundButton { + id: addButton + icon.name: "plusSign" + size: "medium" + anchors.verticalCenter: parent.verticalCenter + } + + + StyledText { + id: usernameText + text: qsTr("Add mailserver") + color: Style.current.blue + anchors.left: addButton.right + anchors.leftMargin: Style.current.padding + anchors.verticalCenter: addButton.verticalCenter + font.pixelSize: 15 + } + + MouseArea { + anchors.fill: parent + cursorShape: Qt.PointingHandCursor + onClicked: addMailserverPopup.open() + } + + ModalPopup { + id: addMailserverPopup + title: qsTr("Add mailserver") + + property string nameValidationError: "" + property string enodeValidationError: "" + + function validate() { + nameValidationError = "" + enodeValidationError = "" + + if (nameInput.text === "") { + nameValidationError = qsTr("You need to enter a name") + } + + if (enodeInput.text === "") { + enodeValidationError = qsTr("You need to enter the enode address") + } + return !nameValidationError && !enodeValidationError + } + + onOpened: { + nameInput.text = ""; + enodeInput.text = ""; + + nameValidationError = ""; + enodeValidationError = ""; + } + + footer: StyledButton { + anchors.right: parent.right + anchors.rightMargin: Style.current.smallPadding + label: qsTr("Save") + anchors.bottom: parent.bottom + disabled: nameInput.text == "" || enodeInput.text == "" + onClicked: { + if (!addMailserverPopup.validate()) { + return; + } + profileModel.mailservers.save(nameInput.text, enodeInput.text) + addMailserverPopup.close() + } + } + + Input { + id: nameInput + label: qsTr("Name") + placeholderText: qsTr("Specify a name") + validationError: addMailserverPopup.nameValidationError + } + + Input { + id: enodeInput + label: qsTr("History node address") + placeholderText: qsTr("enode://{enode-id}:{password}@{ip-address}:{port-number}") + validationError: addMailserverPopup.enodeValidationError + anchors.top: nameInput.bottom + anchors.topMargin: Style.current.bigPadding + } + + } + } + + StyledText { + id: switchLbl + text: qsTr("Automatic mailserver selection") + anchors.left: parent.left + anchors.leftMargin: 24 + anchors.top: addMailserver.bottom + anchors.topMargin: 24 + } + StatusSwitch { id: automaticSelectionSwitch checked: profileModel.mailservers.automaticSelection onCheckedChanged: profileModel.mailservers.enableAutomaticSelection(checked) + anchors.top: addMailserver.bottom + anchors.topMargin: Style.current.padding + anchors.left: switchLbl.right + anchors.leftMargin: Style.current.padding + } StyledText { text: profileModel.mailservers.activeMailserver || qsTr("...") anchors.left: parent.left anchors.leftMargin: 24 - anchors.top: element4.top + anchors.top: switchLbl.bottom anchors.topMargin: 24 visible: automaticSelectionSwitch.checked } ListView { id: mailServersListView - anchors.topMargin: 48 - anchors.top: element4.bottom + anchors.topMargin: 200 + anchors.top: automaticSelectionSwitch.bottom anchors.fill: parent model: profileModel.mailservers.list delegate: mailserversList