From 3de0c699e387fcf8fd1116b6ac2cb755653a3eeb Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Wed, 27 Jul 2022 15:57:07 -0400 Subject: [PATCH] fix(chat_section): reset activeItem when the last channel is removed Fixes #6536 --- src/app/modules/main/chat_section/active_item.nim | 9 +++++++++ src/app/modules/main/chat_section/controller.nim | 4 +++- src/app/modules/main/chat_section/module.nim | 7 ++++++- src/app/modules/main/chat_section/view.nim | 3 +++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/app/modules/main/chat_section/active_item.nim b/src/app/modules/main/chat_section/active_item.nim index 323ddc02ba..8dd669cf97 100644 --- a/src/app/modules/main/chat_section/active_item.nim +++ b/src/app/modules/main/chat_section/active_item.nim @@ -24,6 +24,7 @@ QtObject: ################################################# # Forward declaration section proc activeSubItemChanged(self: ActiveItem) {.signal.} + proc idChanged(self: ActiveItem) {.signal.} ################################################# @@ -32,6 +33,13 @@ QtObject: self.activeSubItem.setActiveSubItemData(subItem) self.activeSubItemChanged() + # Used when there is no longer an active item (last channel was deleted) + proc resetActiveItemData*(self: ActiveItem) = + self.item = Item() + self.activeSubItem.setActiveSubItemData(SubItem()) + self.idChanged() + self.activeSubItemChanged() + proc getId(self: ActiveItem): string {.slot.} = if(self.item.isNil): return "" @@ -39,6 +47,7 @@ QtObject: QtProperty[string] id: read = getId + notify = idChanged proc getIsSubItemActive(self: ActiveItem): bool {.slot.} = if(self.activeSubItem.getId().len > 0): diff --git a/src/app/modules/main/chat_section/controller.nim b/src/app/modules/main/chat_section/controller.nim index e900854de7..4de2dd3c55 100644 --- a/src/app/modules/main/chat_section/controller.nim +++ b/src/app/modules/main/chat_section/controller.nim @@ -252,7 +252,9 @@ proc setActiveItemSubItem*(self: Controller, itemId: string, subItemId: string) self.activeItemId = itemId self.activeSubItemId = subItemId - self.messageService.asyncLoadInitialMessagesForChat(self.getActiveChatId()) + let chatId = self.getActiveChatId() + if chatId != "": + self.messageService.asyncLoadInitialMessagesForChat(chatId) # We need to take other actions here like notify status go that unviewed mentions count is updated and so... diff --git a/src/app/modules/main/chat_section/module.nim b/src/app/modules/main/chat_section/module.nim index 3978af77a9..e88c86c821 100644 --- a/src/app/modules/main/chat_section/module.nim +++ b/src/app/modules/main/chat_section/module.nim @@ -2,7 +2,7 @@ import NimQml, Tables, chronicles, json, sequtils, strutils, strformat, sugar import io_interface import ../io_interface as delegate_interface -import view, controller, item, sub_item, sub_model, base_item +import view, controller, item, sub_item, sub_model, base_item, active_item import model as chats_model import ../../shared_models/user_item as user_item import ../../shared_models/user_model as user_model @@ -310,6 +310,10 @@ method makeChatWithIdActive*(self: Module, chatId: string) = self.setActiveItemSubItem(item.BaseItem.id, subItemId) method activeItemSubItemSet*(self: Module, itemId: string, subItemId: string) = + if (itemId == "" and subItemId == ""): + self.view.activeItem().resetActiveItemData() + return + let item = self.view.chatsModel().getItemById(itemId) if(item.isNil): # Should never be here @@ -492,6 +496,7 @@ method onCommunityCategoryDeleted*(self: Module, cat: Category) = method setFirstChannelAsActive*(self: Module) = if(self.view.chatsModel().getCount() == 0): + self.setActiveItemSubItem("", "") return let item = self.view.chatsModel().getItemAtIndex(0) if(item.subItems.getCount() == 0): diff --git a/src/app/modules/main/chat_section/view.nim b/src/app/modules/main/chat_section/view.nim index 757ac21ad5..5c985eeb8e 100644 --- a/src/app/modules/main/chat_section/view.nim +++ b/src/app/modules/main/chat_section/view.nim @@ -120,6 +120,9 @@ QtObject: proc setActiveItem*(self: View, itemId: string, subItemId: string = "") {.slot.} = self.delegate.setActiveItemSubItem(itemId, subItemId) + proc activeItem*(self: View): ActiveItem = + result = self.activeItem + # Since we cannot return QVariant from the proc which has arguments, so cannot have proc like this: # prepareChatContentModuleForChatId(self: View, chatId: string): QVariant {.slot.} # we're using combinaiton of