status-lib/status/signals/mailserver.nim

89 lines
3.5 KiB
Nim
Raw Normal View History

2021-09-08 18:05:39 +00:00
import json
import base
2021-09-08 20:55:37 +00:00
import signal_type
2021-09-08 18:05:39 +00:00
type MailserverRequestCompletedSignal* = ref object of Signal
requestID*: string
lastEnvelopeHash*: string
cursor*: string
errorMessage*: string
error*: bool
type MailserverRequestExpiredSignal* = ref object of Signal
# TODO
2021-09-28 18:41:40 +00:00
type HistoryRequestStartedSignal* = ref object of Signal
requestId*: string
numBatches*: int
type HistoryRequestBatchProcessedSignal* = ref object of Signal
requestId*: string
batchIndex*: int
numBatches*: int
2021-09-28 18:41:40 +00:00
type HistoryRequestCompletedSignal* = ref object of Signal
requestId*: string
2021-09-28 18:41:40 +00:00
type HistoryRequestFailedSignal* = ref object of Signal
requestId*: string
2021-09-28 18:41:40 +00:00
errorMessage*: string
error*: bool
2022-01-06 17:04:38 +00:00
type MailserverAvailableSignal* = ref object of Signal
address*: string
type MailserverChangedSignal* = ref object of Signal
address*: string
2021-09-08 20:55:37 +00:00
proc fromEvent*(T: type MailserverRequestCompletedSignal, jsonSignal: JsonNode): MailserverRequestCompletedSignal =
result = MailserverRequestCompletedSignal()
result.signalType = SignalType.MailserverRequestCompleted
2021-09-08 18:05:39 +00:00
if jsonSignal["event"].kind != JNull:
2021-09-08 20:55:37 +00:00
result.requestID = jsonSignal["event"]{"requestID"}.getStr()
result.lastEnvelopeHash = jsonSignal["event"]{"lastEnvelopeHash"}.getStr()
result.cursor = jsonSignal["event"]{"cursor"}.getStr()
result.errorMessage = jsonSignal["event"]{"errorMessage"}.getStr()
result.error = result.errorMessage != ""
2021-09-08 18:05:39 +00:00
2021-09-08 20:55:37 +00:00
proc fromEvent*(T: type MailserverRequestExpiredSignal, jsonSignal: JsonNode): MailserverRequestExpiredSignal =
2021-09-08 18:05:39 +00:00
# TODO: parse signal
2021-09-08 20:55:37 +00:00
result = MailserverRequestExpiredSignal()
2021-09-28 18:41:40 +00:00
result.signalType = SignalType.MailserverRequestExpired
proc fromEvent*(T: type HistoryRequestStartedSignal, jsonSignal: JsonNode): HistoryRequestStartedSignal =
result = HistoryRequestStartedSignal()
result.signalType = SignalType.HistoryRequestStarted
result.requestId = jsonSignal["event"]{"requestId"}.getStr()
result.numBatches = jsonSIgnal["event"]{"numBatches"}.getInt()
proc fromEvent*(T: type HistoryRequestBatchProcessedSignal, jsonSignal: JsonNode): HistoryRequestBatchProcessedSignal =
result = HistoryRequestBatchProcessedSignal()
result.signalType = SignalType.HistoryRequestBatchProcessed
result.requestId = jsonSignal["event"]{"requestId"}.getStr()
result.batchIndex = jsonSIgnal["event"]{"batchIndex"}.getInt()
result.numBatches = jsonSIgnal["event"]{"numBatches"}.getInt()
2021-09-28 18:41:40 +00:00
proc fromEvent*(T: type HistoryRequestCompletedSignal, jsonSignal: JsonNode): HistoryRequestCompletedSignal =
result = HistoryRequestCompletedSignal()
result.signalType = SignalType.HistoryRequestCompleted
result.requestId = jsonSignal["event"]{"requestId"}.getStr()
2021-09-28 18:41:40 +00:00
proc fromEvent*(T: type HistoryRequestFailedSignal, jsonSignal: JsonNode): HistoryRequestFailedSignal =
result = HistoryRequestFailedSignal()
result.signalType = SignalType.HistoryRequestStarted
result.requestId = jsonSignal["event"]{"requestId"}.getStr()
2021-09-28 18:41:40 +00:00
if jsonSignal["event"].kind != JNull:
result.errorMessage = jsonSignal["event"]{"errorMessage"}.getStr()
result.error = result.errorMessage != ""
2022-01-06 17:04:38 +00:00
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()