From 78f3bbd4ee8c86fd61064b67c0dbc26b6c12b134 Mon Sep 17 00:00:00 2001 From: Mikhail Barashkov Date: Tue, 14 May 2024 18:00:32 +0300 Subject: [PATCH] Fix scroll to quoted message #566 --- qml/pages/ChatPage.qml | 2 +- src/chatmodel.cpp | 14 ++++++++++++-- src/chatmodel.h | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/qml/pages/ChatPage.qml b/qml/pages/ChatPage.qml index 55278fee..8cafe57a 100644 --- a/qml/pages/ChatPage.qml +++ b/qml/pages/ChatPage.qml @@ -417,7 +417,7 @@ Page { chatPage.messageIdToScrollTo = messageId } if (chatPage.messageIdToScrollTo && chatPage.messageIdToScrollTo != "") { - var index = chatModel.getMessageIndex(chatPage.messageIdToScrollTo); + var index = chatModel.getDisplayedMessageIndex(chatPage.messageIdToScrollTo); if(index !== -1) { chatPage.messageIdToScrollTo = ""; chatView.scrollToIndex(index); diff --git a/src/chatmodel.cpp b/src/chatmodel.cpp index 7dad2310..c856daf4 100644 --- a/src/chatmodel.cpp +++ b/src/chatmodel.cpp @@ -472,13 +472,23 @@ QVariantMap ChatModel::getMessage(int index) return QVariantMap(); } -int ChatModel::getMessageIndex(qlonglong messageId) +int ChatModel::getDisplayedMessageIndex(qlonglong messageId) { if (messages.size() == 0) { return -1; } if (messageIndexMap.contains(messageId)) { - return messageIndexMap.value(messageId); + int rawIndex = messageIndexMap.value(messageId); + // We need to substract number of albums which are shown before this item, because that's the index it's displayed on screen at. + int realIndex = rawIndex; + for(int i = 0; i < rawIndex; i++) { + MessageData *message = messages.at(i); + if(message->albumMessageIds.count() > 0) { + realIndex -= (message->albumMessageIds.count() - 1); + } + } + + return realIndex; } return -1; } diff --git a/src/chatmodel.h b/src/chatmodel.h index e2e8bbc3..07753b75 100644 --- a/src/chatmodel.h +++ b/src/chatmodel.h @@ -49,7 +49,7 @@ class ChatModel : public QAbstractListModel Q_INVOKABLE int getLastReadMessageIndex(); Q_INVOKABLE void setSearchQuery(const QString newSearchQuery); - Q_INVOKABLE int getMessageIndex(qlonglong messageId); + Q_INVOKABLE int getDisplayedMessageIndex(qlonglong messageId); QVariantMap smallPhoto() const; qlonglong getChatId() const;