From 9419c9acaf95887b61cd3c0ddd77df97f59a7455 Mon Sep 17 00:00:00 2001 From: Patryk Osmaczko Date: Tue, 4 Apr 2023 13:01:30 +0200 Subject: [PATCH] fix(chat): mark messages as read only if all messages have been viewed fixes: #10150 --- .../chat_content/messages/module.nim | 1 + ui/app/AppLayouts/Chat/stores/MessageStore.qml | 2 ++ .../AppLayouts/Chat/views/ChatMessagesView.qml | 18 +++++++++++++----- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/app/modules/main/chat_section/chat_content/messages/module.nim b/src/app/modules/main/chat_section/chat_content/messages/module.nim index 402bc8c5811..4a4165882b6 100644 --- a/src/app/modules/main/chat_section/chat_content/messages/module.nim +++ b/src/app/modules/main/chat_section/chat_content/messages/module.nim @@ -678,6 +678,7 @@ method resendChatMessage*(self: Module, messageId: string): string = return self.controller.resendChatMessage(messageId) method resetNewMessagesMarker*(self: Module) = + self.view.setFirstUnseenMessageLoaded(false) self.controller.getAsyncFirstUnseenMessageId() method removeNewMessagesMarker*(self: Module) = diff --git a/ui/app/AppLayouts/Chat/stores/MessageStore.qml b/ui/app/AppLayouts/Chat/stores/MessageStore.qml index e743a7a656a..b5f796b5926 100644 --- a/ui/app/AppLayouts/Chat/stores/MessageStore.qml +++ b/ui/app/AppLayouts/Chat/stores/MessageStore.qml @@ -11,6 +11,8 @@ QtObject { readonly property bool loadingHistoryMessagesInProgress: root.chatSectionModule? root.chatSectionModule.loadingHistoryMessagesInProgress : false readonly property int newMessagesCount: messagesModel ? messagesModel.newMessagesCount : 0 readonly property bool messageSearchOngoing: messageModule ? messageModule.messageSearchOngoing : false + readonly property bool initialMessagesLoaded: messageModule ? messageModule.initialMessagesLoaded : false + readonly property bool firstUnseenMessageLoaded: messageModule ? messageModule.firstUnseenMessageLoaded : false readonly property bool amIChatAdmin: messageModule ? messageModule.amIChatAdmin : false readonly property bool isPinMessageAllowedForMembers: messageModule ? messageModule.isPinMessageAllowedForMembers : false diff --git a/ui/app/AppLayouts/Chat/views/ChatMessagesView.qml b/ui/app/AppLayouts/Chat/views/ChatMessagesView.qml index 59849d4a89e..94e5fd676bd 100644 --- a/ui/app/AppLayouts/Chat/views/ChatMessagesView.qml +++ b/ui/app/AppLayouts/Chat/views/ChatMessagesView.qml @@ -59,7 +59,8 @@ Item { return } - if (chatDetails && chatDetails.active && chatDetails.hasUnreadMessages && !messageStore.messageSearchOngoing) { + if (chatDetails && chatDetails.active && chatDetails.hasUnreadMessages && + !messageStore.messageSearchOngoing && messageStore.firstUnseenMessageLoaded) { chatContentModule.markAllMessagesRead() } } @@ -85,14 +86,21 @@ Item { function onScrollToFirstUnreadMessage(messageIndex) { if (d.isMostRecentMessageInViewport) { - chatLogView.positionViewAtIndex(messageIndex, ListView.Center) - chatLogView.itemAtIndex(messageIndex).startMessageFoundAnimation() + onScrollToMessage(messageIndex) } } + } + + Connections { + target: root.messageStore function onMessageSearchOngoingChanged() { d.markAllMessagesReadIfMostRecentMessageIsInViewport() } + + function onFirstUnseenMessageLoadedChanged() { + d.markAllMessagesReadIfMostRecentMessageIsInViewport() + } } Connections { @@ -155,8 +163,8 @@ Item { Loader { id: loadingMessagesView - readonly property bool show: !messageStore.messageModule.firstUnseenMessageLoaded || - !messageStore.messageModule.initialMessagesLoaded + readonly property bool show: !messageStore.firstUnseenMessageLoaded || + !messageStore.initialMessagesLoaded active: show visible: show anchors.top: loadingMessagesIndicator.bottom