diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt index 4655ebb12e..a73c7b1b05 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt @@ -229,7 +229,8 @@ data class RoomDetailArgs( val roomId: String, val eventId: String? = null, val sharedData: SharedData? = null, - val openShareSpaceForId: String? = null + val openShareSpaceForId: String? = null, + val openAtFirstUnread: Boolean? = null ) : Parcelable class RoomDetailFragment @Inject constructor( diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt index 806d3ee11e..d43732e901 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt @@ -123,7 +123,7 @@ class RoomDetailViewModel @AssistedInject constructor( Timeline.Listener, ChatEffectManager.Delegate, CallProtocolsChecker.Listener { private val room = session.getRoom(initialState.roomId)!! - private val eventId = initialState.eventId ?: if (vectorPreferences.loadRoomAtFirstUnread()) room.roomSummary()?.readMarkerId else null + private val eventId = initialState.eventId ?: if (loadRoomAtFirstUnread()) room.roomSummary()?.readMarkerId else null private val invisibleEventsObservable = BehaviorRelay.create() private val visibleEventsObservable = BehaviorRelay.create() private var timelineEvents = MutableSharedFlow>(0) @@ -181,7 +181,7 @@ class RoomDetailViewModel @AssistedInject constructor( observePowerLevel() room.getRoomSummaryLive() viewModelScope.launch(Dispatchers.IO) { - if (!vectorPreferences.loadRoomAtFirstUnread()) { + if (!loadRoomAtFirstUnread()) { tryOrNull { room.markAsRead(ReadService.MarkAsReadParams.READ_RECEIPT) } } else { tryOrNull { room.setMarkedUnread(false) } @@ -564,7 +564,7 @@ class RoomDetailViewModel @AssistedInject constructor( mostRecentDisplayedEvent?.root?.eventId?.also { session.coroutineScope.launch(NonCancellable) { tryOrNull { room.setReadMarker(it) } - if (vectorPreferences.loadRoomAtFirstUnread()) { + if (loadRoomAtFirstUnread()) { tryOrNull { room.setReadReceipt(it) } } } @@ -1148,4 +1148,8 @@ class RoomDetailViewModel @AssistedInject constructor( callManager.removeProtocolsCheckerListener(this) super.onCleared() } + + private fun loadRoomAtFirstUnread(): Boolean { + return initialState.openAtFirstUnread ?: vectorPreferences.loadRoomAtFirstUnread() + } } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewState.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewState.kt index 128c64a7c6..d67604bee4 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewState.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewState.kt @@ -48,6 +48,7 @@ data class JitsiState( data class RoomDetailViewState( val roomId: String, val eventId: String?, + val openAtFirstUnread: Boolean? = null, val myRoomMember: Async = Uninitialized, val asyncInviter: Async = Uninitialized, val asyncRoomSummary: Async = Uninitialized, @@ -74,7 +75,8 @@ data class RoomDetailViewState( roomId = args.roomId, eventId = args.eventId, // Also highlight the target event, if any - highlightedEventId = args.eventId + highlightedEventId = args.eventId, + openAtFirstUnread = args.openAtFirstUnread ) fun isWebRTCCallOptionAvailable() = (asyncRoomSummary.invoke()?.joinedMembersCount ?: 0) <= 2 diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt index 05a797f9ea..ba238645fc 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt @@ -429,6 +429,9 @@ class RoomListFragment @Inject constructor( is RoomListQuickActionsSharedAction.MarkRead -> { roomListViewModel.handle(RoomListAction.SetMarkedUnread(quickAction.roomId, false)) } + is RoomListQuickActionsSharedAction.OpenAtBottom -> { + navigator.openRoom(requireActivity(), quickAction.roomId, openAtFirstUnread = false) + } is RoomListQuickActionsSharedAction.Leave -> { promptLeaveRoom(quickAction.roomId) } diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/actions/RoomListQuickActionsEpoxyController.kt b/vector/src/main/java/im/vector/app/features/home/room/list/actions/RoomListQuickActionsEpoxyController.kt index 6331764a7e..e343df8e66 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/actions/RoomListQuickActionsEpoxyController.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/actions/RoomListQuickActionsEpoxyController.kt @@ -76,12 +76,18 @@ class RoomListQuickActionsEpoxyController @Inject constructor( id("mark_unread_separator") } if (roomSummary.scIsUnread()) { - RoomListQuickActionsSharedAction.MarkRead(roomSummary.roomId).toBottomSheetItem(-1) + RoomListQuickActionsSharedAction.MarkRead(roomSummary.roomId).toBottomSheetItem(-2) } else { - RoomListQuickActionsSharedAction.MarkUnread(roomSummary.roomId).toBottomSheetItem(-1) + RoomListQuickActionsSharedAction.MarkUnread(roomSummary.roomId).toBottomSheetItem(-2) } } + if (vectorPreferences.loadRoomAtFirstUnread()) { + // TODO can we check if position of roomSummary.readMarkerId is below or equal to + // roomSummary.latestPreviewableOriginalContentEvent, and hide this otherwise? + RoomListQuickActionsSharedAction.OpenAtBottom(roomSummary.roomId).toBottomSheetItem(-1) + } + // Notifications bottomSheetDividerItem { id("notifications_separator") diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/actions/RoomListQuickActionsSharedAction.kt b/vector/src/main/java/im/vector/app/features/home/room/list/actions/RoomListQuickActionsSharedAction.kt index da157435f9..c66f289217 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/actions/RoomListQuickActionsSharedAction.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/actions/RoomListQuickActionsSharedAction.kt @@ -37,6 +37,11 @@ sealed class RoomListQuickActionsSharedAction( R.drawable.ic_room_actions_mark_room_read ) + data class OpenAtBottom(val roomId: String) : RoomListQuickActionsSharedAction( + R.string.room_list_quick_actions_open_at_bottom, + R.drawable.ic_room_actions_open_at_bottom + ) + data class NotificationsAllNoisy(val roomId: String) : RoomListQuickActionsSharedAction( R.string.room_list_quick_actions_notifications_all_noisy, R.drawable.ic_room_actions_notifications_all_noisy diff --git a/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt b/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt index debdf3739c..9a28c1a080 100644 --- a/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt +++ b/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt @@ -113,12 +113,12 @@ class DefaultNavigator @Inject constructor( context.startActivity(intent) } - override fun openRoom(context: Context, roomId: String, eventId: String?, buildTask: Boolean) { + override fun openRoom(context: Context, roomId: String, eventId: String?, buildTask: Boolean, openAtFirstUnread: Boolean?) { if (sessionHolder.getSafeActiveSession()?.getRoom(roomId) == null) { fatalError("Trying to open an unknown room $roomId", vectorPreferences.failFast()) return } - val args = RoomDetailArgs(roomId, eventId) + val args = RoomDetailArgs(roomId, eventId, openAtFirstUnread = openAtFirstUnread) val intent = RoomDetailActivity.newIntent(context, args) startActivity(context, intent, buildTask) } diff --git a/vector/src/main/java/im/vector/app/features/navigation/Navigator.kt b/vector/src/main/java/im/vector/app/features/navigation/Navigator.kt index 612643c804..1bfef4a25a 100644 --- a/vector/src/main/java/im/vector/app/features/navigation/Navigator.kt +++ b/vector/src/main/java/im/vector/app/features/navigation/Navigator.kt @@ -41,7 +41,7 @@ interface Navigator { fun openLogin(context: Context, loginConfig: LoginConfig? = null, flags: Int = 0) - fun openRoom(context: Context, roomId: String, eventId: String? = null, buildTask: Boolean = false) + fun openRoom(context: Context, roomId: String, eventId: String? = null, buildTask: Boolean = false, openAtFirstUnread: Boolean? = null) sealed class PostSwitchSpaceAction { object None : PostSwitchSpaceAction() diff --git a/vector/src/main/res/drawable/ic_room_actions_open_at_bottom.xml b/vector/src/main/res/drawable/ic_room_actions_open_at_bottom.xml new file mode 100644 index 0000000000..ecf9f0422a --- /dev/null +++ b/vector/src/main/res/drawable/ic_room_actions_open_at_bottom.xml @@ -0,0 +1,7 @@ + + + diff --git a/vector/src/main/res/values/strings_sc.xml b/vector/src/main/res/values/strings_sc.xml index 5378299dd9..c7fd47696c 100644 --- a/vector/src/main/res/values/strings_sc.xml +++ b/vector/src/main/res/values/strings_sc.xml @@ -69,6 +69,7 @@ Participants Mark as unread Mark as read + Open at recent messages Message status