From 7ac4eba9e2943aa73a04ced753bfa15d5856d50b Mon Sep 17 00:00:00 2001 From: Alexandra Betouni <31625338+alexandraB99@users.noreply.github.com> Date: Fri, 24 Sep 2021 17:04:49 +0300 Subject: [PATCH] fix(desktop/chat) fixed position view at index Position view at chosen message when coming from either search or notifications was not working properly, especially when coming from another channel (eg from desktop to test). Added timer to delay positioning action until the messages model is almost fully loaded so that the view knows all indexes Depends on #3562 Closes #3592, #3683 --- ui/app/AppLayouts/Chat/ChatColumn.qml | 6 ++-- .../Chat/ChatColumn/ChatMessages.qml | 31 +++++++++++++------ 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/ui/app/AppLayouts/Chat/ChatColumn.qml b/ui/app/AppLayouts/Chat/ChatColumn.qml index 249f53a21b..29bdaffce0 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn.qml @@ -112,8 +112,8 @@ Item { applicationWindow.requestActivate() } - function positionAtMessage(messageId) { - stackLayoutChatMessages.children[stackLayoutChatMessages.currentIndex].message.scrollToMessage(messageId) + function positionAtMessage(messageId, isSearch = false) { + stackLayoutChatMessages.children[stackLayoutChatMessages.currentIndex].message.scrollToMessage(messageId, isSearch); } Timer { @@ -574,7 +574,7 @@ Item { target: chatsModel.messageView onSearchedMessageLoaded: { - positionAtMessage(messageId) + positionAtMessage(messageId, true); } onMessageNotificationPushed: function(messageId, communityId, chatId, msg, contentType, chatType, timestamp, identicon, username, hasMention, isAddedContact, channelName) { diff --git a/ui/app/AppLayouts/Chat/ChatColumn/ChatMessages.qml b/ui/app/AppLayouts/Chat/ChatColumn/ChatMessages.qml index 48855894a0..bc9f82115f 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/ChatMessages.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/ChatMessages.qml @@ -57,17 +57,30 @@ Item { } } - property var scrollToMessage: function (messageId) { - let item - for (let i = 0; i < messageListDelegate.count; i++) { - item = messageListDelegate.items.get(i) - if (item.model.messageId === messageId) { - chatLogView.positionViewAtIndex(i, ListView.Center); - if (appSettings.useCompactMode) { - chatLogView.itemAtIndex(i).startMessageFoundAnimation(); + property var scrollToMessage: function (messageId, isSearch = false) { + delayPositioningViewTimer.msgId = messageId; + delayPositioningViewTimer.isSearch = isSearch; + delayPositioningViewTimer.restart(); + } + + Timer { + id: delayPositioningViewTimer + interval: 1000 + property string msgId + property bool isSearch + onTriggered: { + let item + for (let i = 0; i < messages.rowCount(); i++) { + item = messageListDelegate.items.get(i); + if (item.model.messageId === msgId) { + chatLogView.positionViewAtIndex(i, ListView.Beginning); + if (appSettings.useCompactMode && isSearch) { + chatLogView.itemAtIndex(i).startMessageFoundAnimation(); + } } - return } + msgId = ""; + isSearch = false; } }