status-lib/status/signals/mailserver.nim

52 lines
2.0 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
type HistoryRequestCompletedSignal* = ref object of Signal
type HistoryRequestFailedSignal* = ref object of Signal
errorMessage*: string
error*: bool
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
proc fromEvent*(T: type HistoryRequestCompletedSignal, jsonSignal: JsonNode): HistoryRequestCompletedSignal =
result = HistoryRequestCompletedSignal()
result.signalType = SignalType.HistoryRequestCompleted
proc fromEvent*(T: type HistoryRequestFailedSignal, jsonSignal: JsonNode): HistoryRequestFailedSignal =
result = HistoryRequestFailedSignal()
result.signalType = SignalType.HistoryRequestStarted
if jsonSignal["event"].kind != JNull:
result.errorMessage = jsonSignal["event"]{"errorMessage"}.getStr()
result.error = result.errorMessage != ""