feature(@desktop/chat): implement search on sqlcipher (status-go side)
Current code adapted to handle future changes on message search (like searching message in multiple channels). Memory leak which was happening in qml assigning (copying) MessageItem to qml variable messageItem (where that qml variable messageItem was never deleted) is fixed. Fixes: #2912
This commit is contained in:
parent
b319eb988e
commit
de661459cb
|
@ -51,4 +51,4 @@ QtObject:
|
|||
## added to the view model and displayed to user. Method is convenient for
|
||||
## displaying already filtered messages (for example filtered response from DB)
|
||||
self.clear(false)
|
||||
self.add(messages)
|
||||
self.add(messages)
|
||||
|
|
|
@ -492,7 +492,7 @@ QtObject:
|
|||
for message in messageList.messages:
|
||||
if (message.id == messageId):
|
||||
return chatId
|
||||
|
||||
|
||||
proc getSearchResultMessageModel*(self: MessageView): QVariant {.slot.} =
|
||||
newQVariant(self.searchResultMessageModel)
|
||||
|
||||
|
@ -500,38 +500,10 @@ QtObject:
|
|||
QtProperty[QVariant] searchResultMessageModel:
|
||||
read = getSearchResultMessageModel
|
||||
|
||||
proc onSearchMessages*(self: MessageView, response: string) {.slot.} =
|
||||
let responseObj = response.parseJson
|
||||
if (responseObj.kind != JObject):
|
||||
error "search messages response is not an json object"
|
||||
return
|
||||
|
||||
let chatId = if(responseObj.contains("chatId")): responseObj{"chatId"}.getStr else : ""
|
||||
if (chatId.len == 0):
|
||||
error "search messages response either doesn't contain chatId or it is empty"
|
||||
return
|
||||
|
||||
let messagesObj = if(responseObj.contains("messages")): responseObj{"messages"} else: newJObject()
|
||||
if (messagesObj.kind != JObject):
|
||||
error "search messages response either doesn't contain messages object or it is empty"
|
||||
return
|
||||
|
||||
let (cursor, messages) = status_chat.parseChatMessagesResponse(messagesObj)
|
||||
|
||||
self.searchResultMessageModel.setFilteredMessages(messages)
|
||||
|
||||
proc searchMessages*(self: MessageView, searchTerm: string) {.slot.} =
|
||||
if (searchTerm.len == 0):
|
||||
self.searchResultMessageModel.clear(false)
|
||||
return
|
||||
|
||||
# chatId is used here only to support message search in currently selected channel
|
||||
# channelId is used here only to support message search in currently selected channel
|
||||
# later when we decide to apply message search over multiple channels MessageListProxyModel
|
||||
# will be updated to support setting list of sourcer messages.
|
||||
let chatId = self.channelView.activeChannel.id
|
||||
let slot = SlotArg(
|
||||
vptr: cast[ByteAddress](self.vptr),
|
||||
slot: "onSearchMessages"
|
||||
)
|
||||
|
||||
self.status.chat.asyncSearchMessages(slot, chatId, searchTerm, false)
|
||||
let channelId = self.channelView.activeChannel.id
|
||||
self.searchResultMessageModel.setSourceMessages(self.messageList[channelId].messages)
|
||||
self.searchResultMessageModel.setFilter(searchTerm, false)
|
||||
|
|
|
@ -218,6 +218,8 @@ Popup {
|
|||
prevMessageIndex: -1
|
||||
prevMsgTimestamp: ""
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue