Skip to content

Commit

Permalink
fix(chat): mark messages as read only if all messages have been viewed
Browse files Browse the repository at this point in the history
fixes: #10150
  • Loading branch information
osmaczko authored and jrainville committed Apr 5, 2023
1 parent e950162 commit 9419c9a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand Down
2 changes: 2 additions & 0 deletions ui/app/AppLayouts/Chat/stores/MessageStore.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 13 additions & 5 deletions ui/app/AppLayouts/Chat/views/ChatMessagesView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9419c9a

Please sign in to comment.