Update read marker when we go back in live (#8306)

This commit is contained in:
Yoan Pintas 2023-04-12 09:18:02 +02:00 committed by GitHub
parent 7f42eb3fb6
commit 99aa9493d6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1325,13 +1325,17 @@ class TimelineViewModel @AssistedInject constructor(
computeUnreadState(timelineEvents, roomSummary) computeUnreadState(timelineEvents, roomSummary)
} }
// We don't want live update of unread so we skip when we already had a HasUnread or HasNoUnread // We don't want live update of unread so we skip when we already had a HasUnread or HasNoUnread
// However, we want to update an existing HasUnread, if the readMarkerId hasn't changed, // However, we want to update an existing HasUnread, if the readMarkerId hasn't changed or when we go back in live,
// as we might be loading new events to fill gaps in the timeline. // as we might be loading new events to fill gaps in the timeline.
.distinctUntilChanged { previous, current -> .distinctUntilChanged { previous, current ->
when { when {
previous is UnreadState.Unknown || previous is UnreadState.ReadMarkerNotLoaded -> false previous is UnreadState.Unknown || previous is UnreadState.ReadMarkerNotLoaded -> false
previous is UnreadState.HasUnread && current is UnreadState.HasUnread && previous is UnreadState.HasUnread && current is UnreadState.HasUnread &&
previous.readMarkerId == current.readMarkerId -> false previous.readMarkerId == current.readMarkerId -> false
previous is UnreadState.HasUnread && (
current is UnreadState.HasUnread && previous.firstUnreadEventId != current.firstUnreadEventId ||
current is UnreadState.HasNoUnread
) && timeline?.isLive.orFalse() -> false
current is UnreadState.HasUnread || current is UnreadState.HasNoUnread -> true current is UnreadState.HasUnread || current is UnreadState.HasNoUnread -> true
else -> false else -> false
} }