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

Feature added. Firstly we check if the searched message is already displayed and if yes simply jump
to it, if not then we are loading new 20 messages in the past using cursor and check if the
searched message's id is among those received messages. We do that in a loop till we find the
message we are searching for.

Fixes: #3005
This commit is contained in:
Sale Djenic 2021-07-26 10:08:03 +02:00 committed by Iuri Matias
parent e62465d86f
commit 5d8b02e057
4 changed files with 63 additions and 8 deletions

View File

@ -32,6 +32,8 @@ QtObject:
unreadMessageCnt: int unreadMessageCnt: int
unreadDirectMessagesAndMentionsCount: int unreadDirectMessagesAndMentionsCount: int
channelOpenTime*: Table[string, int64] channelOpenTime*: Table[string, int64]
searchedMessageId: string
loadingHistoryMessages: bool
proc setup(self: MessageView) = self.QAbstractListModel.setup proc setup(self: MessageView) = self.QAbstractListModel.setup
proc delete*(self: MessageView) = proc delete*(self: MessageView) =
@ -57,9 +59,32 @@ QtObject:
result.unreadMessageCnt = 0 result.unreadMessageCnt = 0
result.searchResultMessageModel = newMessageListProxyModel(status) result.searchResultMessageModel = newMessageListProxyModel(status)
result.unreadDirectMessagesAndMentionsCount = 0 result.unreadDirectMessagesAndMentionsCount = 0
result.loadingHistoryMessages = false
result.setup result.setup
# proc getMessageListIndexById(self: MessageView, id: string): int #################################################
# Forward declaration section
#################################################
proc checkIfSearchedMessageIsLoaded(self: MessageView)
#################################################
# Properties
#################################################
proc loadingHistoryMessagesChanged*(self: MessageView) {.signal.}
proc setLoadingHistoryMessages*(self: MessageView, value: bool) =
if (value == self.loadingHistoryMessages):
return
self.loadingHistoryMessages = value
self.loadingHistoryMessagesChanged()
proc getLoadingHistoryMessages*(self: MessageView): QVariant {.slot.} =
return newQVariant(self.loadingHistoryMessages)
QtProperty[QVariant] loadingHistoryMessages:
read = getLoadingHistoryMessages
notify = loadingHistoryMessagesChanged
proc replaceMentionsWithPubKeys(self: MessageView, mentions: seq[string], contacts: seq[Profile], message: string, predicate: proc (contact: Profile): string): string = proc replaceMentionsWithPubKeys(self: MessageView, mentions: seq[string], contacts: seq[Profile], message: string, predicate: proc (contact: Profile): string): string =
var updatedMessage = message var updatedMessage = message
@ -263,11 +288,16 @@ QtObject:
proc loadMoreMessages*(self: MessageView) {.slot.} = proc loadMoreMessages*(self: MessageView) {.slot.} =
let channelId = self.channelView.activeChannel.id let channelId = self.channelView.activeChannel.id
self.setLoadingHistoryMessages(true)
self.status.chat.loadMoreMessagesForChannel(channelId) self.status.chat.loadMoreMessagesForChannel(channelId)
proc onMessagesLoaded*(self: MessageView, messages: var seq[Message]) = proc onMessagesLoaded*(self: MessageView, messages: var seq[Message]) =
self.pushMessages(messages) self.pushMessages(messages)
self.messagesLoaded(); self.messagesLoaded();
self.setLoadingHistoryMessages(false)
self.checkIfSearchedMessageIsLoaded()
proc loadingMessagesChanged*(self: MessageView, value: bool) {.signal.} proc loadingMessagesChanged*(self: MessageView, value: bool) {.signal.}
@ -436,3 +466,24 @@ QtObject:
proc onSearchMessagesLoaded*(self: MessageView, messages: seq[Message]) = proc onSearchMessagesLoaded*(self: MessageView, messages: seq[Message]) =
self.searchResultMessageModel.setFilteredMessages(messages) self.searchResultMessageModel.setFilteredMessages(messages)
proc isMessageDisplayed*(self: MessageView, messageId: string): bool {.slot.} =
let chatId = self.channelView.activeChannel.id
var message = self.messageList[chatId].getMessageById(messageId)
return message.id != ""
proc loadMessagesTillMessageWithIdIsLoaded*(self: MessageView, messageId: string) {.slot.} =
self.searchedMessageId = messageId
self.loadMoreMessages()
proc searchedMessageLoaded*(self: MessageView, messageId: string) {.signal.}
proc checkIfSearchedMessageIsLoaded(self: MessageView) =
if (self.searchedMessageId.len == 0):
return
if (self.isMessageDisplayed(self.searchedMessageId)):
self.searchedMessageLoaded(self.searchedMessageId)
self.searchedMessageId = ""
else:
self.loadMoreMessages()

View File

@ -585,6 +585,10 @@ Item {
Connections { Connections {
target: chatsModel.messageView target: chatsModel.messageView
onSearchedMessageLoaded: {
positionAtMessage(messageId)
}
onMessageNotificationPushed: function(chatId, msg, contentType, chatType, timestamp, identicon, username, hasMention, isAddedContact, channelName) { onMessageNotificationPushed: function(chatId, msg, contentType, chatType, timestamp, identicon, username, hasMention, isAddedContact, channelName) {
if (appSettings.notificationSetting == Constants.notifyAllMessages || if (appSettings.notificationSetting == Constants.notifyAllMessages ||
(appSettings.notificationSetting == Constants.notifyJustMentions && hasMention)) { (appSettings.notificationSetting == Constants.notifyJustMentions && hasMention)) {

View File

@ -23,7 +23,6 @@ Item {
property var messageContextMenuInst property var messageContextMenuInst
property var messageList: MessagesData {} property var messageList: MessagesData {}
property bool loadingMessages: false
property real scrollY: chatLogView.visibleArea.yPosition * chatLogView.contentHeight property real scrollY: chatLogView.visibleArea.yPosition * chatLogView.contentHeight
property int newMessages: 0 property int newMessages: 0
property int countOnStartUp: 0 property int countOnStartUp: 0
@ -180,9 +179,6 @@ Item {
Connections { Connections {
target: chatsModel.messageView target: chatsModel.messageView
onMessagesLoaded: {
loadingMessages = false;
}
onSendingMessage: { onSendingMessage: {
chatLogView.scrollToBottom(true) chatLogView.scrollToBottom(true)
@ -227,8 +223,9 @@ Item {
} }
property var loadMsgs : Backpressure.oneInTime(chatLogView, 500, function() { property var loadMsgs : Backpressure.oneInTime(chatLogView, 500, function() {
if(loadingMessages) return; if(chatsModel.messageView.loadingHistoryMessages)
loadingMessages = true; return
chatsModel.messageView.loadMoreMessages(); chatsModel.messageView.loadMoreMessages();
}); });

View File

@ -212,7 +212,10 @@ Popup {
popup.close() popup.close()
positionAtMessage(model.messageId) if(chatsModel.messageView.isMessageDisplayed(model.messageId))
positionAtMessage(model.messageId)
else
chatsModel.messageView.loadMessagesTillMessageWithIdIsLoaded(model.messageId)
} }
prevMessageIndex: -1 prevMessageIndex: -1