From a90aa4cc3acd42d8e30e32417de2c463b413e65b Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 8 Jun 2021 16:56:58 -0400 Subject: [PATCH] refactor chat usage of libstatus --- src/app/chat/view.nim | 15 +++++++-------- src/status/chat.nim | 19 ++++++++++++++++++- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/app/chat/view.nim b/src/app/chat/view.nim index fdb6775f83..53c143d190 100644 --- a/src/app/chat/view.nim +++ b/src/app/chat/view.nim @@ -1,6 +1,5 @@ import NimQml, Tables, json, sequtils, chronicles, times, re, sugar, strutils, os, strformat, algorithm import ../../status/[status, mailservers] -import ../../status/libstatus/chat as libstatus_chat import ../../status/constants import ../../status/utils as status_utils import ../../status/chat as status_chat @@ -37,7 +36,7 @@ const getLinkPreviewDataTask: Task = proc(argEncoded: string) {.gcsafe, nimcall. var success: bool # We need to call directly on libstatus because going through the status model is not thread safe let - response = libstatus_chat.getLinkPreviewData(arg.link, success) + response = status_chat.getLinkPreviewData(arg.link, success) responseJson = %* { "result": %response, "success": %success, "uuid": %arg.uuid } arg.finish(responseJson) @@ -55,19 +54,19 @@ const asyncMessageLoadTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} let arg = decode[AsyncMessageLoadTaskArg](argEncoded) var messages: JsonNode var msgCallSuccess: bool - let msgCallResult = rpcChatMessages(arg.chatId, newJString(""), 20, msgCallSuccess) + let msgCallResult = status_chat.rpcChatMessages(arg.chatId, newJString(""), 20, msgCallSuccess) if(msgCallSuccess): messages = msgCallResult.parseJson()["result"] var reactions: JsonNode var reactionsCallSuccess: bool - let reactionsCallResult = rpcReactions(arg.chatId, newJString(""), 20, reactionsCallSuccess) + let reactionsCallResult = status_chat.rpcReactions(arg.chatId, newJString(""), 20, reactionsCallSuccess) if(reactionsCallSuccess): reactions = reactionsCallResult.parseJson()["result"] var pinnedMessages: JsonNode var pinnedMessagesCallSuccess: bool - let pinnedMessagesCallResult = rpcPinnedChatMessages(arg.chatId, newJString(""), 20, pinnedMessagesCallSuccess) + let pinnedMessagesCallResult = status_chat.rpcPinnedChatMessages(arg.chatId, newJString(""), 20, pinnedMessagesCallSuccess) if(pinnedMessagesCallSuccess): pinnedMessages = pinnedMessagesCallResult.parseJson()["result"] @@ -689,17 +688,17 @@ QtObject: let messages = rpcResponseObj{"messages"} if(messages != nil and messages.kind != JNull): - let chatMessages = parseChatMessagesResponse(messages) + let chatMessages = status_chat.parseChatMessagesResponse(chatId, messages) self.status.chat.chatMessages(chatId, true, chatMessages[0], chatMessages[1]) let rxns = rpcResponseObj{"reactions"} if(rxns != nil and rxns.kind != JNull): - let reactions = parseReactionsResponse(chatId, rxns) + let reactions = status_chat.parseReactionsResponse(chatId, rxns) self.status.chat.chatReactions(chatId, true, reactions[0], reactions[1]) let pinnedMsgs = rpcResponseObj{"pinnedMessages"} if(pinnedMsgs != nil and pinnedMsgs.kind != JNull): - let pinnedMessages = parseChatPinnedMessagesResponse(pinnedMsgs) + let pinnedMessages = status_chat.parseChatMessagesResponse(chatId, pinnedMsgs, true) self.status.chat.pinnedMessagesByChatID(chatId, pinnedMessages[0], pinnedMessages[1]) proc asyncActivityNotificationLoaded*(self: ChatsView, rpcResponse: string) {.slot.} = diff --git a/src/status/chat.nim b/src/status/chat.nim index 18e5d9754e..3f84f3a3f8 100644 --- a/src/status/chat.nim +++ b/src/status/chat.nim @@ -573,4 +573,21 @@ proc markActivityCenterNotificationsRead*(self: ChatModel, ids: seq[string]): st proc unreadActivityCenterNotificationsCount*(self: ChatModel): int = status_chat.unreadActivityCenterNotificationsCount() - \ No newline at end of file + +proc getLinkPreviewData*(link: string, success: var bool): JsonNode = + result = status_chat.getLinkPreviewData(link, success) + +proc rpcChatMessages*(chatId: string, cursorVal: JsonNode, limit: int, success: var bool): string = + result = status_chat.rpcChatMessages(chatId, cursorVal, limit, success) + +proc rpcReactions*(chatId: string, cursorVal: JsonNode, limit: int, success: var bool): string = + result = status_chat.rpcReactions(chatId, cursorVal, limit, success) + +proc rpcPinnedChatMessages*(chatId: string, cursorVal: JsonNode, limit: int, success: var bool): string = + result = status_chat.rpcPinnedChatMessages(chatId, cursorVal, limit, success) + +proc parseReactionsResponse*(chatId: string, rpcResult: JsonNode): (string, seq[Reaction]) = + result = status_chat.parseReactionsResponse(chatId, rpcResult) + +proc parseChatMessagesResponse*(chatId: string, rpcResult: JsonNode, isPin: bool = false): (string, seq[Message]) = + result = status_chat.parseChatMessagesResponse(chatId, rpcResult, isPin)