Merge pull request #5475 from SpiritCroc/readmarkerline

Fix some cases where the read marker line would not show up when it should
This commit is contained in:
ganfra 2022-04-11 11:12:13 +02:00 committed by GitHub
commit 53c7cec55d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 2 deletions

1
changelog.d/5475.bugfix Normal file
View File

@ -0,0 +1 @@
Fix some cases where the read marker line would not show up

View File

@ -36,7 +36,7 @@ sealed class UnreadState {
object Unknown : UnreadState()
object HasNoUnread : UnreadState()
data class ReadMarkerNotLoaded(val readMarkerId: String) : UnreadState()
data class HasUnread(val firstUnreadEventId: String) : UnreadState()
data class HasUnread(val firstUnreadEventId: String, val readMarkerId: String) : UnreadState()
}
data class JitsiState(

View File

@ -1111,9 +1111,13 @@ class TimelineViewModel @AssistedInject constructor(
computeUnreadState(timelineEvents, roomSummary)
}
// 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,
// as we might be loading new events to fill gaps in the timeline.
.distinctUntilChanged { previous, current ->
when {
previous is UnreadState.Unknown || previous is UnreadState.ReadMarkerNotLoaded -> false
previous is UnreadState.HasUnread && current is UnreadState.HasUnread &&
previous.readMarkerId == current.readMarkerId -> false
current is UnreadState.HasUnread || current is UnreadState.HasNoUnread -> true
else -> false
}
@ -1132,12 +1136,17 @@ class TimelineViewModel @AssistedInject constructor(
} else {
UnreadState.Unknown
}
// If the read marker is at the bottom-most event, this doesn't mean we read all, in case we just haven't loaded more events.
// Avoid incorrectly returning HasNoUnread in this case.
if (firstDisplayableEventIndex == 0 && timeline.hasMoreToLoad(Timeline.Direction.FORWARDS)) {
return UnreadState.Unknown
}
for (i in (firstDisplayableEventIndex - 1) downTo 0) {
val timelineEvent = events.getOrNull(i) ?: return UnreadState.Unknown
val eventId = timelineEvent.root.eventId ?: return UnreadState.Unknown
val isFromMe = timelineEvent.root.senderId == session.myUserId
if (!isFromMe) {
return UnreadState.HasUnread(eventId)
return UnreadState.HasUnread(eventId, readMarkerIdSnapshot)
}
}
return UnreadState.HasNoUnread