chore(@desktop/general): json common properties moved to the more general location

This commit is contained in:
Sale Djenic 2021-09-02 13:05:10 +02:00 committed by Iuri Matias
parent 8015235eea
commit 71360d4362
4 changed files with 39 additions and 38 deletions

View File

@ -14,6 +14,9 @@ import tasks/[qt, task_runner_impl]
import signals/messages
import ens, accounts
include chat/utils
include chat/async_tasks
logScope:
topics = "chat-model"
@ -69,9 +72,6 @@ type
channelId*: string
notificationTypes*: seq[ActivityCenterNotificationType]
include chat/utils
include chat/async_tasks
QtObject:
type ChatModel* = ref object of QObject
publicKey*: string

View File

@ -1,3 +1,5 @@
include ../utils/json_utils
type
AsyncSearchMessagesTaskArg = ref object of QObjectTaskArg
searchTerm: string

View File

@ -8,37 +8,3 @@ proc formatChatUpdate(response: JsonNode): (seq[Chat], seq[Message]) =
for jsonChat in response["result"]["chats"]:
chats.add(jsonChat.toChat)
result = (chats, messages)
# This may be moved later to some common file.
# We may create a macro for these template procedures aslo.
template getProp(obj: JsonNode, prop: string, value: var typedesc[int]): bool =
var success = false
if (obj.kind == JObject and obj.contains(prop)):
value = obj[prop].getInt
success = true
success
template getProp(obj: JsonNode, prop: string, value: var typedesc[string]): bool =
var success = false
if (obj.kind == JObject and obj.contains(prop)):
value = obj[prop].getStr
success = true
success
template getProp(obj: JsonNode, prop: string, value: var typedesc[float]): bool =
var success = false
if (obj.kind == JObject and obj.contains(prop)):
value = obj[prop].getFloat
success = true
success
template getProp(obj: JsonNode, prop: string, value: var typedesc[JsonNode]): bool =
var success = false
if (obj.kind == JObject and obj.contains(prop)):
value = obj[prop]
success = true
success

View File

@ -0,0 +1,33 @@
import json
template getProp(obj: JsonNode, prop: string, value: var typedesc[int]): bool =
var success = false
if (obj.kind == JObject and obj.contains(prop)):
value = obj[prop].getInt
success = true
success
template getProp(obj: JsonNode, prop: string, value: var typedesc[string]): bool =
var success = false
if (obj.kind == JObject and obj.contains(prop)):
value = obj[prop].getStr
success = true
success
template getProp(obj: JsonNode, prop: string, value: var typedesc[float]): bool =
var success = false
if (obj.kind == JObject and obj.contains(prop)):
value = obj[prop].getFloat
success = true
success
template getProp(obj: JsonNode, prop: string, value: var typedesc[JsonNode]): bool =
var success = false
if (obj.kind == JObject and obj.contains(prop)):
value = obj[prop]
success = true
success