Merge remote-tracking branch 'handydevcom/Fix_Scroll_To_Quoted_Message' into aurora_beta

This commit is contained in:
Nikolai Sinyov 2024-07-02 16:24:22 +03:00
commit 25ce179a31
3 changed files with 15 additions and 4 deletions

View file

@ -417,7 +417,7 @@ Page {
chatPage.messageIdToScrollTo = messageId chatPage.messageIdToScrollTo = messageId
} }
if (chatPage.messageIdToScrollTo && chatPage.messageIdToScrollTo != "") { if (chatPage.messageIdToScrollTo && chatPage.messageIdToScrollTo != "") {
var index = chatModel.getMessageIndex(chatPage.messageIdToScrollTo); var index = chatModel.getDisplayedMessageIndex(chatPage.messageIdToScrollTo);
if(index !== -1) { if(index !== -1) {
chatPage.messageIdToScrollTo = ""; chatPage.messageIdToScrollTo = "";
chatView.scrollToIndex(index); chatView.scrollToIndex(index);

View file

@ -472,13 +472,24 @@ QVariantMap ChatModel::getMessage(int index)
return QVariantMap(); return QVariantMap();
} }
int ChatModel::getMessageIndex(qlonglong messageId) int ChatModel::getDisplayedMessageIndex(qlonglong messageId)
{ {
if (messages.size() == 0) { if (messages.size() == 0) {
return -1; return -1;
} }
if (messageIndexMap.contains(messageId)) { 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; return -1;
} }

View file

@ -49,7 +49,7 @@ public:
Q_INVOKABLE int getLastReadMessageIndex(); Q_INVOKABLE int getLastReadMessageIndex();
Q_INVOKABLE void setSearchQuery(const QString newSearchQuery); Q_INVOKABLE void setSearchQuery(const QString newSearchQuery);
Q_INVOKABLE int getMessageIndex(qlonglong messageId); Q_INVOKABLE int getDisplayedMessageIndex(qlonglong messageId);
QVariantMap smallPhoto() const; QVariantMap smallPhoto() const;
qlonglong getChatId() const; qlonglong getChatId() const;