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
|
@ -500,38 +500,10 @@ QtObject:
|
||||||
QtProperty[QVariant] searchResultMessageModel:
|
QtProperty[QVariant] searchResultMessageModel:
|
||||||
read = getSearchResultMessageModel
|
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.} =
|
proc searchMessages*(self: MessageView, searchTerm: string) {.slot.} =
|
||||||
if (searchTerm.len == 0):
|
# channelId is used here only to support message search in currently selected channel
|
||||||
self.searchResultMessageModel.clear(false)
|
|
||||||
return
|
|
||||||
|
|
||||||
# chatId is used here only to support message search in currently selected channel
|
|
||||||
# later when we decide to apply message search over multiple channels MessageListProxyModel
|
# later when we decide to apply message search over multiple channels MessageListProxyModel
|
||||||
# will be updated to support setting list of sourcer messages.
|
# will be updated to support setting list of sourcer messages.
|
||||||
let chatId = self.channelView.activeChannel.id
|
let channelId = self.channelView.activeChannel.id
|
||||||
let slot = SlotArg(
|
self.searchResultMessageModel.setSourceMessages(self.messageList[channelId].messages)
|
||||||
vptr: cast[ByteAddress](self.vptr),
|
self.searchResultMessageModel.setFilter(searchTerm, false)
|
||||||
slot: "onSearchMessages"
|
|
||||||
)
|
|
||||||
|
|
||||||
self.status.chat.asyncSearchMessages(slot, chatId, searchTerm, false)
|
|
||||||
|
|
|
@ -218,6 +218,8 @@ Popup {
|
||||||
prevMessageIndex: -1
|
prevMessageIndex: -1
|
||||||
prevMsgTimestamp: ""
|
prevMsgTimestamp: ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue