From dc65e60e66581769075618f4dcea8e19a73b7a54 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 8 Feb 2024 11:49:14 +0100 Subject: [PATCH] Mark as unread: add a feature flag, disabled on release build. --- .../roomlist/impl/RoomListContextMenu.kt | 62 ++++++++++--------- .../roomlist/impl/RoomListPresenter.kt | 4 ++ .../features/roomlist/impl/RoomListState.kt | 1 + .../roomlist/impl/RoomListStateProvider.kt | 1 + .../roomlist/impl/RoomListPresenterTests.kt | 2 + .../libraries/featureflag/api/FeatureFlags.kt | 7 +++ .../impl/StaticFeatureFlagProvider.kt | 1 + 7 files changed, 48 insertions(+), 30 deletions(-) diff --git a/features/roomlist/impl/src/main/kotlin/io/element/android/features/roomlist/impl/RoomListContextMenu.kt b/features/roomlist/impl/src/main/kotlin/io/element/android/features/roomlist/impl/RoomListContextMenu.kt index fc42ee7af6..cdd8c4527d 100644 --- a/features/roomlist/impl/src/main/kotlin/io/element/android/features/roomlist/impl/RoomListContextMenu.kt +++ b/features/roomlist/impl/src/main/kotlin/io/element/android/features/roomlist/impl/RoomListContextMenu.kt @@ -88,36 +88,38 @@ private fun RoomListModalBottomSheetContent( ) } ) - ListItem( - headlineContent = { - Text( - text = stringResource( - id = if (contextMenu.hasNewContent) { - R.string.screen_roomlist_mark_as_read - } else { - R.string.screen_roomlist_mark_as_unread - } - ), - style = MaterialTheme.typography.bodyLarge, - ) - }, - modifier = Modifier.clickable { - if (contextMenu.hasNewContent) { - onRoomMarkReadClicked() - } else { - onRoomMarkUnreadClicked() - } - }, - /* TODO Design - leadingContent = ListItemContent.Icon( - iconSource = IconSource.Vector( - CompoundIcons.Settings, - contentDescription = stringResource(id = CommonStrings.common_settings) - ) - ), - */ - style = ListItemStyle.Primary, - ) + if (contextMenu.markAsUnreadFeatureFlagEnabled) { + ListItem( + headlineContent = { + Text( + text = stringResource( + id = if (contextMenu.hasNewContent) { + R.string.screen_roomlist_mark_as_read + } else { + R.string.screen_roomlist_mark_as_unread + } + ), + style = MaterialTheme.typography.bodyLarge, + ) + }, + modifier = Modifier.clickable { + if (contextMenu.hasNewContent) { + onRoomMarkReadClicked() + } else { + onRoomMarkUnreadClicked() + } + }, + /* TODO Design + leadingContent = ListItemContent.Icon( + iconSource = IconSource.Vector( + CompoundIcons.Settings, + contentDescription = stringResource(id = CommonStrings.common_settings) + ) + ), + */ + style = ListItemStyle.Primary, + ) + } ListItem( headlineContent = { Text( diff --git a/features/roomlist/impl/src/main/kotlin/io/element/android/features/roomlist/impl/RoomListPresenter.kt b/features/roomlist/impl/src/main/kotlin/io/element/android/features/roomlist/impl/RoomListPresenter.kt index 2a06914aa2..fa841ff88f 100644 --- a/features/roomlist/impl/src/main/kotlin/io/element/android/features/roomlist/impl/RoomListPresenter.kt +++ b/features/roomlist/impl/src/main/kotlin/io/element/android/features/roomlist/impl/RoomListPresenter.kt @@ -111,6 +111,9 @@ class RoomListPresenter @Inject constructor( } } + val markAsUnreadFeatureFlagEnabled by featureFlagService.isFeatureEnabledFlow(FeatureFlags.MarkAsUnread) + .collectAsState(initial = null) + // Avatar indicator val showAvatarIndicator by indicatorService.showRoomListTopBarIndicator() @@ -135,6 +138,7 @@ class RoomListPresenter @Inject constructor( roomId = event.roomListRoomSummary.roomId, roomName = event.roomListRoomSummary.name, isDm = event.roomListRoomSummary.isDm, + markAsUnreadFeatureFlagEnabled = markAsUnreadFeatureFlagEnabled == true, hasNewContent = event.roomListRoomSummary.hasNewContent ) } diff --git a/features/roomlist/impl/src/main/kotlin/io/element/android/features/roomlist/impl/RoomListState.kt b/features/roomlist/impl/src/main/kotlin/io/element/android/features/roomlist/impl/RoomListState.kt index 10dd17037a..d2f1a55671 100644 --- a/features/roomlist/impl/src/main/kotlin/io/element/android/features/roomlist/impl/RoomListState.kt +++ b/features/roomlist/impl/src/main/kotlin/io/element/android/features/roomlist/impl/RoomListState.kt @@ -49,6 +49,7 @@ data class RoomListState( val roomId: RoomId, val roomName: String, val isDm: Boolean, + val markAsUnreadFeatureFlagEnabled: Boolean, val hasNewContent: Boolean, ) : ContextMenu } diff --git a/features/roomlist/impl/src/main/kotlin/io/element/android/features/roomlist/impl/RoomListStateProvider.kt b/features/roomlist/impl/src/main/kotlin/io/element/android/features/roomlist/impl/RoomListStateProvider.kt index 64f75c85dc..c975ee069a 100644 --- a/features/roomlist/impl/src/main/kotlin/io/element/android/features/roomlist/impl/RoomListStateProvider.kt +++ b/features/roomlist/impl/src/main/kotlin/io/element/android/features/roomlist/impl/RoomListStateProvider.kt @@ -106,5 +106,6 @@ internal fun aContextMenuShown( roomId = RoomId("!aRoom:aDomain"), roomName = roomName, isDm = isDm, + markAsUnreadFeatureFlagEnabled = true, hasNewContent = hasNewContent, ) diff --git a/features/roomlist/impl/src/test/kotlin/io/element/android/features/roomlist/impl/RoomListPresenterTests.kt b/features/roomlist/impl/src/test/kotlin/io/element/android/features/roomlist/impl/RoomListPresenterTests.kt index 1ede6b44d4..49d7eb2974 100644 --- a/features/roomlist/impl/src/test/kotlin/io/element/android/features/roomlist/impl/RoomListPresenterTests.kt +++ b/features/roomlist/impl/src/test/kotlin/io/element/android/features/roomlist/impl/RoomListPresenterTests.kt @@ -356,6 +356,7 @@ class RoomListPresenterTests { roomId = summary.roomId, roomName = summary.name, isDm = false, + markAsUnreadFeatureFlagEnabled = true, hasNewContent = false, ) ) @@ -382,6 +383,7 @@ class RoomListPresenterTests { roomId = summary.roomId, roomName = summary.name, isDm = false, + markAsUnreadFeatureFlagEnabled = true, hasNewContent = false, ) ) diff --git a/libraries/featureflag/api/src/main/kotlin/io/element/android/libraries/featureflag/api/FeatureFlags.kt b/libraries/featureflag/api/src/main/kotlin/io/element/android/libraries/featureflag/api/FeatureFlags.kt index 61c155caac..3c56c81fae 100644 --- a/libraries/featureflag/api/src/main/kotlin/io/element/android/libraries/featureflag/api/FeatureFlags.kt +++ b/libraries/featureflag/api/src/main/kotlin/io/element/android/libraries/featureflag/api/FeatureFlags.kt @@ -75,4 +75,11 @@ enum class FeatureFlags( defaultValue = true, isFinished = false, ), + MarkAsUnread( + key = "feature.markAsUnread", + title = "Mark as unread", + description = "Allow user to mark a room as unread", + defaultValue = true, + isFinished = false, + ), } diff --git a/libraries/featureflag/impl/src/main/kotlin/io/element/android/libraries/featureflag/impl/StaticFeatureFlagProvider.kt b/libraries/featureflag/impl/src/main/kotlin/io/element/android/libraries/featureflag/impl/StaticFeatureFlagProvider.kt index 75b16d4e84..8462a33ba5 100644 --- a/libraries/featureflag/impl/src/main/kotlin/io/element/android/libraries/featureflag/impl/StaticFeatureFlagProvider.kt +++ b/libraries/featureflag/impl/src/main/kotlin/io/element/android/libraries/featureflag/impl/StaticFeatureFlagProvider.kt @@ -40,6 +40,7 @@ class StaticFeatureFlagProvider @Inject constructor() : FeatureFlags.PinUnlock -> true FeatureFlags.Mentions -> true FeatureFlags.SecureStorage -> true + FeatureFlags.MarkAsUnread -> false } } else { false