fix(@desktop/chat): endless search when user has no chats or communities

This commit is contained in:
Michał Cieślak 2022-07-19 17:15:09 +02:00 committed by Michał
parent 9aa1a1073e
commit d0125c86b5
2 changed files with 8 additions and 2 deletions

View File

@ -127,6 +127,10 @@ proc searchMessages*(self: Controller, searchTerm: string) =
for cId in communitiesIds: for cId in communitiesIds:
communities.add(cId) communities.add(cId)
if (communities.len == 0 and chats.len == 0):
self.delegate.onSearchMessagesDone(@[])
return
self.messageService.asyncSearchMessages(communities, chats, self.searchTerm, false) self.messageService.asyncSearchMessages(communities, chats, self.searchTerm, false)
proc getOneToOneChatNameAndImage*(self: Controller, chatId: string): proc getOneToOneChatNameAndImage*(self: Controller, chatId: string):

View File

@ -526,8 +526,8 @@ QtObject:
self.finishAsyncSearchMessagesWithError(chatId, "search messages response doesn't contain messages array") self.finishAsyncSearchMessagesWithError(chatId, "search messages response doesn't contain messages array")
return return
if (messagesArray.kind != JArray): if (messagesArray.kind notin {JArray, JNull}):
self.finishAsyncSearchMessagesWithError(chatId, "expected messages json array is not of JArray type") self.finishAsyncSearchMessagesWithError(chatId, "expected messages json array is neither of JArray nor JNull type")
return return
var messages = map(messagesArray.getElems(), proc(x: JsonNode): MessageDto = x.toMessageDto()) var messages = map(messagesArray.getElems(), proc(x: JsonNode): MessageDto = x.toMessageDto())
@ -542,6 +542,7 @@ QtObject:
return return
if (searchTerm.len == 0): if (searchTerm.len == 0):
error "the searched term cannot be empty", procName="asyncSearchMessages"
return return
let arg = AsyncSearchMessagesInChatTaskArg( let arg = AsyncSearchMessagesInChatTaskArg(
@ -564,6 +565,7 @@ QtObject:
return return
if (searchTerm.len == 0): if (searchTerm.len == 0):
error "the searched term cannot be empty", procName="asyncSearchMessages"
return return
let arg = AsyncSearchMessagesInChatsAndCommunitiesTaskArg( let arg = AsyncSearchMessagesInChatsAndCommunitiesTaskArg(