fix(search): add community to channelGroups and fix channel search

Fixes #7017
This commit is contained in:
Jonathan Rainville 2022-08-15 14:21:11 -04:00
parent cfef7dc443
commit 8624b3ae9a
2 changed files with 15 additions and 3 deletions

View File

@ -157,7 +157,7 @@ method onSearchMessagesDone*(self: Module, messages: seq[MessageDto]) =
for channelGroup in channelGroups:
let isCommunity = channelGroup.channelGroupType == ChannelGroupType.Community
if(self.controller.searchLocation().len == 0 and
channelGroup.name.toLower.startsWith(searchTerm)):
channelGroup.name.toLower.contains(searchTerm)):
let item = result_item.initItem(
channelGroup.id,
content="",
@ -180,7 +180,7 @@ method onSearchMessagesDone*(self: Module, messages: seq[MessageDto]) =
items.add(item)
# Add channels
if(self.controller.searchSubLocation().len == 0 and self.controller.searchLocation().len == 0 or
if((self.controller.searchSubLocation().len == 0 and self.controller.searchLocation().len == 0) or
self.controller.searchLocation() == channelGroup.id):
for chatDto in channelGroup.chats:
var chatName = chatDto.name
@ -197,7 +197,7 @@ method onSearchMessagesDone*(self: Module, messages: seq[MessageDto]) =
if(chatName.startsWith("@")):
rawChatName = chatName[1 ..^ 1]
if(rawChatName.toLower.startsWith(searchTerm)):
if(rawChatName.toLower.contains(searchTerm)):
let item = result_item.initItem(
chatDto.id,
content="",

View File

@ -3,6 +3,7 @@ import NimQml, Tables, json, sequtils, strformat, chronicles, os, std/algorithm,
import ./dto/chat as chat_dto
import ../message/dto/message as message_dto
import ../activity_center/dto/notification as notification_dto
import ../community/dto/community as community_dto
import ../contacts/service as contact_service
import ../../../backend/chat as status_chat
import ../../../backend/group_chat as status_group_chat
@ -115,6 +116,7 @@ QtObject:
# Forward declarations
proc updateOrAddChat*(self: Service, chat: ChatDto)
proc updateOrAddChannelGroup*(self: Service, channelGroup: ChannelGroupDto)
proc doConnect(self: Service) =
self.events.on(SignalType.Message.event) do(e: Args):
@ -132,6 +134,11 @@ QtObject:
if (receivedData.clearedHistories.len > 0):
for clearedHistoryDto in receivedData.clearedHistories:
self.events.emit(SIGNAL_CHAT_HISTORY_CLEARED, ChatArgs(chatId: clearedHistoryDto.chatId))
# Handling community updates
if (receivedData.communities.len > 0):
for community in receivedData.communities:
self.updateOrAddChannelGroup(community.toChannelGroupDto())
proc sortPersonnalChatAsFirst[T, D](x, y: (T, D)): int =
if (x[1].channelGroupType == Personal): return -1
@ -196,6 +203,11 @@ QtObject:
else:
self.channelGroups[channelGroupId].chats[index] = chat
proc updateOrAddChannelGroup*(self: Service, channelGroup: ChannelGroupDto) =
self.channelGroups[channelGroup.id] = channelGroup
for chat in channelGroup.chats:
self.updateOrAddChat(chat)
proc parseChatResponse*(self: Service, response: RpcResponse[JsonNode]): (seq[ChatDto], seq[MessageDto]) =
var chats: seq[ChatDto] = @[]
var messages: seq[MessageDto] = @[]