perf(@desktop/chat): make mark all messages read async
This commit is contained in:
parent
0d5cf71df5
commit
e2ca49b097
|
@ -93,13 +93,13 @@ QtObject:
|
|||
if (self.chats.chats.len == 0): return
|
||||
let selectedChannel = self.getChannel(channelIndex)
|
||||
if (selectedChannel == nil): return
|
||||
discard self.status.chat.markAllChannelMessagesRead(selectedChannel.id)
|
||||
self.status.chat.asyncMarkAllChannelMessagesRead(selectedChannel.id)
|
||||
|
||||
proc markChatItemAsRead*(self: ChannelView, id: string) {.slot.} =
|
||||
if (self.chats.chats.len == 0): return
|
||||
let selectedChannel = self.getChannelById(id)
|
||||
if (selectedChannel == nil): return
|
||||
discard self.status.chat.markAllChannelMessagesRead(selectedChannel.id)
|
||||
self.status.chat.asyncMarkAllChannelMessagesRead(selectedChannel.id)
|
||||
|
||||
proc clearUnreadIfNeeded*(self: ChannelView, channel: var Chat) =
|
||||
if (not channel.isNil and (channel.unviewedMessagesCount > 0 or channel.mentionsCount > 0)):
|
||||
|
@ -166,7 +166,7 @@ QtObject:
|
|||
if not self.communities.activeCommunity.active:
|
||||
self.previousActiveChannelIndex = self.chats.chats.findIndexById(self.activeChannel.id)
|
||||
|
||||
discard self.status.chat.markAllChannelMessagesRead(self.activeChannel.id)
|
||||
self.status.chat.asyncMarkAllChannelMessagesRead(self.activeChannel.id)
|
||||
|
||||
self.activeChannelChanged()
|
||||
|
||||
|
|
|
@ -367,25 +367,37 @@ QtObject:
|
|||
let reactions = status_chat.removeEmojiReaction(emojiReactionId)
|
||||
self.events.emit("reactionsLoaded", ReactionsLoadedArgs(reactions: reactions))
|
||||
|
||||
proc markAllChannelMessagesRead*(self: ChatModel, chatId: string): JsonNode =
|
||||
var response = status_chat.markAllRead(chatId)
|
||||
proc onMarkMessagesRead(self: ChatModel, response: string, chatId: string): JsonNode =
|
||||
result = parseJson(response)
|
||||
if self.channels.hasKey(chatId):
|
||||
self.channels[chatId].unviewedMessagesCount = 0
|
||||
self.channels[chatId].mentionsCount = 0
|
||||
self.events.emit("channelUpdate", ChatUpdateArgs(messages: @[], chats: @[self.channels[chatId]], contacts: @[]))
|
||||
|
||||
proc onAsyncMarkMessagesRead(self: ChatModel, response: string) {.slot.} =
|
||||
let parsedResponse = parseJson(response)
|
||||
discard self.onMarkMessagesRead(parsedResponse{"response"}.getStr, parsedResponse{"chatId"}.getStr)
|
||||
|
||||
proc markAllChannelMessagesRead*(self: ChatModel, chatId: string): JsonNode =
|
||||
var response = status_chat.markAllRead(chatId)
|
||||
return self.onMarkMessagesRead(response, chatId)
|
||||
|
||||
proc asyncMarkAllChannelMessagesRead*(self: ChatModel, chatId: string) =
|
||||
let arg = AsyncMarkAllReadTaskArg(
|
||||
tptr: cast[ByteAddress](asyncMarkAllReadTask),
|
||||
vptr: cast[ByteAddress](self.vptr),
|
||||
slot: "onAsyncMarkMessagesRead",
|
||||
chatId: chatId,
|
||||
)
|
||||
self.tasks.threadpool.start(arg)
|
||||
|
||||
proc markMessagesSeen*(self: ChatModel, chatId: string, messageIds: seq[string]): JsonNode =
|
||||
var response = status_chat.markMessagesSeen(chatId, messageIds)
|
||||
result = parseJson(response)
|
||||
if self.channels.hasKey(chatId):
|
||||
self.channels[chatId].unviewedMessagesCount = 0
|
||||
self.channels[chatId].mentionsCount = 0
|
||||
self.events.emit("channelUpdate", ChatUpdateArgs(messages: @[], chats: @[self.channels[chatId]], contacts: @[]))
|
||||
return self.onMarkMessagesRead(response, chatId)
|
||||
|
||||
proc confirmJoiningGroup*(self: ChatModel, chatId: string) =
|
||||
var response = status_chat.confirmJoiningGroup(chatId)
|
||||
self.emitUpdate(response)
|
||||
var response = status_chat.confirmJoiningGroup(chatId)
|
||||
self.emitUpdate(response)
|
||||
|
||||
proc renameGroup*(self: ChatModel, chatId: string, newName: string) =
|
||||
var response = status_chat.renameGroup(chatId, newName)
|
||||
|
|
|
@ -49,6 +49,20 @@ const asyncSearchMessagesInChatsAndCommunitiesTask: Task = proc(argEncoded: stri
|
|||
}
|
||||
arg.finish(responseJson)
|
||||
|
||||
#################################################
|
||||
# Async mark messages read
|
||||
#################################################
|
||||
type
|
||||
AsyncMarkAllReadTaskArg = ref object of QObjectTaskArg
|
||||
chatId: string
|
||||
|
||||
const asyncMarkAllReadTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
|
||||
let arg = decode[AsyncMarkAllReadTaskArg](argEncoded)
|
||||
arg.finish(%*{
|
||||
"response": status_chat.markAllRead(arg.chatId),
|
||||
"chatId": arg.chatId,
|
||||
})
|
||||
|
||||
#################################################
|
||||
# Async load messages
|
||||
#################################################
|
||||
|
|
Loading…
Reference in New Issue