Skip to content

Commit da5a3ea

Browse files
authored
Jump to unread marker instead of first unread message (#8305)
1 parent 29777f5 commit da5a3ea

File tree

5 files changed

+9
-6
lines changed

5 files changed

+9
-6
lines changed

changelog.d/8268.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The read marker is stuck in the past

vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailAction.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ sealed class RoomDetailAction : VectorViewModelAction {
3939
data class UndoReaction(val targetEventId: String, val reaction: String, val reason: String? = "") : RoomDetailAction()
4040
data class RedactAction(val targetEventId: String, val reason: String? = "") : RoomDetailAction()
4141
data class UpdateQuickReactAction(val targetEventId: String, val selectedReaction: String, val add: Boolean) : RoomDetailAction()
42-
data class NavigateToEvent(val eventId: String, val highlight: Boolean) : RoomDetailAction()
42+
data class NavigateToEvent(val eventId: String, val highlight: Boolean, val isFirstUnreadEvent: Boolean = false) : RoomDetailAction()
4343
object MarkAllAsRead : RoomDetailAction()
4444
data class DownloadOrOpen(val eventId: String, val senderId: String?, val messageFileContent: MessageWithAttachmentContent) : RoomDetailAction()
4545
object JoinAndOpenReplacementRoom : RoomDetailAction()

vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewEvents.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ sealed class RoomDetailViewEvents : VectorViewEvents {
4141

4242
data class OpenRoom(val roomId: String, val closeCurrentRoom: Boolean = false) : RoomDetailViewEvents()
4343

44-
data class NavigateToEvent(val eventId: String) : RoomDetailViewEvents()
44+
data class NavigateToEvent(val eventId: String, val isFirstUnreadEvent: Boolean) : RoomDetailViewEvents()
4545
data class JoinJitsiConference(val widget: Widget, val withVideo: Boolean) : RoomDetailViewEvents()
4646
object LeaveJitsiConference : RoomDetailViewEvents()
4747

vector/src/main/java/im/vector/app/features/home/room/detail/TimelineFragment.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,9 @@ class TimelineFragment :
748748
}
749749

750750
private fun navigateToEvent(action: RoomDetailViewEvents.NavigateToEvent) {
751-
val scrollPosition = timelineEventController.searchPositionOfEvent(action.eventId)
751+
val scrollPosition = timelineEventController.getPositionOfReadMarker().takeIf { action.isFirstUnreadEvent }
752+
?: timelineEventController.searchPositionOfEvent(action.eventId)
753+
752754
if (scrollPosition == null) {
753755
scrollOnHighlightedEventCallback.scheduleScrollTo(action.eventId)
754756
} else {
@@ -1995,10 +1997,10 @@ class TimelineFragment :
19951997

19961998
private fun onJumpToReadMarkerClicked() = withState(timelineViewModel) {
19971999
if (it.unreadState is UnreadState.HasUnread) {
1998-
timelineViewModel.handle(RoomDetailAction.NavigateToEvent(it.unreadState.firstUnreadEventId, false))
2000+
timelineViewModel.handle(RoomDetailAction.NavigateToEvent(it.unreadState.firstUnreadEventId, highlight = false, isFirstUnreadEvent = true))
19992001
}
20002002
if (it.unreadState is UnreadState.ReadMarkerNotLoaded) {
2001-
timelineViewModel.handle(RoomDetailAction.NavigateToEvent(it.unreadState.readMarkerId, false))
2003+
timelineViewModel.handle(RoomDetailAction.NavigateToEvent(it.unreadState.readMarkerId, highlight = false))
20022004
}
20032005
}
20042006

vector/src/main/java/im/vector/app/features/home/room/detail/TimelineViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ class TimelineViewModel @AssistedInject constructor(
10331033
if (action.highlight) {
10341034
setState { copy(highlightedEventId = targetEventId) }
10351035
}
1036-
_viewEvents.post(RoomDetailViewEvents.NavigateToEvent(targetEventId))
1036+
_viewEvents.post(RoomDetailViewEvents.NavigateToEvent(targetEventId, action.isFirstUnreadEvent))
10371037
}
10381038

10391039
private fun handleResendEvent(action: RoomDetailAction.ResendMessage) {

0 commit comments

Comments
 (0)