chore(@desktop/general): json common properties moved to the more general location
This commit is contained in:
parent
8015235eea
commit
71360d4362
|
@ -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
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
include ../utils/json_utils
|
||||
|
||||
type
|
||||
AsyncSearchMessagesTaskArg = ref object of QObjectTaskArg
|
||||
searchTerm: string
|
||||
|
|
|
@ -7,38 +7,4 @@ proc formatChatUpdate(response: JsonNode): (seq[Chat], seq[Message]) =
|
|||
if response["result"]{"chats"} != nil:
|
||||
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
|
||||
result = (chats, messages)
|
|
@ -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
|
Loading…
Reference in New Issue