Skip to content

Commit

Permalink
Fix scroll to quoted message Wunderfitz#566
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Barashkov committed May 14, 2024
1 parent 6cae9b4 commit 4b471e1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion qml/pages/ChatPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 12 additions & 2 deletions src/chatmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/chatmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 4b471e1

Please sign in to comment.