Start DM - Add feature flag

This commit is contained in:
Florian Renaud 2022-05-11 16:19:33 +02:00
parent 3dcec85dea
commit c9ab0927f0
4 changed files with 20 additions and 2 deletions

View File

@ -70,6 +70,11 @@ class DebugFeaturesStateFactory @Inject constructor(
key = DebugFeatureKeys.allowExternalUnifiedPushDistributors, key = DebugFeatureKeys.allowExternalUnifiedPushDistributors,
factory = VectorFeatures::allowExternalUnifiedPushDistributors factory = VectorFeatures::allowExternalUnifiedPushDistributors
), ),
createBooleanFeature(
label = "Start DM on first message",
key = DebugFeatureKeys.startDmOnFirstMsg,
factory = VectorFeatures::shouldStartDmOnFirstMessage
),
) )
) )
} }

View File

@ -66,6 +66,9 @@ class DebugVectorFeatures(
override fun isScreenSharingEnabled(): Boolean = read(DebugFeatureKeys.screenSharing) override fun isScreenSharingEnabled(): Boolean = read(DebugFeatureKeys.screenSharing)
?: vectorFeatures.isScreenSharingEnabled() ?: vectorFeatures.isScreenSharingEnabled()
override fun shouldStartDmOnFirstMessage(): Boolean = read(DebugFeatureKeys.startDmOnFirstMsg)
?: vectorFeatures.shouldStartDmOnFirstMessage()
fun <T> override(value: T?, key: Preferences.Key<T>) = updatePreferences { fun <T> override(value: T?, key: Preferences.Key<T>) = updatePreferences {
if (value == null) { if (value == null) {
it.remove(key) it.remove(key)
@ -123,4 +126,5 @@ object DebugFeatureKeys {
val allowExternalUnifiedPushDistributors = booleanPreferencesKey("allow-external-unified-push-distributors") val allowExternalUnifiedPushDistributors = booleanPreferencesKey("allow-external-unified-push-distributors")
val liveLocationSharing = booleanPreferencesKey("live-location-sharing") val liveLocationSharing = booleanPreferencesKey("live-location-sharing")
val screenSharing = booleanPreferencesKey("screen-sharing") val screenSharing = booleanPreferencesKey("screen-sharing")
val startDmOnFirstMsg = booleanPreferencesKey("start-dm-on-first-msg")
} }

View File

@ -30,6 +30,7 @@ interface VectorFeatures {
fun isOnboardingCombinedLoginEnabled(): Boolean fun isOnboardingCombinedLoginEnabled(): Boolean
fun allowExternalUnifiedPushDistributors(): Boolean fun allowExternalUnifiedPushDistributors(): Boolean
fun isScreenSharingEnabled(): Boolean fun isScreenSharingEnabled(): Boolean
fun shouldStartDmOnFirstMessage(): Boolean
enum class OnboardingVariant { enum class OnboardingVariant {
LEGACY, LEGACY,
@ -48,4 +49,5 @@ class DefaultVectorFeatures : VectorFeatures {
override fun isOnboardingCombinedLoginEnabled() = false override fun isOnboardingCombinedLoginEnabled() = false
override fun allowExternalUnifiedPushDistributors(): Boolean = Config.ALLOW_EXTERNAL_UNIFIED_PUSH_DISTRIBUTORS override fun allowExternalUnifiedPushDistributors(): Boolean = Config.ALLOW_EXTERNAL_UNIFIED_PUSH_DISTRIBUTORS
override fun isScreenSharingEnabled(): Boolean = true override fun isScreenSharingEnabled(): Boolean = true
override fun shouldStartDmOnFirstMessage(): Boolean = false
} }

View File

@ -26,6 +26,7 @@ import im.vector.app.core.di.MavericksAssistedViewModelFactory
import im.vector.app.core.di.hiltMavericksViewModelFactory import im.vector.app.core.di.hiltMavericksViewModelFactory
import im.vector.app.core.mvrx.runCatchingToAsync import im.vector.app.core.mvrx.runCatchingToAsync
import im.vector.app.core.platform.VectorViewModel 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.AnalyticsTracker
import im.vector.app.features.analytics.plan.CreatedRoom import im.vector.app.features.analytics.plan.CreatedRoom
import im.vector.app.features.raw.wellknown.getElementWellknown import im.vector.app.features.raw.wellknown.getElementWellknown
@ -46,7 +47,8 @@ class CreateDirectRoomViewModel @AssistedInject constructor(
@Assisted initialState: CreateDirectRoomViewState, @Assisted initialState: CreateDirectRoomViewState,
private val rawService: RawService, private val rawService: RawService,
val session: Session, val session: Session,
val analyticsTracker: AnalyticsTracker val analyticsTracker: AnalyticsTracker,
val vectorFeatures: VectorFeatures
) : ) :
VectorViewModel<CreateDirectRoomViewState, CreateDirectRoomAction, CreateDirectRoomViewEvents>(initialState) { VectorViewModel<CreateDirectRoomViewState, CreateDirectRoomAction, CreateDirectRoomViewEvents>(initialState) {
@ -124,7 +126,12 @@ class CreateDirectRoomViewModel @AssistedInject constructor(
} }
val result = runCatchingToAsync { val result = runCatchingToAsync {
session.roomService().createRoom(roomParams) if (vectorFeatures.shouldStartDmOnFirstMessage()) {
// Todo: Prepare direct room creation
throw Throwable("Start DM on first message is not implemented yet.")
} else {
session.roomService().createRoom(roomParams)
}
} }
analyticsTracker.capture(CreatedRoom(isDM = roomParams.isDirect.orFalse())) analyticsTracker.capture(CreatedRoom(isDM = roomParams.isDirect.orFalse()))