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);
pageStack.pushAttached(Qt.resolvedUrl("ChatInformationPage.qml"), { "chatInformation" : chatInformation, "privateChatUserInformation": chatPartnerInformation, "groupInformation": chatGroupInformation, "chatOnlineMemberCount": chatOnlineMemberCount});
chatPage.isInitialized = true;
if(doSendBotStartMessage) {
tdLibWrapper.sendBotStartMessage(chatInformation.id, chatInformation.id, sendBotStartMessageParameter, "")
@ -595,6 +594,9 @@ Page {
onMessagesIncrementalUpdate: {
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;
if (!chatPage.isInitialized) {
chatView.scrollToIndex(modelIndex);
}
chatViewCooldownTimer.restart();
}
onNotificationSettingsUpdated: {
@ -925,6 +927,12 @@ Page {
onTriggered: {
Debug.log("[ChatPage] Cooldown completed...");
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;
int listInboxPosition = this->calculateLastKnownMessageId();
int listOutboxPosition = this->calculateLastReadSentMessageId();
listInboxPosition = this->calculateScrollPosition(listInboxPosition);
if (this->inIncrementalUpdate) {
this->inIncrementalUpdate = false;
emit messagesIncrementalUpdate(listInboxPosition, listOutboxPosition);
@ -443,6 +444,7 @@ void ChatModel::handleMessagesReceived(const QVariantList &messages, int totalCo
this->inReload = false;
int listInboxPosition = this->calculateLastKnownMessageId();
int listOutboxPosition = this->calculateLastReadSentMessageId();
listInboxPosition = this->calculateScrollPosition(listInboxPosition);
if (this->inIncrementalUpdate) {
this->inIncrementalUpdate = false;
emit messagesIncrementalUpdate(listInboxPosition, listOutboxPosition);
@ -779,6 +781,16 @@ int ChatModel::calculateLastReadSentMessageId()
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()
{
// 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);
int calculateLastKnownMessageId();
int calculateLastReadSentMessageId();
int calculateScrollPosition(int listInboxPosition);
bool isMostRecentMessageLoaded();
private: