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 NimQml, Tables, json, sequtils, chronicles, times, re, sugar, strutils, os, strformat, algorithm
|
||||||
import ../../status/[status, mailservers]
|
import ../../status/[status, mailservers]
|
||||||
import ../../status/libstatus/chat as libstatus_chat
|
|
||||||
import ../../status/constants
|
import ../../status/constants
|
||||||
import ../../status/utils as status_utils
|
import ../../status/utils as status_utils
|
||||||
import ../../status/chat as status_chat
|
import ../../status/chat as status_chat
|
||||||
|
@ -37,7 +36,7 @@ const getLinkPreviewDataTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.
|
||||||
var success: bool
|
var success: bool
|
||||||
# We need to call directly on libstatus because going through the status model is not thread safe
|
# We need to call directly on libstatus because going through the status model is not thread safe
|
||||||
let
|
let
|
||||||
response = libstatus_chat.getLinkPreviewData(arg.link, success)
|
response = status_chat.getLinkPreviewData(arg.link, success)
|
||||||
responseJson = %* { "result": %response, "success": %success, "uuid": %arg.uuid }
|
responseJson = %* { "result": %response, "success": %success, "uuid": %arg.uuid }
|
||||||
arg.finish(responseJson)
|
arg.finish(responseJson)
|
||||||
|
|
||||||
|
@ -55,19 +54,19 @@ const asyncMessageLoadTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.}
|
||||||
let arg = decode[AsyncMessageLoadTaskArg](argEncoded)
|
let arg = decode[AsyncMessageLoadTaskArg](argEncoded)
|
||||||
var messages: JsonNode
|
var messages: JsonNode
|
||||||
var msgCallSuccess: bool
|
var msgCallSuccess: bool
|
||||||
let msgCallResult = rpcChatMessages(arg.chatId, newJString(""), 20, msgCallSuccess)
|
let msgCallResult = status_chat.rpcChatMessages(arg.chatId, newJString(""), 20, msgCallSuccess)
|
||||||
if(msgCallSuccess):
|
if(msgCallSuccess):
|
||||||
messages = msgCallResult.parseJson()["result"]
|
messages = msgCallResult.parseJson()["result"]
|
||||||
|
|
||||||
var reactions: JsonNode
|
var reactions: JsonNode
|
||||||
var reactionsCallSuccess: bool
|
var reactionsCallSuccess: bool
|
||||||
let reactionsCallResult = rpcReactions(arg.chatId, newJString(""), 20, reactionsCallSuccess)
|
let reactionsCallResult = status_chat.rpcReactions(arg.chatId, newJString(""), 20, reactionsCallSuccess)
|
||||||
if(reactionsCallSuccess):
|
if(reactionsCallSuccess):
|
||||||
reactions = reactionsCallResult.parseJson()["result"]
|
reactions = reactionsCallResult.parseJson()["result"]
|
||||||
|
|
||||||
var pinnedMessages: JsonNode
|
var pinnedMessages: JsonNode
|
||||||
var pinnedMessagesCallSuccess: bool
|
var pinnedMessagesCallSuccess: bool
|
||||||
let pinnedMessagesCallResult = rpcPinnedChatMessages(arg.chatId, newJString(""), 20, pinnedMessagesCallSuccess)
|
let pinnedMessagesCallResult = status_chat.rpcPinnedChatMessages(arg.chatId, newJString(""), 20, pinnedMessagesCallSuccess)
|
||||||
if(pinnedMessagesCallSuccess):
|
if(pinnedMessagesCallSuccess):
|
||||||
pinnedMessages = pinnedMessagesCallResult.parseJson()["result"]
|
pinnedMessages = pinnedMessagesCallResult.parseJson()["result"]
|
||||||
|
|
||||||
|
@ -689,17 +688,17 @@ QtObject:
|
||||||
|
|
||||||
let messages = rpcResponseObj{"messages"}
|
let messages = rpcResponseObj{"messages"}
|
||||||
if(messages != nil and messages.kind != JNull):
|
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])
|
self.status.chat.chatMessages(chatId, true, chatMessages[0], chatMessages[1])
|
||||||
|
|
||||||
let rxns = rpcResponseObj{"reactions"}
|
let rxns = rpcResponseObj{"reactions"}
|
||||||
if(rxns != nil and rxns.kind != JNull):
|
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])
|
self.status.chat.chatReactions(chatId, true, reactions[0], reactions[1])
|
||||||
|
|
||||||
let pinnedMsgs = rpcResponseObj{"pinnedMessages"}
|
let pinnedMsgs = rpcResponseObj{"pinnedMessages"}
|
||||||
if(pinnedMsgs != nil and pinnedMsgs.kind != JNull):
|
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])
|
self.status.chat.pinnedMessagesByChatID(chatId, pinnedMessages[0], pinnedMessages[1])
|
||||||
|
|
||||||
proc asyncActivityNotificationLoaded*(self: ChatsView, rpcResponse: string) {.slot.} =
|
proc asyncActivityNotificationLoaded*(self: ChatsView, rpcResponse: string) {.slot.} =
|
||||||
|
|
|
@ -574,3 +574,20 @@ proc markActivityCenterNotificationsRead*(self: ChatModel, ids: seq[string]): st
|
||||||
proc unreadActivityCenterNotificationsCount*(self: ChatModel): int =
|
proc unreadActivityCenterNotificationsCount*(self: ChatModel): int =
|
||||||
status_chat.unreadActivityCenterNotificationsCount()
|
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