Open room at bottom action if open at unread

Change-Id: Ia933c5a9f31c4025a34912a82f699e5c5abe8dd3
This commit is contained in:
SpiritCroc 2021-10-25 19:47:32 +02:00
parent 61140f3698
commit 9cb746d509
10 changed files with 39 additions and 10 deletions

View File

@ -229,7 +229,8 @@ data class RoomDetailArgs(
val roomId: String, val roomId: String,
val eventId: String? = null, val eventId: String? = null,
val sharedData: SharedData? = null, val sharedData: SharedData? = null,
val openShareSpaceForId: String? = null val openShareSpaceForId: String? = null,
val openAtFirstUnread: Boolean? = null
) : Parcelable ) : Parcelable
class RoomDetailFragment @Inject constructor( class RoomDetailFragment @Inject constructor(

View File

@ -123,7 +123,7 @@ class RoomDetailViewModel @AssistedInject constructor(
Timeline.Listener, ChatEffectManager.Delegate, CallProtocolsChecker.Listener { Timeline.Listener, ChatEffectManager.Delegate, CallProtocolsChecker.Listener {
private val room = session.getRoom(initialState.roomId)!! 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<RoomDetailAction.TimelineEventTurnsInvisible>() private val invisibleEventsObservable = BehaviorRelay.create<RoomDetailAction.TimelineEventTurnsInvisible>()
private val visibleEventsObservable = BehaviorRelay.create<RoomDetailAction.TimelineEventTurnsVisible>() private val visibleEventsObservable = BehaviorRelay.create<RoomDetailAction.TimelineEventTurnsVisible>()
private var timelineEvents = MutableSharedFlow<List<TimelineEvent>>(0) private var timelineEvents = MutableSharedFlow<List<TimelineEvent>>(0)
@ -181,7 +181,7 @@ class RoomDetailViewModel @AssistedInject constructor(
observePowerLevel() observePowerLevel()
room.getRoomSummaryLive() room.getRoomSummaryLive()
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch(Dispatchers.IO) {
if (!vectorPreferences.loadRoomAtFirstUnread()) { if (!loadRoomAtFirstUnread()) {
tryOrNull { room.markAsRead(ReadService.MarkAsReadParams.READ_RECEIPT) } tryOrNull { room.markAsRead(ReadService.MarkAsReadParams.READ_RECEIPT) }
} else { } else {
tryOrNull { room.setMarkedUnread(false) } tryOrNull { room.setMarkedUnread(false) }
@ -564,7 +564,7 @@ class RoomDetailViewModel @AssistedInject constructor(
mostRecentDisplayedEvent?.root?.eventId?.also { mostRecentDisplayedEvent?.root?.eventId?.also {
session.coroutineScope.launch(NonCancellable) { session.coroutineScope.launch(NonCancellable) {
tryOrNull { room.setReadMarker(it) } tryOrNull { room.setReadMarker(it) }
if (vectorPreferences.loadRoomAtFirstUnread()) { if (loadRoomAtFirstUnread()) {
tryOrNull { room.setReadReceipt(it) } tryOrNull { room.setReadReceipt(it) }
} }
} }
@ -1148,4 +1148,8 @@ class RoomDetailViewModel @AssistedInject constructor(
callManager.removeProtocolsCheckerListener(this) callManager.removeProtocolsCheckerListener(this)
super.onCleared() super.onCleared()
} }
private fun loadRoomAtFirstUnread(): Boolean {
return initialState.openAtFirstUnread ?: vectorPreferences.loadRoomAtFirstUnread()
}
} }

View File

@ -48,6 +48,7 @@ data class JitsiState(
data class RoomDetailViewState( data class RoomDetailViewState(
val roomId: String, val roomId: String,
val eventId: String?, val eventId: String?,
val openAtFirstUnread: Boolean? = null,
val myRoomMember: Async<RoomMemberSummary> = Uninitialized, val myRoomMember: Async<RoomMemberSummary> = Uninitialized,
val asyncInviter: Async<RoomMemberSummary> = Uninitialized, val asyncInviter: Async<RoomMemberSummary> = Uninitialized,
val asyncRoomSummary: Async<RoomSummary> = Uninitialized, val asyncRoomSummary: Async<RoomSummary> = Uninitialized,
@ -74,7 +75,8 @@ data class RoomDetailViewState(
roomId = args.roomId, roomId = args.roomId,
eventId = args.eventId, eventId = args.eventId,
// Also highlight the target event, if any // Also highlight the target event, if any
highlightedEventId = args.eventId highlightedEventId = args.eventId,
openAtFirstUnread = args.openAtFirstUnread
) )
fun isWebRTCCallOptionAvailable() = (asyncRoomSummary.invoke()?.joinedMembersCount ?: 0) <= 2 fun isWebRTCCallOptionAvailable() = (asyncRoomSummary.invoke()?.joinedMembersCount ?: 0) <= 2

View File

@ -429,6 +429,9 @@ class RoomListFragment @Inject constructor(
is RoomListQuickActionsSharedAction.MarkRead -> { is RoomListQuickActionsSharedAction.MarkRead -> {
roomListViewModel.handle(RoomListAction.SetMarkedUnread(quickAction.roomId, false)) roomListViewModel.handle(RoomListAction.SetMarkedUnread(quickAction.roomId, false))
} }
is RoomListQuickActionsSharedAction.OpenAtBottom -> {
navigator.openRoom(requireActivity(), quickAction.roomId, openAtFirstUnread = false)
}
is RoomListQuickActionsSharedAction.Leave -> { is RoomListQuickActionsSharedAction.Leave -> {
promptLeaveRoom(quickAction.roomId) promptLeaveRoom(quickAction.roomId)
} }

View File

@ -76,12 +76,18 @@ class RoomListQuickActionsEpoxyController @Inject constructor(
id("mark_unread_separator") id("mark_unread_separator")
} }
if (roomSummary.scIsUnread()) { if (roomSummary.scIsUnread()) {
RoomListQuickActionsSharedAction.MarkRead(roomSummary.roomId).toBottomSheetItem(-1) RoomListQuickActionsSharedAction.MarkRead(roomSummary.roomId).toBottomSheetItem(-2)
} else { } 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 // Notifications
bottomSheetDividerItem { bottomSheetDividerItem {
id("notifications_separator") id("notifications_separator")

View File

@ -37,6 +37,11 @@ sealed class RoomListQuickActionsSharedAction(
R.drawable.ic_room_actions_mark_room_read 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( data class NotificationsAllNoisy(val roomId: String) : RoomListQuickActionsSharedAction(
R.string.room_list_quick_actions_notifications_all_noisy, R.string.room_list_quick_actions_notifications_all_noisy,
R.drawable.ic_room_actions_notifications_all_noisy R.drawable.ic_room_actions_notifications_all_noisy

View File

@ -113,12 +113,12 @@ class DefaultNavigator @Inject constructor(
context.startActivity(intent) 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) { if (sessionHolder.getSafeActiveSession()?.getRoom(roomId) == null) {
fatalError("Trying to open an unknown room $roomId", vectorPreferences.failFast()) fatalError("Trying to open an unknown room $roomId", vectorPreferences.failFast())
return return
} }
val args = RoomDetailArgs(roomId, eventId) val args = RoomDetailArgs(roomId, eventId, openAtFirstUnread = openAtFirstUnread)
val intent = RoomDetailActivity.newIntent(context, args) val intent = RoomDetailActivity.newIntent(context, args)
startActivity(context, intent, buildTask) startActivity(context, intent, buildTask)
} }

View File

@ -41,7 +41,7 @@ interface Navigator {
fun openLogin(context: Context, loginConfig: LoginConfig? = null, flags: Int = 0) 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 { sealed class PostSwitchSpaceAction {
object None : PostSwitchSpaceAction() object None : PostSwitchSpaceAction()

View File

@ -0,0 +1,7 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:fillColor="#000" android:pathData="M7.41,14.58L12,19.17L16.59,14.58L18,16L12,22L6,16L7.41,14.58M7.41,8.58L12,13.17L16.59,8.58L18,10L12,16L6,10L7.41,8.58M7.41,2.58L12,7.17L16.59,2.58L18,4L12,10L6,4L7.41,2.58Z" />
</vector>

View File

@ -69,6 +69,7 @@
<string name="show_participants_sc">Participants</string> <string name="show_participants_sc">Participants</string>
<string name="room_list_quick_actions_mark_room_unread">Mark as unread</string> <string name="room_list_quick_actions_mark_room_unread">Mark as unread</string>
<string name="room_list_quick_actions_mark_room_read">Mark as read</string> <string name="room_list_quick_actions_mark_room_read">Mark as read</string>
<string name="room_list_quick_actions_open_at_bottom">Open at recent messages</string>
<string name="footer_read_receipt_content_description">Message status</string> <string name="footer_read_receipt_content_description">Message status</string>