2021-09-17 16:58:33 +00:00
|
|
|
import json, times, chronicles
|
2021-09-08 18:05:39 +00:00
|
|
|
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 }
|
|
|
|
])
|
2021-09-17 16:58:33 +00:00
|
|
|
info "ping", topics="mailserver-interaction", rpc_method="mailservers_ping", addresses, timeoutMs, result
|
2021-09-08 18:05:39 +00:00
|
|
|
|
|
|
|
proc update*(peer: string) =
|
2021-09-17 16:58:33 +00:00
|
|
|
let response = callPrivateRPC("updateMailservers".prefix, %* [[peer]])
|
|
|
|
info "update", topics="mailserver-interaction", rpc_method="wakuext_updateMailservers", peer, response
|
2021-09-08 18:05:39 +00:00
|
|
|
|
|
|
|
proc setMailserver*(peer: string): string =
|
2021-09-17 16:58:33 +00:00
|
|
|
result = callPrivateRPC("setMailserver".prefix, %* [peer])
|
|
|
|
info "setMailserver", topics="mailserver-interaction", rpc_method="wakuext_setMailserver", peer, result
|
2021-09-08 18:05:39 +00:00
|
|
|
|
|
|
|
proc delete*(peer: string) =
|
2021-09-17 16:58:33 +00:00
|
|
|
let response = callPrivateRPC("mailservers_deleteMailserver", %* [peer])
|
|
|
|
info "delete", topics="mailserver-interaction", rpc_method="mailservers_deleteMailserver", peer, response
|
2021-09-08 18:05:39 +00:00
|
|
|
|
|
|
|
proc requestAllHistoricMessages*(): string =
|
2021-09-17 16:58:33 +00:00
|
|
|
result = callPrivateRPC("requestAllHistoricMessages".prefix, %*[])
|
|
|
|
info "requestAllHistoricMessages", topics="mailserver-interaction", rpc_method="mailservers_requestAllHistoricMessages", result
|
2021-09-08 18:05:39 +00:00
|
|
|
|
|
|
|
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 =
|
2021-09-17 16:58:33 +00:00
|
|
|
result = callPrivateRPC("syncChatFromSyncedFrom".prefix, %*[chatId])
|
|
|
|
info "syncChatFromSyncedFrom", topics="mailserver-interaction", rpc_method="wakuext_syncChatFromSyncedFrom", chatId, result
|
2021-09-08 18:05:39 +00:00
|
|
|
|
|
|
|
proc fillGaps*(chatId: string, messageIds: seq[string]): string =
|
2021-09-17 16:58:33 +00:00
|
|
|
result = callPrivateRPC("fillGaps".prefix, %*[chatId, messageIds])
|
|
|
|
info "fillGaps", topics="mailserver-interaction", rpc_method="wakuext_fillGaps", chatId, messageIds, result
|