2021-09-08 18:05:39 +00:00
|
|
|
import json, times
|
|
|
|
import core, ../utils
|
|
|
|
|
2021-09-10 19:56:30 +00:00
|
|
|
proc ping*(mailservers: seq[string], timeoutMs: int): string =
|
2021-09-08 18:05:39 +00:00
|
|
|
var addresses: seq[string] = @[]
|
|
|
|
for mailserver in mailservers:
|
|
|
|
addresses.add(mailserver)
|
2021-09-10 19:56:30 +00:00
|
|
|
result = callPrivateRPC("mailservers_ping", %* [
|
2021-09-08 18:05:39 +00:00
|
|
|
{ "addresses": addresses, "timeoutMs": timeoutMs }
|
|
|
|
])
|
|
|
|
|
|
|
|
proc update*(peer: string) =
|
|
|
|
discard callPrivateRPC("updateMailservers".prefix, %* [[peer]])
|
|
|
|
|
|
|
|
proc setMailserver*(peer: string): string =
|
|
|
|
return callPrivateRPC("setMailserver".prefix, %* [peer])
|
|
|
|
|
|
|
|
proc delete*(peer: string) =
|
|
|
|
discard callPrivateRPC("mailservers_deleteMailserver", %* [peer])
|
|
|
|
|
|
|
|
proc requestAllHistoricMessages*(): string =
|
|
|
|
return callPrivateRPC("requestAllHistoricMessages".prefix, %*[])
|
|
|
|
|
|
|
|
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 =
|
|
|
|
return callPrivateRPC("syncChatFromSyncedFrom".prefix, %*[chatId])
|
|
|
|
|
|
|
|
proc fillGaps*(chatId: string, messageIds: seq[string]): string =
|
|
|
|
return callPrivateRPC("fillGaps".prefix, %*[chatId, messageIds])
|