Chat page: Adjust initial scroll position, honoring #243

This commit is contained in:
Sebastian Wolf 2021-02-02 22:05:24 +01:00
parent c6f0a41559
commit 3176c3dc8c
No known key found for this signature in database
GPG key ID: CEA9522B5F38A90A
3 changed files with 22 additions and 1 deletions

View file

@ -443,7 +443,6 @@ Page {
chatModel.initialize(chatInformation); chatModel.initialize(chatInformation);
pageStack.pushAttached(Qt.resolvedUrl("ChatInformationPage.qml"), { "chatInformation" : chatInformation, "privateChatUserInformation": chatPartnerInformation, "groupInformation": chatGroupInformation, "chatOnlineMemberCount": chatOnlineMemberCount}); pageStack.pushAttached(Qt.resolvedUrl("ChatInformationPage.qml"), { "chatInformation" : chatInformation, "privateChatUserInformation": chatPartnerInformation, "groupInformation": chatGroupInformation, "chatOnlineMemberCount": chatOnlineMemberCount});
chatPage.isInitialized = true;
if(doSendBotStartMessage) { if(doSendBotStartMessage) {
tdLibWrapper.sendBotStartMessage(chatInformation.id, chatInformation.id, sendBotStartMessageParameter, "") tdLibWrapper.sendBotStartMessage(chatInformation.id, chatInformation.id, sendBotStartMessageParameter, "")
@ -595,6 +594,9 @@ Page {
onMessagesIncrementalUpdate: { onMessagesIncrementalUpdate: {
Debug.log("Incremental update received. View now has ", chatView.count, " messages, view is on index ", modelIndex, ", own messages were read before index ", lastReadSentIndex); Debug.log("Incremental update received. View now has ", chatView.count, " messages, view is on index ", modelIndex, ", own messages were read before index ", lastReadSentIndex);
chatView.lastReadSentIndex = lastReadSentIndex; chatView.lastReadSentIndex = lastReadSentIndex;
if (!chatPage.isInitialized) {
chatView.scrollToIndex(modelIndex);
}
chatViewCooldownTimer.restart(); chatViewCooldownTimer.restart();
} }
onNotificationSettingsUpdated: { onNotificationSettingsUpdated: {
@ -925,6 +927,12 @@ Page {
onTriggered: { onTriggered: {
Debug.log("[ChatPage] Cooldown completed..."); Debug.log("[ChatPage] Cooldown completed...");
chatView.inCooldown = false; chatView.inCooldown = false;
if (!chatPage.isInitialized) {
Debug.log("Page is initialized!");
chatPage.isInitialized = true;
chatView.handleScrollPositionChanged();
}
} }
} }

View file

@ -403,6 +403,7 @@ void ChatModel::handleMessagesReceived(const QVariantList &messages, int totalCo
this->inReload = false; this->inReload = false;
int listInboxPosition = this->calculateLastKnownMessageId(); int listInboxPosition = this->calculateLastKnownMessageId();
int listOutboxPosition = this->calculateLastReadSentMessageId(); int listOutboxPosition = this->calculateLastReadSentMessageId();
listInboxPosition = this->calculateScrollPosition(listInboxPosition);
if (this->inIncrementalUpdate) { if (this->inIncrementalUpdate) {
this->inIncrementalUpdate = false; this->inIncrementalUpdate = false;
emit messagesIncrementalUpdate(listInboxPosition, listOutboxPosition); emit messagesIncrementalUpdate(listInboxPosition, listOutboxPosition);
@ -443,6 +444,7 @@ void ChatModel::handleMessagesReceived(const QVariantList &messages, int totalCo
this->inReload = false; this->inReload = false;
int listInboxPosition = this->calculateLastKnownMessageId(); int listInboxPosition = this->calculateLastKnownMessageId();
int listOutboxPosition = this->calculateLastReadSentMessageId(); int listOutboxPosition = this->calculateLastReadSentMessageId();
listInboxPosition = this->calculateScrollPosition(listInboxPosition);
if (this->inIncrementalUpdate) { if (this->inIncrementalUpdate) {
this->inIncrementalUpdate = false; this->inIncrementalUpdate = false;
emit messagesIncrementalUpdate(listInboxPosition, listOutboxPosition); emit messagesIncrementalUpdate(listInboxPosition, listOutboxPosition);
@ -779,6 +781,16 @@ int ChatModel::calculateLastReadSentMessageId()
return listOutboxPosition; return listOutboxPosition;
} }
int ChatModel::calculateScrollPosition(int listInboxPosition)
{
LOG("Calculating new scroll position, current:" << listInboxPosition << ", list size:" << this->messages.size());
if ((this->messages.size() - 1) > listInboxPosition) {
return listInboxPosition + 1;
} else {
return listInboxPosition;
}
}
bool ChatModel::isMostRecentMessageLoaded() bool ChatModel::isMostRecentMessageLoaded()
{ {
// Need to check if we can actually add messages (only possible if the previously latest messages are loaded) // Need to check if we can actually add messages (only possible if the previously latest messages are loaded)

View file

@ -85,6 +85,7 @@ private:
QVariantMap enhanceMessage(const QVariantMap &message); QVariantMap enhanceMessage(const QVariantMap &message);
int calculateLastKnownMessageId(); int calculateLastKnownMessageId();
int calculateLastReadSentMessageId(); int calculateLastReadSentMessageId();
int calculateScrollPosition(int listInboxPosition);
bool isMostRecentMessageLoaded(); bool isMostRecentMessageLoaded();
private: private: