feat(chat): clear unread messages count when changing channels
Closes #138
This commit is contained in:
parent
15dc98b44a
commit
2641986bbe
|
@ -1,5 +1,6 @@
|
|||
import NimQml
|
||||
import Tables
|
||||
import json
|
||||
|
||||
import ../../signals/types
|
||||
import ../../status/chat
|
||||
|
@ -43,7 +44,9 @@ QtObject:
|
|||
|
||||
proc setActiveChannelByIndex*(self: ChatsView, index: int) {.slot.} =
|
||||
if(self.chats.chats.len == 0): return
|
||||
|
||||
var response = self.status.chat.markAllChannelMessagesRead(self.activeChannel.id)
|
||||
if not response.hasKey("error"):
|
||||
self.chats.clearUnreadMessagesCount(self.activeChannel.chatItem)
|
||||
let selectedChannel = self.chats.getChannel(index)
|
||||
if self.activeChannel.id == selectedChannel.id: return
|
||||
self.activeChannel.setChatItem(selectedChannel)
|
||||
|
|
|
@ -98,3 +98,12 @@ QtObject:
|
|||
self.chats[0] = channel
|
||||
|
||||
self.dataChanged(topLeft, bottomRight, @[ChannelsRoles.Name.int, ChannelsRoles.LastMessage.int, ChannelsRoles.Timestamp.int, ChannelsRoles.LastMessage.int, ChannelsRoles.UnreadMessages.int, ChannelsRoles.Identicon.int, ChannelsRoles.LastMessage.int])
|
||||
|
||||
proc clearUnreadMessagesCount*(self: ChannelsList, channel: ChatItem) =
|
||||
let idx = self.chats.findById(channel.id)
|
||||
let topLeft = self.createIndex(0, 0, nil)
|
||||
let bottomRight = self.createIndex(self.chats.len - 1, 0, nil)
|
||||
channel.unviewedMessagesCount = 0
|
||||
self.chats[idx] = channel
|
||||
|
||||
self.dataChanged(topLeft, bottomRight, @[ChannelsRoles.Name.int, ChannelsRoles.LastMessage.int, ChannelsRoles.Timestamp.int, ChannelsRoles.LastMessage.int, ChannelsRoles.UnreadMessages.int, ChannelsRoles.Identicon.int, ChannelsRoles.LastMessage.int])
|
||||
|
|
|
@ -124,3 +124,7 @@ proc sendMessage*(self: ChatModel, chatId: string, msg: string): string =
|
|||
proc chatMessages*(self: ChatModel, chatId: string) =
|
||||
let msgs = status_chat.chatMessages(chatId)
|
||||
self.events.emit("messagesLoaded", MsgsLoadedArgs(messages: msgs))
|
||||
|
||||
proc markAllChannelMessagesRead*(self: ChatModel, chatId: string): JsonNode =
|
||||
var response = status_chat.markAllRead(chatId)
|
||||
result = parseJson(response)
|
||||
|
|
|
@ -110,3 +110,6 @@ proc sendChatMessage*(chatId: string, msg: string): string =
|
|||
"contentType": 1
|
||||
}
|
||||
])
|
||||
|
||||
proc markAllRead*(chatId: string): string =
|
||||
callPrivateRPC("markAllRead".prefix, %* [chatId])
|
||||
|
|
Loading…
Reference in New Issue