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.
This commit is contained in:
Jonathan Rainville 2023-08-03 16:29:56 -04:00
parent ecf5efb94e
commit 20790a4c2a
2 changed files with 33 additions and 21 deletions

View File

@ -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/wallet_account/service as wallet_account_service
import ../../../app_service/service/token/service as token_service import ../../../app_service/service/token/service as token_service
import ../../../app_service/service/network/service as networks_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 from backend/collectibles_types import CollectibleOwner
import io_interface import io_interface
@ -441,17 +443,8 @@ proc setActiveSection*(self: Controller, sectionId: string, skipSavingInSettings
singletonInstance.localAccountSensitiveSettings.setActiveSection(sectionIdToSave) singletonInstance.localAccountSensitiveSettings.setActiveSection(sectionIdToSave)
self.delegate.activeSectionSet(self.activeSectionId) self.delegate.activeSectionSet(self.activeSectionId)
proc getNumOfNotificaitonsForChat*(self: Controller): tuple[unviewed:int, mentions:int] = proc getAllChats*(self: Controller): seq[ChatDto] =
result.unviewed = 0 result = self.chatService.getAllChats()
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 sectionUnreadMessagesAndMentionsCount*(self: Controller, communityId: string): proc sectionUnreadMessagesAndMentionsCount*(self: Controller, communityId: string):
tuple[unviewedMessagesCount: int, unviewedMentionsCount: int] = tuple[unviewedMessagesCount: int, unviewedMentionsCount: int] =
@ -525,3 +518,9 @@ proc slowdownArchivesImport*(self:Controller) =
proc speedupArchivesImport*(self:Controller) = proc speedupArchivesImport*(self:Controller) =
communityService.speedupArchivesImport() 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)

View File

@ -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/keycard/service as keycard_service
import ../../../app_service/service/shared_urls/service as urls_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/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/types
import ../../../app_service/common/social_links import ../../../app_service/common/social_links
@ -812,17 +813,29 @@ method getCommunitySectionModule*[T](self: Module[T], communityId: string): QVar
return self.channelGroupModules[communityId].getModuleAsVariant() return self.channelGroupModules[communityId].getModuleAsVariant()
method rebuildChatSearchModel*[T](self: Module[T]) = 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] = @[] var items: seq[chat_search_item.Item] = @[]
for cId in self.channelGroupModules.keys: for chat in self.controller.getAllChats():
items.add(transform(self.channelGroupModules[cId].chatsModel().items(), cId, var chatName = chat.name
self.view.model().getItemById(cId).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) self.view.chatSearchModel().setItems(items)