feat: add custom mailserver

This commit is contained in:
Richard Ramos 2021-01-11 15:31:47 -04:00 committed by Iuri Matias
parent 840a6189eb
commit efc1feb2fa
5 changed files with 142 additions and 3 deletions

View File

@ -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)

View File

@ -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))

View File

@ -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"]

View File

@ -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)

View File

@ -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