feature(@desktop/chat): support jumping to search result message that is not currently loaded in memory

A crash leaving chat is fixed.

The issue was very hidden cause everything looks ok, at first glance, but not, the thing is that
"messages" exposed to qml were deleted from ChatsView and signals beginRemoveRows and
endRemoveRows were emitted for CatsView abstract list model instead for MessageView abstract list
model. That results in an app crash in some moments (not always reproducible, but often).

Fixes: #3005
This commit is contained in:
Sale Djenic 2021-07-29 16:39:04 +02:00 committed by Iuri Matias
parent 83d6817f70
commit 5e569865e4
2 changed files with 14 additions and 6 deletions

View File

@ -300,12 +300,7 @@ QtObject:
proc removeChat*(self: ChatsView, chatId: string) =
discard self.channelView.chats.removeChatItemFromList(chatId)
if (self.messageView.messageList.hasKey(chatId)):
let index = self.messageView.getMessageListIndexById(chatId)
self.beginRemoveRows(newQModelIndex(), index, index)
self.messageView.messageList[chatId].delete
self.messageView.messageList.del(chatId)
self.endRemoveRows()
self.messageView.removeChat(chatId)
proc toggleReaction*(self: ChatsView, messageId: string, emojiId: int) {.slot.} =
if self.channelView.activeChannel.id == status_utils.getTimelineChatId():

View File

@ -431,6 +431,19 @@ QtObject:
if (message.id == messageId):
return chatId
proc removeChat*(self: MessageView, chatId: string) =
if (not self.messageList.hasKey(chatId)):
return
let index = self.getMessageListIndexById(chatId)
if (index < 0 or index >= self.messageList.len):
return
self.beginRemoveRows(newQModelIndex(), index, index)
self.messageList[chatId].delete
self.messageList.del(chatId)
self.endRemoveRows()
proc getSearchResultMessageModel*(self: MessageView): QVariant {.slot.} =
newQVariant(self.searchResultMessageModel)