diff --git a/src/app/chat/view.nim b/src/app/chat/view.nim index 341221dd3b..1ce49da58f 100644 --- a/src/app/chat/view.nim +++ b/src/app/chat/view.nim @@ -91,6 +91,7 @@ QtObject: result.setup() + proc getMessageListIndexById(self: ChatsView, id: string): int proc getChannel*(self: ChatsView, index: int): Chat = if (self.communities.activeCommunity.active): @@ -289,7 +290,11 @@ QtObject: notify = activeChannelChanged proc setActiveChannel*(self: ChatsView, channel: string) {.slot.} = - if(channel == ""): return + if (self.activeChannel.id == "" and channel == backToFirstChat): + self.setActiveChannelByIndex(0) + return + + if(channel == "" or channel == backToFirstChat): return let selectedChannel = self.getChannelById(channel) self.activeChannel.setChatItem(selectedChannel) @@ -561,6 +566,8 @@ QtObject: if (self.chats.chats.len == 0): return let selectedChannel = self.getChannel(channelIndex) if (selectedChannel == nil): return + if (self.activeChannel.id == selectedChannel.id): + self.activeChannel.chatItem = nil self.status.chat.leave(selectedChannel.id) self.status.mailservers.deleteMailserverTopic(selectedChannel.id) @@ -571,8 +578,11 @@ QtObject: proc removeChat*(self: ChatsView, chatId: string) = discard self.chats.removeChatItemFromList(chatId) if (self.messageList.hasKey(chatId)): + let index = self.getMessageListIndexById(chatId) + self.beginRemoveRows(newQModelIndex(), index, index) self.messageList[chatId].delete self.messageList.del(chatId) + self.endRemoveRows() proc toggleReaction*(self: ChatsView, messageId: string, emojiId: int) {.slot.} = if self.activeChannel.id == status_utils.getTimelineChatId(): @@ -738,9 +748,16 @@ QtObject: ChatViewRoles.MessageList.int:"messages" }.toTable - proc getMessageListIndex(self: ChatsView):int {.slot.} = + proc getMessageListIndex(self: ChatsView): int {.slot.} = var idx = -1 for msg in toSeq(self.messageList.values): idx = idx + 1 if(self.activeChannel.id == msg.id): return idx return idx + + proc getMessageListIndexById(self: ChatsView, id: string): int {.slot.} = + var idx = -1 + for msg in toSeq(self.messageList.values): + idx = idx + 1 + if(id == msg.id): return idx + return idx diff --git a/src/status/chat.nim b/src/status/chat.nim index 4637d8b3e0..265bcae77d 100644 --- a/src/status/chat.nim +++ b/src/status/chat.nim @@ -18,6 +18,8 @@ import ens logScope: topics = "chat-model" +const backToFirstChat* = "__goBackToFirstChat" + type ChatUpdateArgs* = ref object of Args chats*: seq[Chat] @@ -215,7 +217,7 @@ proc leave*(self: ChatModel, chatId: string) = self.channels.del(chatId) discard status_chat.clearChatHistory(chatId) self.events.emit("channelLeft", ChatIdArg(chatId: chatId)) - self.events.emit("activeChannelChanged", ChatIdArg(chatId: "")) + self.events.emit("activeChannelChanged", ChatIdArg(chatId: backToFirstChat)) proc clearHistory*(self: ChatModel, chatId: string) = discard status_chat.clearChatHistory(chatId)