From e9d809d9c338b9ed3707945ba9ef4dc6e24a22a2 Mon Sep 17 00:00:00 2001 From: Florian Renaud Date: Mon, 19 Sep 2022 18:50:05 +0200 Subject: [PATCH 1/5] Move and enable deferred DMs into labs settings --- library/ui-strings/src/main/res/values/strings.xml | 3 +++ .../features/debug/features/DebugFeaturesStateFactory.kt | 5 ----- .../app/features/debug/features/DebugVectorFeatures.kt | 3 --- vector-config/src/main/res/values/config-settings.xml | 1 + .../main/java/im/vector/app/features/VectorFeatures.kt | 2 -- .../features/createdirect/CreateDirectRoomViewModel.kt | 6 +++--- .../vector/app/features/createdirect/DirectRoomHelper.kt | 6 +++--- .../im/vector/app/features/settings/VectorPreferences.kt | 8 ++++++++ vector/src/main/res/xml/vector_settings_labs.xml | 6 ++++++ 9 files changed, 24 insertions(+), 16 deletions(-) diff --git a/library/ui-strings/src/main/res/values/strings.xml b/library/ui-strings/src/main/res/values/strings.xml index 714b48e8b4..99ff55a93d 100644 --- a/library/ui-strings/src/main/res/values/strings.xml +++ b/library/ui-strings/src/main/res/values/strings.xml @@ -442,6 +442,9 @@ Enable new layout A simplified Element with optional tabs + Enable deferred DMs + Direct rooms will be created after sending a first message. + Invites Low priority diff --git a/vector-app/src/debug/java/im/vector/app/features/debug/features/DebugFeaturesStateFactory.kt b/vector-app/src/debug/java/im/vector/app/features/debug/features/DebugFeaturesStateFactory.kt index 9b2711a8c3..9118dea1e3 100644 --- a/vector-app/src/debug/java/im/vector/app/features/debug/features/DebugFeaturesStateFactory.kt +++ b/vector-app/src/debug/java/im/vector/app/features/debug/features/DebugFeaturesStateFactory.kt @@ -80,11 +80,6 @@ class DebugFeaturesStateFactory @Inject constructor( key = DebugFeatureKeys.forceUsageOfOpusEncoder, factory = VectorFeatures::forceUsageOfOpusEncoder ), - createBooleanFeature( - label = "Start DM on first message", - key = DebugFeatureKeys.startDmOnFirstMsg, - factory = VectorFeatures::shouldStartDmOnFirstMessage - ), createBooleanFeature( label = "Enable New App Layout", key = DebugFeatureKeys.newAppLayoutEnabled, diff --git a/vector-app/src/debug/java/im/vector/app/features/debug/features/DebugVectorFeatures.kt b/vector-app/src/debug/java/im/vector/app/features/debug/features/DebugVectorFeatures.kt index bb4cae3201..c01c058fc6 100644 --- a/vector-app/src/debug/java/im/vector/app/features/debug/features/DebugVectorFeatures.kt +++ b/vector-app/src/debug/java/im/vector/app/features/debug/features/DebugVectorFeatures.kt @@ -73,9 +73,6 @@ class DebugVectorFeatures( override fun forceUsageOfOpusEncoder(): Boolean = read(DebugFeatureKeys.forceUsageOfOpusEncoder) ?: vectorFeatures.forceUsageOfOpusEncoder() - override fun shouldStartDmOnFirstMessage(): Boolean = read(DebugFeatureKeys.startDmOnFirstMsg) - ?: vectorFeatures.shouldStartDmOnFirstMessage() - override fun isNewAppLayoutFeatureEnabled(): Boolean = read(DebugFeatureKeys.newAppLayoutEnabled) ?: vectorFeatures.isNewAppLayoutFeatureEnabled() diff --git a/vector-config/src/main/res/values/config-settings.xml b/vector-config/src/main/res/values/config-settings.xml index 8953138e5e..3342b1da14 100755 --- a/vector-config/src/main/res/values/config-settings.xml +++ b/vector-config/src/main/res/values/config-settings.xml @@ -37,6 +37,7 @@ true + true false true true diff --git a/vector/src/main/java/im/vector/app/features/VectorFeatures.kt b/vector/src/main/java/im/vector/app/features/VectorFeatures.kt index dbdb0ba1c7..e1c083db29 100644 --- a/vector/src/main/java/im/vector/app/features/VectorFeatures.kt +++ b/vector/src/main/java/im/vector/app/features/VectorFeatures.kt @@ -33,7 +33,6 @@ interface VectorFeatures { fun isScreenSharingEnabled(): Boolean fun isLocationSharingEnabled(): Boolean fun forceUsageOfOpusEncoder(): Boolean - fun shouldStartDmOnFirstMessage(): Boolean /** * This is only to enable if the labs flag should be visible and effective. @@ -56,7 +55,6 @@ class DefaultVectorFeatures : VectorFeatures { override fun isScreenSharingEnabled(): Boolean = true override fun isLocationSharingEnabled() = Config.ENABLE_LOCATION_SHARING override fun forceUsageOfOpusEncoder(): Boolean = false - override fun shouldStartDmOnFirstMessage(): Boolean = false override fun isNewAppLayoutFeatureEnabled(): Boolean = true override fun isNewDeviceManagementEnabled(): Boolean = false } diff --git a/vector/src/main/java/im/vector/app/features/createdirect/CreateDirectRoomViewModel.kt b/vector/src/main/java/im/vector/app/features/createdirect/CreateDirectRoomViewModel.kt index 61ebc82767..3f67708a28 100644 --- a/vector/src/main/java/im/vector/app/features/createdirect/CreateDirectRoomViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/createdirect/CreateDirectRoomViewModel.kt @@ -26,11 +26,11 @@ import im.vector.app.core.di.MavericksAssistedViewModelFactory import im.vector.app.core.di.hiltMavericksViewModelFactory import im.vector.app.core.mvrx.runCatchingToAsync import im.vector.app.core.platform.VectorViewModel -import im.vector.app.features.VectorFeatures import im.vector.app.features.analytics.AnalyticsTracker import im.vector.app.features.analytics.plan.CreatedRoom import im.vector.app.features.raw.wellknown.getElementWellknown import im.vector.app.features.raw.wellknown.isE2EByDefault +import im.vector.app.features.settings.VectorPreferences import im.vector.app.features.userdirectory.PendingSelection import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -45,9 +45,9 @@ import org.matrix.android.sdk.api.session.room.model.create.CreateRoomParams class CreateDirectRoomViewModel @AssistedInject constructor( @Assisted initialState: CreateDirectRoomViewState, private val rawService: RawService, + private val vectorPreferences: VectorPreferences, val session: Session, val analyticsTracker: AnalyticsTracker, - val vectorFeatures: VectorFeatures ) : VectorViewModel(initialState) { @@ -124,7 +124,7 @@ class CreateDirectRoomViewModel @AssistedInject constructor( } val result = runCatchingToAsync { - if (vectorFeatures.shouldStartDmOnFirstMessage()) { + if (vectorPreferences.isDeferredDmEnabled()) { session.roomService().createLocalRoom(roomParams) } else { analyticsTracker.capture(CreatedRoom(isDM = roomParams.isDirect.orFalse())) diff --git a/vector/src/main/java/im/vector/app/features/createdirect/DirectRoomHelper.kt b/vector/src/main/java/im/vector/app/features/createdirect/DirectRoomHelper.kt index c2cc13920f..466aca1176 100644 --- a/vector/src/main/java/im/vector/app/features/createdirect/DirectRoomHelper.kt +++ b/vector/src/main/java/im/vector/app/features/createdirect/DirectRoomHelper.kt @@ -16,11 +16,11 @@ package im.vector.app.features.createdirect -import im.vector.app.features.VectorFeatures import im.vector.app.features.analytics.AnalyticsTracker import im.vector.app.features.analytics.plan.CreatedRoom import im.vector.app.features.raw.wellknown.getElementWellknown import im.vector.app.features.raw.wellknown.isE2EByDefault +import im.vector.app.features.settings.VectorPreferences import org.matrix.android.sdk.api.extensions.orFalse import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.raw.RawService @@ -32,7 +32,7 @@ class DirectRoomHelper @Inject constructor( private val rawService: RawService, private val session: Session, private val analyticsTracker: AnalyticsTracker, - private val vectorFeatures: VectorFeatures, + private val vectorPreferences: VectorPreferences, ) { suspend fun ensureDMExists(userId: String): String { @@ -50,7 +50,7 @@ class DirectRoomHelper @Inject constructor( setDirectMessage() enableEncryptionIfInvitedUsersSupportIt = adminE2EByDefault } - roomId = if (vectorFeatures.shouldStartDmOnFirstMessage()) { + roomId = if (vectorPreferences.isDeferredDmEnabled()) { session.roomService().createLocalRoom(roomParams) } else { analyticsTracker.capture(CreatedRoom(isDM = roomParams.isDirect.orFalse())) diff --git a/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt b/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt index fca931eaef..4da6455f74 100755 --- a/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt +++ b/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt @@ -66,6 +66,7 @@ class VectorPreferences @Inject constructor( const val SETTINGS_BACKGROUND_SYNC_DIVIDER_PREFERENCE_KEY = "SETTINGS_BACKGROUND_SYNC_DIVIDER_PREFERENCE_KEY" const val SETTINGS_LABS_PREFERENCE_KEY = "SETTINGS_LABS_PREFERENCE_KEY" const val SETTINGS_LABS_NEW_APP_LAYOUT_KEY = "SETTINGS_LABS_NEW_APP_LAYOUT_KEY" + const val SETTINGS_LABS_DEFERRED_DM_KEY = "SETTINGS_LABS_DEFERRED_DM_KEY" const val SETTINGS_CRYPTOGRAPHY_PREFERENCE_KEY = "SETTINGS_CRYPTOGRAPHY_PREFERENCE_KEY" const val SETTINGS_CRYPTOGRAPHY_DIVIDER_PREFERENCE_KEY = "SETTINGS_CRYPTOGRAPHY_DIVIDER_PREFERENCE_KEY" const val SETTINGS_CRYPTOGRAPHY_MANAGE_PREFERENCE_KEY = "SETTINGS_CRYPTOGRAPHY_MANAGE_PREFERENCE_KEY" @@ -1162,6 +1163,13 @@ class VectorPreferences @Inject constructor( defaultPrefs.getBoolean(SETTINGS_LABS_NEW_APP_LAYOUT_KEY, getDefault(R.bool.settings_labs_new_app_layout_default)) } + /** + * Indicates whether or not deferred DMs are enabled. + */ + fun isDeferredDmEnabled(): Boolean { + return defaultPrefs.getBoolean(SETTINGS_LABS_DEFERRED_DM_KEY, getDefault(R.bool.settings_labs_deferred_dm_default)) + } + fun showLiveSenderInfo(): Boolean { return defaultPrefs.getBoolean(SETTINGS_TIMELINE_SHOW_LIVE_SENDER_INFO, getDefault(R.bool.settings_timeline_show_live_sender_info_default)) } diff --git a/vector/src/main/res/xml/vector_settings_labs.xml b/vector/src/main/res/xml/vector_settings_labs.xml index f61d5fe7bc..8baeaad3c6 100644 --- a/vector/src/main/res/xml/vector_settings_labs.xml +++ b/vector/src/main/res/xml/vector_settings_labs.xml @@ -89,4 +89,10 @@ android:summary="@string/labs_enable_new_app_layout_summary" android:title="@string/labs_enable_new_app_layout_title" /> + + From 3786bd9c65f6dc473393e556fc55a4f68ad2a863 Mon Sep 17 00:00:00 2001 From: Florian Renaud Date: Tue, 20 Sep 2022 10:02:33 +0200 Subject: [PATCH 2/5] changelog --- changelog.d/7180.feature | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/7180.feature diff --git a/changelog.d/7180.feature b/changelog.d/7180.feature new file mode 100644 index 0000000000..bdfe090ceb --- /dev/null +++ b/changelog.d/7180.feature @@ -0,0 +1 @@ +Deferred DMs - Enable and move the feature to labs settings From dd92bb756a3c331fe6d0af12ed8e66fb00a9b9fc Mon Sep 17 00:00:00 2001 From: Florian Renaud Date: Wed, 21 Sep 2022 09:27:37 +0200 Subject: [PATCH 3/5] Add visibility setting field for lab setting --- vector-config/src/main/res/values/config-settings.xml | 1 + vector/src/main/res/xml/vector_settings_labs.xml | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/vector-config/src/main/res/values/config-settings.xml b/vector-config/src/main/res/values/config-settings.xml index 3342b1da14..c69452e3d0 100755 --- a/vector-config/src/main/res/values/config-settings.xml +++ b/vector-config/src/main/res/values/config-settings.xml @@ -37,6 +37,7 @@ true + true true false true diff --git a/vector/src/main/res/xml/vector_settings_labs.xml b/vector/src/main/res/xml/vector_settings_labs.xml index 8baeaad3c6..9fac6d722a 100644 --- a/vector/src/main/res/xml/vector_settings_labs.xml +++ b/vector/src/main/res/xml/vector_settings_labs.xml @@ -47,8 +47,8 @@ @@ -93,6 +93,7 @@ android:defaultValue="@bool/settings_labs_deferred_dm_default" android:key="SETTINGS_LABS_DEFERRED_DM_KEY" android:summary="@string/labs_enable_deferred_dm_summary" - android:title="@string/labs_enable_deferred_dm_title" /> + android:title="@string/labs_enable_deferred_dm_title" + app:isPreferenceVisible="@bool/settings_labs_deferred_dm_visible" /> From fa8b56b1ad0790f73a09661203a2f78b21a8d72d Mon Sep 17 00:00:00 2001 From: Florian Renaud Date: Wed, 21 Sep 2022 09:35:26 +0200 Subject: [PATCH 4/5] Restore tracking for deferred DMs --- .../app/features/home/room/detail/TimelineViewModel.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineViewModel.kt index a6513ffc4f..02dd2604e1 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineViewModel.kt @@ -39,6 +39,7 @@ import im.vector.app.core.utils.BehaviorDataSource import im.vector.app.features.analytics.AnalyticsTracker import im.vector.app.features.analytics.DecryptionFailureTracker import im.vector.app.features.analytics.extensions.toAnalyticsJoinedRoom +import im.vector.app.features.analytics.plan.CreatedRoom import im.vector.app.features.analytics.plan.JoinedRoom import im.vector.app.features.call.conference.ConferenceEvent import im.vector.app.features.call.conference.JitsiActiveConferenceHolder @@ -78,6 +79,7 @@ import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import org.matrix.android.sdk.api.MatrixPatterns +import org.matrix.android.sdk.api.extensions.orFalse import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.query.QueryStringValue import org.matrix.android.sdk.api.raw.RawService @@ -1247,8 +1249,12 @@ class TimelineViewModel @AssistedInject constructor( LocalRoomCreationState.FAILURE -> { _viewEvents.post(RoomDetailViewEvents.HideWaitingView) } - LocalRoomCreationState.CREATED -> - _viewEvents.post(RoomDetailViewEvents.OpenRoom(room.localRoomSummary()?.replacementRoomId!!, true)) + LocalRoomCreationState.CREATED -> { + room.localRoomSummary()?.let { + analyticsTracker.capture(CreatedRoom(isDM = it.roomSummary?.isDirect.orFalse())) + _viewEvents.post(RoomDetailViewEvents.OpenRoom(it.replacementRoomId!!, true)) + } + } } } .launchIn(viewModelScope) From c252f6eb70f89559e057b61b8a79a5bb86640a6f Mon Sep 17 00:00:00 2001 From: Florian Renaud Date: Wed, 21 Sep 2022 09:50:05 +0200 Subject: [PATCH 5/5] Update lab setting wording following design review --- library/ui-strings/src/main/res/values/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/ui-strings/src/main/res/values/strings.xml b/library/ui-strings/src/main/res/values/strings.xml index 99ff55a93d..0364cc4565 100644 --- a/library/ui-strings/src/main/res/values/strings.xml +++ b/library/ui-strings/src/main/res/values/strings.xml @@ -443,7 +443,7 @@ A simplified Element with optional tabs Enable deferred DMs - Direct rooms will be created after sending a first message. + Create DM only on first message Invites