Open-at-unread: add option to not mark as read until fully read

Change-Id: Ie700cee773bce08248212ddd3fcc7793b4a919cc
This commit is contained in:
SpiritCroc 2022-03-22 08:27:22 +01:00
parent 22b5cb2d31
commit 7723b45993
6 changed files with 30 additions and 4 deletions

View file

@ -51,6 +51,11 @@ interface ReadService {
*/
suspend fun setMarkedUnread(markedUnread: Boolean)
/**
* Change the explicitly set unread marker flag
*/
suspend fun setMarkedUnreadFlag(markedUnread: Boolean)
/**
* Check if an event is already read, ie. your read receipt is set on a more recent event.
*/

View file

@ -80,7 +80,7 @@ internal class DefaultReadService @AssistedInject constructor(
}
}
private suspend fun setMarkedUnreadFlag(markedUnread: Boolean) {
override suspend fun setMarkedUnreadFlag(markedUnread: Boolean) {
val params = SetMarkedUnreadTask.Params(roomId, markedUnread = markedUnread)
setMarkedUnreadTask.execute(params)
}

View file

@ -195,11 +195,15 @@ class TimelineViewModel @AssistedInject constructor(
setupPreviewUrlObservers()
room.getRoomSummaryLive()
viewModelScope.launch(Dispatchers.IO) {
if (!loadRoomAtFirstUnread()) {
tryOrNull { room.markAsRead(ReadService.MarkAsReadParams.READ_RECEIPT) }
if (loadRoomAtFirstUnread()) {
if (vectorPreferences.readReceiptFollowsReadMarker()) {
tryOrNull { room.setMarkedUnreadFlag(false) }
} else {
tryOrNull { room.setMarkedUnread(false) }
}
} else {
tryOrNull { room.markAsRead(ReadService.MarkAsReadParams.READ_RECEIPT) }
}
}
// Inform the SDK that the room is displayed
viewModelScope.launch(Dispatchers.IO) {

View file

@ -217,6 +217,7 @@ class VectorPreferences @Inject constructor(private val context: Context, privat
private const val SETTINGS_ENABLE_SPACE_PAGER = "SETTINGS_ENABLE_SPACE_PAGER"
private const val SETTINGS_NOTIF_ONLY_ALERT_ONCE = "SETTINGS_NOTIF_ONLY_ALERT_ONCE"
private const val SETTINGS_HIDE_CALL_BUTTONS = "SETTINGS_HIDE_CALL_BUTTONS"
private const val SETTINGS_READ_RECEIPT_FOLLOWS_READ_MARKER = "SETTINGS_READ_RECEIPT_FOLLOWS_READ_MARKER"
private const val DID_ASK_TO_ENABLE_SESSION_PUSH = "DID_ASK_TO_ENABLE_SESSION_PUSH"
@ -1089,6 +1090,11 @@ class VectorPreferences @Inject constructor(private val context: Context, privat
return defaultPrefs.getBoolean(SETTINGS_HIDE_CALL_BUTTONS, false)
}
// SC addition
fun readReceiptFollowsReadMarker(): Boolean {
return defaultPrefs.getBoolean(SETTINGS_READ_RECEIPT_FOLLOWS_READ_MARKER, false)
}
/**
* I likely do more fresh installs of the app than anyone else, so a shortcut to change some of the default settings to
* my preferred values can safe me some time
@ -1112,6 +1118,7 @@ class VectorPreferences @Inject constructor(private val context: Context, privat
.putBoolean(SETTINGS_UNIFIED_PUSH_FORCE_CUSTOM_GATEWAY, true)
.putBoolean(SETTINGS_AGGREGATE_UNREAD_COUNTS, false)
.putBoolean(SETTINGS_ENABLE_SPACE_PAGER, true)
.putBoolean(SETTINGS_READ_RECEIPT_FOLLOWS_READ_MARKER, true)
.apply()
}

View file

@ -183,4 +183,7 @@
<string name="settings_upstream_labs">Element features</string>
<string name="settings_labs_room_list">Room list</string>
<string name="settings_labs_timeline">Timeline</string>
<string name="settings_read_receipt_follows_read_marker">Only mark chats as read if fully read</string>
<string name="settings_read_receipt_follows_read_marker_summary">Do not update your read receipt when opening the room, but only gradually while reading</string>
</resources>

View file

@ -29,6 +29,13 @@
android:title="@string/settings_open_chats_at_first_unread"
android:summary="@string/settings_open_chats_at_first_unread_summary" />
<im.vector.app.core.preference.VectorSwitchPreference
android:defaultValue="false"
android:key="SETTINGS_READ_RECEIPT_FOLLOWS_READ_MARKER"
android:dependency="SETTINGS_OPEN_CHATS_AT_FIRST_UNREAD"
android:title="@string/settings_read_receipt_follows_read_marker"
android:summary="@string/settings_read_receipt_follows_read_marker_summary" />
<im.vector.app.core.preference.VectorSwitchPreference
android:defaultValue="false"
android:key="SETTINGS_ALLOW_URL_PREVIEW_IN_ENCRYPTED_ROOM_KEY"