fix: code review
This commit is contained in:
parent
55466416d6
commit
17477b0c45
|
@ -451,18 +451,36 @@ QtObject:
|
|||
|
||||
proc asyncMessageLoad*(self: ChatsView, chatId: string) {.slot.} =
|
||||
spawnAndSend(self, "asyncMessageLoaded") do: # Call self.ensResolved(string) when ens is resolved
|
||||
|
||||
var messages: JsonNode
|
||||
var msgCallSuccess: bool
|
||||
let msgCallResult = rpcChatMessages(chatId, newJString(""), 20, msgCallSuccess)
|
||||
if(msgCallSuccess):
|
||||
messages = msgCallResult.parseJson()["result"]
|
||||
|
||||
var reactions: JsonNode
|
||||
var reactionsCallSuccess: bool
|
||||
let reactionsCallResult = rpcReactions(chatId, newJString(""), 20, reactionsCallSuccess)
|
||||
if(reactionsCallSuccess):
|
||||
reactions = reactionsCallResult.parseJson()["result"]
|
||||
|
||||
|
||||
$(%*{
|
||||
"chatId": chatId,
|
||||
"messages": callPrivateRPC("chatMessages".prefix, %* [chatId, "", 20]).parseJson()["result"],
|
||||
"reactions": callPrivateRPC("emojiReactionsByChatID".prefix, %* [chatId, "", 20]).parseJson()["result"]
|
||||
"messages": messages,
|
||||
"reactions": reactions
|
||||
})
|
||||
|
||||
proc asyncMessageLoaded*(self: ChatsView, rpcResponse: string) {.slot.} =
|
||||
let rpcResponseObj = rpcResponse.parseJson
|
||||
let chatMessages = parseChatMessagesResponse(rpcResponseObj["chatId"].getStr, rpcResponseObj["messages"])
|
||||
let reactions = parseReactionsResponse(rpcResponseObj["chatId"].getStr, rpcResponseObj["reactions"])
|
||||
self.status.chat.chatMessages(rpcResponseObj["chatId"].getStr, true, chatMessages[0], chatMessages[1])
|
||||
self.status.chat.chatReactions(rpcResponseObj["chatId"].getStr, true, reactions[0], reactions[1])
|
||||
|
||||
if(rpcResponseObj["messages"].kind != JNull):
|
||||
let chatMessages = parseChatMessagesResponse(rpcResponseObj["chatId"].getStr, rpcResponseObj["messages"])
|
||||
self.status.chat.chatMessages(rpcResponseObj["chatId"].getStr, true, chatMessages[0], chatMessages[1])
|
||||
|
||||
if(rpcResponseObj["reactions"].kind != JNull):
|
||||
let reactions = parseReactionsResponse(rpcResponseObj["chatId"].getStr, rpcResponseObj["reactions"])
|
||||
self.status.chat.chatReactions(rpcResponseObj["chatId"].getStr, true, reactions[0], reactions[1])
|
||||
|
||||
proc hideLoadingIndicator*(self: ChatsView) {.slot.} =
|
||||
self.loadingMessages = false
|
||||
|
|
|
@ -62,6 +62,14 @@ proc parseChatMessagesResponse*(chatId: string, rpcResult: JsonNode): (string, s
|
|||
messages.add(jsonMsg.toMessage)
|
||||
return (rpcResult{"cursor"}.getStr, messages)
|
||||
|
||||
proc rpcChatMessages*(chatId: string, cursorVal: JsonNode, limit: int, success: var bool): string =
|
||||
success = true
|
||||
try:
|
||||
result = callPrivateRPC("chatMessages".prefix, %* [chatId, cursorVal, limit])
|
||||
except RpcException as e:
|
||||
success = false
|
||||
result = e.msg
|
||||
|
||||
proc chatMessages*(chatId: string, cursor: string = ""): (string, seq[Message]) =
|
||||
var cursorVal: JsonNode
|
||||
|
||||
|
@ -70,8 +78,10 @@ proc chatMessages*(chatId: string, cursor: string = ""): (string, seq[Message])
|
|||
else:
|
||||
cursorVal = newJString(cursor)
|
||||
|
||||
let callRPCResult = parseJson(callPrivateRPC("chatMessages".prefix, %* [chatId, cursorVal, 20]))["result"]
|
||||
return parseChatMessagesResponse(chatId, callRPCResult)
|
||||
var success: bool
|
||||
let callResult = rpcChatMessages(chatId, cursorVal, 20, success)
|
||||
if success:
|
||||
result = parseChatMessagesResponse(chatId, callResult.parseJson()["result"])
|
||||
|
||||
proc parseReactionsResponse*(chatId: string, rpcResult: JsonNode): (string, seq[Reaction]) =
|
||||
var reactions: seq[Reaction] = @[]
|
||||
|
@ -80,6 +90,14 @@ proc parseReactionsResponse*(chatId: string, rpcResult: JsonNode): (string, seq[
|
|||
reactions.add(jsonMsg.toReaction)
|
||||
return (rpcResult{"cursor"}.getStr, reactions)
|
||||
|
||||
proc rpcReactions*(chatId: string, cursorVal: JsonNode, limit: int, success: var bool): string =
|
||||
success = true
|
||||
try:
|
||||
result = callPrivateRPC("emojiReactionsByChatID".prefix, %* [chatId, cursorVal, limit])
|
||||
except RpcException as e:
|
||||
success = false
|
||||
result = e.msg
|
||||
|
||||
proc getEmojiReactionsByChatId*(chatId: string, cursor: string = ""): (string, seq[Reaction]) =
|
||||
var cursorVal: JsonNode
|
||||
|
||||
|
@ -88,8 +106,10 @@ proc getEmojiReactionsByChatId*(chatId: string, cursor: string = ""): (string, s
|
|||
else:
|
||||
cursorVal = newJString(cursor)
|
||||
|
||||
let rpcResult = parseJson(callPrivateRPC("emojiReactionsByChatID".prefix, %* [chatId, cursorVal, 20]))["result"]
|
||||
return parseReactionsResponse(chatId, rpcResult)
|
||||
var success: bool
|
||||
let rpcResult = rpcReactions(chatId, cursorVal, 20, success)
|
||||
if success:
|
||||
result = parseReactionsResponse(chatId, rpcResult.parseJson()["result"])
|
||||
|
||||
proc addEmojiReaction*(chatId: string, messageId: string, emojiId: int): seq[Reaction] =
|
||||
let rpcResult = parseJson(callPrivateRPC("sendEmojiReaction".prefix, %* [chatId, messageId, emojiId]))["result"]
|
||||
|
|
Loading…
Reference in New Issue