Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix scroll to quoted message #568

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
15 changes: 13 additions & 2 deletions src/chatmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,13 +472,24 @@ 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);
}
}
if(realIndex < -1)
return -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