refactor chat usage of libstatus
This commit is contained in:
parent
2e8af89adf
commit
a90aa4cc3a
|
@ -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.} =
|
||||
|
|
|
@ -573,4 +573,21 @@ proc markActivityCenterNotificationsRead*(self: ChatModel, ids: seq[string]): st
|
|||
|
||||
proc unreadActivityCenterNotificationsCount*(self: ChatModel): int =
|
||||
status_chat.unreadActivityCenterNotificationsCount()
|
||||
|
||||
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue