refactor: mailserver cycle
This commit is contained in:
parent
ebd6f2674b
commit
d51b70c703
|
@ -1,21 +0,0 @@
|
|||
import json
|
||||
|
||||
import statusgo_backend/mailservers as status_mailservers
|
||||
import ../eventemitter
|
||||
|
||||
type
|
||||
MailserversModel* = ref object
|
||||
events*: EventEmitter
|
||||
|
||||
proc newMailserversModel*(events: EventEmitter): MailserversModel =
|
||||
result = MailserversModel()
|
||||
result.events = events
|
||||
|
||||
proc fillGaps*(self: MailserversModel, chatId: string, messageIds: seq[string]): string =
|
||||
result = status_mailservers.fillGaps(chatId, messageIds)
|
||||
|
||||
proc setMailserver*(self: MailserversModel, peer: string): string =
|
||||
result = status_mailservers.setMailserver(peer)
|
||||
|
||||
proc requestAllHistoricMessages*(self: MailserversModel): string =
|
||||
result = status_mailservers.requestAllHistoricMessages()
|
|
@ -30,6 +30,8 @@ proc decode*(jsonSignal: JsonNode): Signal =
|
|||
of SignalType.HistoryRequestFailed: HistoryRequestFailedSignal.fromEvent(jsonSignal)
|
||||
of SignalType.HistoryRequestBatchProcessed: HistoryRequestBatchProcessedSignal.fromEvent(jsonSignal)
|
||||
of SignalType.KeycardConnected: KeycardConnectedSignal.fromEvent(jsonSignal)
|
||||
of SignalType.MailserverAvailable: MailserverAvailableSignal.fromEvent(jsonSignal)
|
||||
of SignalType.MailserverChanged: MailserverChangedSignal.fromEvent(jsonSignal)
|
||||
else: Signal()
|
||||
|
||||
result.signalType = signalType
|
||||
|
|
|
@ -30,6 +30,12 @@ type HistoryRequestFailedSignal* = ref object of Signal
|
|||
errorMessage*: string
|
||||
error*: bool
|
||||
|
||||
type MailserverAvailableSignal* = ref object of Signal
|
||||
address*: string
|
||||
|
||||
type MailserverChangedSignal* = ref object of Signal
|
||||
address*: string
|
||||
|
||||
proc fromEvent*(T: type MailserverRequestCompletedSignal, jsonSignal: JsonNode): MailserverRequestCompletedSignal =
|
||||
result = MailserverRequestCompletedSignal()
|
||||
result.signalType = SignalType.MailserverRequestCompleted
|
||||
|
@ -70,3 +76,13 @@ proc fromEvent*(T: type HistoryRequestFailedSignal, jsonSignal: JsonNode): Histo
|
|||
if jsonSignal["event"].kind != JNull:
|
||||
result.errorMessage = jsonSignal["event"]{"errorMessage"}.getStr()
|
||||
result.error = result.errorMessage != ""
|
||||
|
||||
proc fromEvent*(T: type MailserverAvailableSignal, jsonSignal: JsonNode): MailserverAvailableSignal =
|
||||
result = MailserverAvailableSignal()
|
||||
result.signalType = SignalType.MailserverAvailable
|
||||
result.address = jsonSignal["event"]{"address"}.getStr()
|
||||
|
||||
proc fromEvent*(T: type MailserverChangedSignal, jsonSignal: JsonNode): MailserverChangedSignal =
|
||||
result = MailserverChangedSignal()
|
||||
result.signalType = SignalType.MailserverChanged
|
||||
result.address = jsonSignal["event"]{"address"}.getStr()
|
||||
|
|
|
@ -27,6 +27,8 @@ type SignalType* {.pure.} = enum
|
|||
HistoryRequestFailed = "history.request.failed"
|
||||
HistoryRequestBatchProcessed = "history.request.batch.processed"
|
||||
KeycardConnected = "keycard.connected"
|
||||
MailserverAvailable = "mailserver.available"
|
||||
MailserverChanged = "mailserver.changed"
|
||||
Unknown
|
||||
|
||||
proc event*(self:SignalType):string =
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import statusgo_backend/accounts as statusgo_backend_accounts
|
||||
import statusgo_backend/core as statusgo_backend_core
|
||||
import statusgo_backend/settings as statusgo_backend_settings
|
||||
import chat, accounts, wallet, wallet2, node, network, messages, contacts, profile, stickers, permissions, fleet, settings, mailservers, tokens
|
||||
import chat, accounts, wallet, wallet2, node, network, messages, contacts, profile, stickers, permissions, fleet, settings, tokens
|
||||
import notifications/os_notifications
|
||||
import ../eventemitter
|
||||
import bitops, stew/byteutils, chronicles
|
||||
|
@ -28,7 +28,6 @@ type Status* = ref object
|
|||
stickers*: StickersModel
|
||||
permissions*: PermissionsModel
|
||||
settings*: SettingsModel
|
||||
mailservers*: MailserversModel
|
||||
tokens*: TokensModel
|
||||
osnotifications*: OsNotifications
|
||||
keycard*: KeycardModel
|
||||
|
@ -51,7 +50,6 @@ proc newStatusInstance*(fleetConfig: string, backendName: string = "statusgo"):
|
|||
result.stickers = stickers.newStickersModel(result.events)
|
||||
result.permissions = permissions.newPermissionsModel(result.events)
|
||||
result.settings = settings.newSettingsModel(result.events)
|
||||
result.mailservers = mailservers.newMailserversModel(result.events)
|
||||
result.tokens = tokens.newTokensModel(result.events)
|
||||
result.osnotifications = newOsNotifications(result.events)
|
||||
result.keycard = newKeycardModel(result.backend)
|
||||
|
@ -69,7 +67,6 @@ proc reset*(self: Status) {.exportc, dynlib.} =
|
|||
# NOT NEEDED self.chat.reset()
|
||||
# NOT NEEDED self.wallet.reset()
|
||||
# NOT NEEDED self.node.reset()
|
||||
# NOT NEEDED self.mailservers.reset()
|
||||
# NOT NEEDED self.profile.reset()
|
||||
|
||||
# TODO: add all resets here
|
||||
|
|
|
@ -143,6 +143,7 @@ var NODE_CONFIG* = %* {
|
|||
}
|
||||
},
|
||||
"ShhextConfig": {
|
||||
"EnableMailserverCycle": true,
|
||||
"BackupDisabledDataDir": "./",
|
||||
"DataSyncEnabled": true,
|
||||
"InstallationID": "aef27732-8d86-5039-a32e-bdbe094d8791",
|
||||
|
|
|
@ -1,57 +0,0 @@
|
|||
import json, times, chronicles
|
||||
import core, ../utils
|
||||
|
||||
proc ping*(mailservers: seq[string], timeoutMs: int, isWakuV2: bool = false): string =
|
||||
var addresses: seq[string] = @[]
|
||||
for mailserver in mailservers:
|
||||
addresses.add(mailserver)
|
||||
var rpcMethod = if isWakuV2: "mailservers_multiAddressPing" else: "mailservers_ping"
|
||||
result = callPrivateRPC(rpcMethod, %* [
|
||||
{ "addresses": addresses, "timeoutMs": timeoutMs }
|
||||
])
|
||||
info "ping", topics="mailserver-interaction", rpc_method="mailservers_ping", addresses, timeoutMs, result
|
||||
|
||||
proc update*(peer: string) =
|
||||
let response = callPrivateRPC("updateMailservers".prefix, %* [[peer]])
|
||||
info "update", topics="mailserver-interaction", rpc_method="wakuext_updateMailservers", peer, response
|
||||
|
||||
proc setMailserver*(peer: string): string =
|
||||
result = callPrivateRPC("setMailserver".prefix, %* [peer])
|
||||
info "setMailserver", topics="mailserver-interaction", rpc_method="wakuext_setMailserver", peer, result
|
||||
|
||||
proc delete*(peer: string) =
|
||||
let response = callPrivateRPC("mailservers_deleteMailserver", %* [peer])
|
||||
info "delete", topics="mailserver-interaction", rpc_method="mailservers_deleteMailserver", peer, response
|
||||
|
||||
proc requestAllHistoricMessages*(): string =
|
||||
result = callPrivateRPC("requestAllHistoricMessages".prefix, %*[])
|
||||
info "requestAllHistoricMessages", topics="mailserver-interaction", rpc_method="mailservers_requestAllHistoricMessages"
|
||||
|
||||
proc requestStoreMessages*(topics: seq[string], symKeyID: string, peer: string, numberOfMessages: int, fromTimestamp: int64 = 0, toTimestamp: int64 = 0, force: bool = false) =
|
||||
var toValue = times.toUnix(times.getTime())
|
||||
var fromValue = toValue - 86400
|
||||
if fromTimestamp != 0:
|
||||
fromValue = fromTimestamp
|
||||
if toTimestamp != 0:
|
||||
toValue = toTimestamp
|
||||
|
||||
echo callPrivateRPC("requestMessages".prefix, %* [
|
||||
{
|
||||
"topics": topics,
|
||||
"mailServerPeer": "16Uiu2HAmVVi6Q4j7MAKVibquW8aA27UNrA4Q8Wkz9EetGViu8ZF1",
|
||||
"timeout": 30,
|
||||
"limit": numberOfMessages,
|
||||
"cursor": nil,
|
||||
"from": fromValue,
|
||||
"to": toValue,
|
||||
"force": force
|
||||
}
|
||||
])
|
||||
|
||||
proc syncChatFromSyncedFrom*(chatId: string): string =
|
||||
result = callPrivateRPC("syncChatFromSyncedFrom".prefix, %*[chatId])
|
||||
info "syncChatFromSyncedFrom", topics="mailserver-interaction", rpc_method="wakuext_syncChatFromSyncedFrom", chatId, result
|
||||
|
||||
proc fillGaps*(chatId: string, messageIds: seq[string]): string =
|
||||
result = callPrivateRPC("fillGaps".prefix, %*[chatId, messageIds])
|
||||
info "fillGaps", topics="mailserver-interaction", rpc_method="wakuext_fillGaps", chatId, messageIds, result
|
|
@ -225,6 +225,9 @@ proc login*(name, keyUid, hashedPassword, identicon, thumbnail, large: string):
|
|||
# While this is fixed, you can add here any missing attribute on the node config, and it will be merged with whatever
|
||||
# the account has in the db
|
||||
var nodeCfg = %* {
|
||||
"ShhextConfig": %* {
|
||||
"EnableMailserverCycle": true
|
||||
},
|
||||
"Web3ProviderConfig": %* {
|
||||
"Enabled": true
|
||||
},
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
import json, chronicles
|
||||
import core, utils
|
||||
import response_type
|
||||
|
||||
export response_type
|
||||
|
||||
logScope:
|
||||
topics = "status-lib-mailserver"
|
||||
|
||||
proc saveMailserver*(id: string, name: string, enode: string, fleet: string):
|
||||
RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
let payload = %* [{
|
||||
"id": id,
|
||||
"name": name,
|
||||
"address": enode,
|
||||
"fleet": fleet
|
||||
}]
|
||||
result = core.callPrivateRPC("mailservers_addMailserver", payload)
|
||||
|
||||
proc getMailservers*(): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
result = core.callPrivateRPC("mailservers_getMailservers")
|
||||
|
||||
proc requestAllHistoricMessages*(): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
let payload = %* []
|
||||
result = core.callPrivateRPC("requestAllHistoricMessages".prefix, payload)
|
||||
info "requestAllHistoricMessages", topics="mailserver-interaction", rpc_method="mailservers_requestAllHistoricMessages"
|
||||
|
||||
proc syncChatFromSyncedFrom*(chatId: string): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
let payload = %*[chatId]
|
||||
result = core.callPrivateRPC("syncChatFromSyncedFrom".prefix, payload)
|
||||
info "syncChatFromSyncedFrom", topics="mailserver-interaction", rpc_method="wakuext_syncChatFromSyncedFrom", chatId, result
|
||||
|
||||
proc fillGaps*(chatId: string, messageIds: seq[string]): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
let payload = %*[chatId, messageIds]
|
||||
result = core.callPrivateRPC("fillGaps".prefix, payload)
|
||||
info "fillGaps", topics="mailserver-interaction", rpc_method="wakuext_fillGaps", chatId, messageIds, result
|
||||
|
||||
proc delete*(peer: string): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
let payload = %* [peer]
|
||||
result = core.callPrivateRPC("mailservers_deleteMailserver", payload)
|
||||
info "delete", topics="mailserver-interaction", rpc_method="mailservers_deleteMailserver", peer, result
|
||||
|
||||
proc disconnectActiveMailserver*(): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
let payload = %* []
|
||||
result = core.callPrivateRPC("disconnectActiveMailserver".prefix, payload)
|
||||
info "delete", topics="mailserver-interaction", rpc_method="wakuext_disconnectActiveMailserver", result
|
|
@ -1 +1 @@
|
|||
Subproject commit 9d3f2d82f10cb1c7f3d241142c5e1af33a66e3fe
|
||||
Subproject commit 6f26d00bd54a7d2f608199877358ba3112d328a3
|
Loading…
Reference in New Issue