feat: mailserver request signals (#46)

This commit is contained in:
Richard Ramos 2021-09-28 14:41:40 -04:00 committed by GitHub
parent 38a405b1c1
commit c07e04e976
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 1 deletions

View File

@ -24,6 +24,9 @@ proc decode*(jsonSignal: JsonNode): Signal =
of SignalType.CommunityFound: CommunitySignal.fromEvent(jsonSignal)
of SignalType.Stats: StatsSignal.fromEvent(jsonSignal)
of SignalType.ChroniclesLogs: ChroniclesLogsSignal.fromEvent(jsonSignal)
of SignalType.HistoryRequestCompleted: HistoryRequestCompletedSignal.fromEvent(jsonSignal)
of SignalType.HistoryRequestStarted: HistoryRequestStartedSignal.fromEvent(jsonSignal)
of SignalType.HistoryRequestFailed: HistoryRequestFailedSignal.fromEvent(jsonSignal)
else: Signal()
result.signalType = signalType

View File

@ -13,6 +13,13 @@ type MailserverRequestCompletedSignal* = ref object of Signal
type MailserverRequestExpiredSignal* = ref object of Signal
# TODO
type HistoryRequestStartedSignal* = ref object of Signal
type HistoryRequestCompletedSignal* = ref object of Signal
type HistoryRequestFailedSignal* = ref object of Signal
errorMessage*: string
error*: bool
proc fromEvent*(T: type MailserverRequestCompletedSignal, jsonSignal: JsonNode): MailserverRequestCompletedSignal =
result = MailserverRequestCompletedSignal()
result.signalType = SignalType.MailserverRequestCompleted
@ -26,4 +33,19 @@ proc fromEvent*(T: type MailserverRequestCompletedSignal, jsonSignal: JsonNode):
proc fromEvent*(T: type MailserverRequestExpiredSignal, jsonSignal: JsonNode): MailserverRequestExpiredSignal =
# TODO: parse signal
result = MailserverRequestExpiredSignal()
result.signalType = SignalType.MailserverRequestExpired
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 != ""

View File

@ -21,6 +21,9 @@ type SignalType* {.pure.} = enum
CommunityFound = "community.found"
Stats = "stats"
ChroniclesLogs = "chronicles-log"
HistoryRequestStarted = "history.request.started"
HistoryRequestCompleted = "history.request.completed"
HistoryRequestFailed = "history.request.failed"
Unknown
proc event*(self:SignalType):string =