From 20790a4c2a22a07c1c43e19e80b6f8873f3c8408 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Thu, 3 Aug 2023 16:29:56 -0400 Subject: [PATCH] fix(chatSearch): fix chat search to include all and only chats Fixes #10770 There were two issues, the first one was that categories were included in the search model because the categories are now part of the chat_model. Also, since it used the chat_model, some chats were not part of the search model at start, because they weren't loaded yet. I fixed by using the chats from the service directly instead. --- src/app/modules/main/controller.nim | 21 +++++++++--------- src/app/modules/main/module.nim | 33 ++++++++++++++++++++--------- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/src/app/modules/main/controller.nim b/src/app/modules/main/controller.nim index 9c9f877077..8736527648 100644 --- a/src/app/modules/main/controller.nim +++ b/src/app/modules/main/controller.nim @@ -21,6 +21,8 @@ import ../../../app_service/service/community_tokens/service as community_tokens import ../../../app_service/service/wallet_account/service as wallet_account_service import ../../../app_service/service/token/service as token_service import ../../../app_service/service/network/service as networks_service +import ../../../app_service/service/visual_identity/service as procs_from_visual_identity_service + from backend/collectibles_types import CollectibleOwner import io_interface @@ -441,17 +443,8 @@ proc setActiveSection*(self: Controller, sectionId: string, skipSavingInSettings singletonInstance.localAccountSensitiveSettings.setActiveSection(sectionIdToSave) self.delegate.activeSectionSet(self.activeSectionId) -proc getNumOfNotificaitonsForChat*(self: Controller): tuple[unviewed:int, mentions:int] = - result.unviewed = 0 - result.mentions = 0 - let chats = self.chatService.getAllChats() - for chat in chats: - if(chat.chatType == ChatType.CommunityChat): - continue - - if not chat.muted: - result.unviewed += chat.unviewedMessagesCount - result.mentions += chat.unviewedMentionsCount +proc getAllChats*(self: Controller): seq[ChatDto] = + result = self.chatService.getAllChats() proc sectionUnreadMessagesAndMentionsCount*(self: Controller, communityId: string): tuple[unviewedMessagesCount: int, unviewedMentionsCount: int] = @@ -525,3 +518,9 @@ proc slowdownArchivesImport*(self:Controller) = proc speedupArchivesImport*(self:Controller) = communityService.speedupArchivesImport() + +proc getColorHash*(self: Controller, pubkey: string): ColorHashDto = + procs_from_visual_identity_service.colorHashOf(pubkey) + +proc getColorId*(self: Controller, pubkey: string): int = + procs_from_visual_identity_service.colorIdOf(pubkey) diff --git a/src/app/modules/main/module.nim b/src/app/modules/main/module.nim index 86b54805e5..227422aa32 100644 --- a/src/app/modules/main/module.nim +++ b/src/app/modules/main/module.nim @@ -63,6 +63,7 @@ import ../../../app_service/service/general/service as general_service import ../../../app_service/service/keycard/service as keycard_service import ../../../app_service/service/shared_urls/service as urls_service import ../../../app_service/service/network_connection/service as network_connection_service +import ../../../app_service/service/visual_identity/service as procs_from_visual_identity_service import ../../../app_service/common/types import ../../../app_service/common/social_links @@ -812,17 +813,29 @@ method getCommunitySectionModule*[T](self: Module[T], communityId: string): QVar return self.channelGroupModules[communityId].getModuleAsVariant() method rebuildChatSearchModel*[T](self: Module[T]) = - let transformItem = proc(item: chat_item.Item, sectionId, sectionName: string): chat_search_item.Item = - result = chat_search_item.initItem(item.id(), item.name(), item.color(), item.colorId(), item.icon(), item.colorHash().toJson(), sectionId, sectionName) - - let transform = proc(items: seq[chat_item.Item], sectionId, sectionName: string): seq[chat_search_item.Item] = - for item in items: - result.add(transformItem(item, sectionId, sectionName)) - var items: seq[chat_search_item.Item] = @[] - for cId in self.channelGroupModules.keys: - items.add(transform(self.channelGroupModules[cId].chatsModel().items(), cId, - self.view.model().getItemById(cId).name())) + for chat in self.controller.getAllChats(): + var chatName = chat.name + var chatImage = chat.icon + var colorHash: ColorHashDto = @[] + var colorId: int = 0 + if chat.chatType == ChatType.OneToOne: + let contactDetails = self.controller.getContactDetails(chat.id) + chatName = contactDetails.defaultDisplayName + chatImage = contactDetails.icon + if not contactDetails.dto.ensVerified: + colorHash = self.controller.getColorHash(chat.id) + colorId = self.controller.getColorId(chat.id) + items.add(chat_search_item.initItem( + chat.id, + chatName, + chat.color, + colorId, + chatImage, + colorHash.toJson(), + chat.communityId, + self.view.model().getItemById(chat.communityId).name(), + )) self.view.chatSearchModel().setItems(items)