status-lib/status/chat/utils.nim

13 lines
467 B
Nim
Raw Normal View History

2021-09-08 18:05:39 +00:00
import json
import ../types/[message, chat]
proc formatChatUpdate*(response: JsonNode): (seq[Chat], seq[Message]) =
var chats: seq[Chat] = @[]
var messages: seq[Message] = @[]
if response["result"]{"messages"} != nil:
for jsonMsg in response["result"]["messages"]:
messages.add(jsonMsg.toMessage())
if response["result"]{"chats"} != nil:
for jsonChat in response["result"]["chats"]:
chats.add(jsonChat.toChat)
result = (chats, messages)