Add option to mark read chats while having open without reading

Change-Id: I75a136b1bdfd3e6667bb43b43ff8fcaab275e7d9
This commit is contained in:
SpiritCroc 2022-09-11 19:55:24 +02:00
parent 293304b2c4
commit ae3b771238
5 changed files with 18 additions and 8 deletions

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="MissingTranslation">
<string name="normal_priority_header">Normal priority</string>

View file

@ -39,7 +39,7 @@ sealed class RoomDetailAction : VectorViewModelAction {
data class RedactAction(val targetEventId: String, val reason: String? = "") : RoomDetailAction()
data class UpdateQuickReactAction(val targetEventId: String, val selectedReaction: String, val add: Boolean) : RoomDetailAction()
data class NavigateToEvent(val eventId: String, val highlight: Boolean) : RoomDetailAction()
object MarkAllAsRead : RoomDetailAction()
data class MarkAllAsRead(val forceIfOpenedAnonymously: Boolean = false) : RoomDetailAction()
data class DownloadOrOpen(val eventId: String, val senderId: String?, val messageFileContent: MessageWithAttachmentContent) : RoomDetailAction()
object JoinAndOpenReplacementRoom : RoomDetailAction()
object OnClickMisconfiguredEncryption : RoomDetailAction()

View file

@ -1073,7 +1073,7 @@ class TimelineFragment :
onJumpToReadMarkerClicked()
}
views.jumpToReadMarkerView.setOnCloseIconClickListener {
timelineViewModel.handle(RoomDetailAction.MarkAllAsRead)
timelineViewModel.handle(RoomDetailAction.MarkAllAsRead())
}
}
@ -1291,6 +1291,10 @@ class TimelineFragment :
navigator.openRoomProfile(requireActivity(), timelineArgs.roomId)
true
}
R.id.menu_mark_as_read -> {
timelineViewModel.handle(RoomDetailAction.MarkAllAsRead(forceIfOpenedAnonymously = true))
true
}
R.id.dev_hidden_events -> {
item.toggleExec { shouldShow ->
vectorPreferences.setShouldShowHiddenEvents(shouldShow)

View file

@ -472,7 +472,7 @@ class TimelineViewModel @AssistedInject constructor(
is RoomDetailAction.OnClickMisconfiguredEncryption -> handleClickMisconfiguredE2E()
is RoomDetailAction.ResendMessage -> handleResendEvent(action)
is RoomDetailAction.RemoveFailedEcho -> handleRemove(action)
is RoomDetailAction.MarkAllAsRead -> handleMarkAllAsRead()
is RoomDetailAction.MarkAllAsRead -> handleMarkAllAsRead(action)
is RoomDetailAction.ReportContent -> handleReportContent(action)
is RoomDetailAction.IgnoreUser -> handleIgnoreUser(action)
is RoomDetailAction.EnterTrackingUnreadMessagesState -> startTrackingUnreadMessages(action)
@ -835,6 +835,7 @@ class TimelineViewModel @AssistedInject constructor(
// SC extras start
R.id.show_room_info -> true // SC
R.id.show_participants -> true // SC
R.id.menu_mark_as_read -> initialState.openAnonymously
// SC dev start
R.id.dev_bubble_style,
R.id.dev_hidden_events,
@ -1120,11 +1121,11 @@ class TimelineViewModel @AssistedInject constructor(
*/
private fun TimelineEvent.indexOfEvent(): Int = timeline?.getIndexOfEvent(eventId) ?: Int.MAX_VALUE
private fun handleMarkAllAsRead() {
private fun handleMarkAllAsRead(action: RoomDetailAction.MarkAllAsRead) {
if (room == null) return
setState { copy(unreadState = UnreadState.HasNoUnread) }
viewModelScope.launch {
tryOrNullAnon { room.readService().markAsRead(ReadService.MarkAsReadParams.BOTH) }
tryOrNullAnon(action.forceIfOpenedAnonymously) { room.readService().markAsRead(ReadService.MarkAsReadParams.BOTH) }
}
}
@ -1481,8 +1482,8 @@ class TimelineViewModel @AssistedInject constructor(
return initialState.openAtFirstUnread ?: vectorPreferences.loadRoomAtFirstUnread()
}
private inline fun <A>tryOrNullAnon(operation: () -> A): A? {
if (initialState.openAnonymously) {
private inline fun <A>tryOrNullAnon(forceAllow: Boolean = false, operation: () -> A): A? {
if (initialState.openAnonymously && !forceAllow) {
return null
}
return tryOrNull { operation() }

View file

@ -168,6 +168,11 @@
</menu>
</item>
<item
android:id="@+id/menu_mark_as_read"
android:title="@string/room_list_quick_actions_mark_room_read"
app:showAsAction="never" />
<item
android:id="@+id/menu_thread_timeline_view_in_room"
android:icon="@drawable/ic_threads_view_in_room_24"