From 978ee5a3346c7a7299d28dac967589a46ed6cf40 Mon Sep 17 00:00:00 2001 From: Sebastian Wolf Date: Tue, 2 Feb 2021 23:19:02 +0100 Subject: [PATCH] Handle last read sent message better, might address #301 --- qml/pages/ChatPage.qml | 11 ++++++++--- src/chatmodel.cpp | 7 ++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/qml/pages/ChatPage.qml b/qml/pages/ChatPage.qml index 54ba6e9..2f6f178 100644 --- a/qml/pages/ChatPage.qml +++ b/qml/pages/ChatPage.qml @@ -145,7 +145,7 @@ Page { function initializePage() { Debug.log("[ChatPage] Initializing chat page..."); chatView.currentIndex = -1; - chatView.lastReadSentIndex = 0; + chatView.lastReadSentIndex = -1; var chatType = chatInformation.type['@type']; isPrivateChat = chatType === "chatTypePrivate"; isSecretChat = chatType === "chatTypeSecret"; @@ -182,6 +182,7 @@ Page { } function getMessageStatusText(message, listItemIndex, lastReadSentIndex, useElapsed) { + Debug.log("Last read sent index: " + lastReadSentIndex); var messageStatusSuffix = ""; if(!message) { return ""; @@ -597,6 +598,10 @@ Page { if (!chatPage.isInitialized) { chatView.scrollToIndex(modelIndex); } + if (chatView.height > chatView.contentHeight) { + Debug.log("[ChatPage] Chat content quite small..."); + viewMessageTimer.queueViewMessage(chatView.count - 1); + } chatViewCooldownTimer.restart(); } onNotificationSettingsUpdated: { @@ -800,7 +805,7 @@ Page { Rectangle { id: chatSecretBackground - color: Theme.highlightBackgroundColor + color: Theme.rgba(Theme.overlayBackgroundColor, Theme.opacityFaint) width: chatPage.isPortrait ? Theme.fontSizeLarge : Theme.fontSizeMedium height: width anchors.left: parent.left @@ -960,7 +965,7 @@ Page { clip: true highlightMoveDuration: 0 highlightResizeDuration: 0 - property int lastReadSentIndex: 0 + property int lastReadSentIndex: -1 property bool inCooldown: false property bool manuallyScrolledToBottom property QtObject precalculatedValues: QtObject { diff --git a/src/chatmodel.cpp b/src/chatmodel.cpp index 7a38a31..8efcd26 100644 --- a/src/chatmodel.cpp +++ b/src/chatmodel.cpp @@ -757,12 +757,12 @@ int ChatModel::calculateLastKnownMessageId() LOG("contains last read ID?" << messageIndexMap.contains(lastKnownMessageId)); LOG("contains last own ID?" << messageIndexMap.contains(lastOwnMessageId)); int listInboxPosition = messageIndexMap.value(lastKnownMessageId, messages.size() - 1); - int listOwnPosition = messageIndexMap.value(lastOwnMessageId, 0); + int listOwnPosition = messageIndexMap.value(lastOwnMessageId, -1); if (listInboxPosition > this->messages.size() - 1 ) { listInboxPosition = this->messages.size() - 1; } if (listOwnPosition > this->messages.size() - 1 ) { - listOwnPosition = 0; + listOwnPosition = -1; } LOG("Last known message is at position" << listInboxPosition); LOG("Last own message is at position" << listOwnPosition); @@ -776,8 +776,9 @@ int ChatModel::calculateLastReadSentMessageId() LOG("lastReadSentMessageId" << lastReadSentMessageId); LOG("size messageIndexMap" << messageIndexMap.size()); LOG("contains ID?" << messageIndexMap.contains(lastReadSentMessageId)); - const int listOutboxPosition = messageIndexMap.value(lastReadSentMessageId, messages.size() - 1); + const int listOutboxPosition = messageIndexMap.value(lastReadSentMessageId, -1); LOG("Last read sent message is at position" << listOutboxPosition); + emit lastReadSentMessageUpdated(listOutboxPosition); return listOutboxPosition; }