diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/actionlist/ActionListPresenter.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/actionlist/ActionListPresenter.kt index e228f3eb736..f2b97769c03 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/actionlist/ActionListPresenter.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/actionlist/ActionListPresenter.kt @@ -37,6 +37,8 @@ import io.element.android.features.messages.impl.timeline.model.event.canBeForwa import io.element.android.features.messages.impl.timeline.model.event.canReact import io.element.android.libraries.architecture.Presenter import io.element.android.libraries.di.RoomScope +import io.element.android.libraries.featureflag.api.FeatureFlagService +import io.element.android.libraries.featureflag.api.FeatureFlags import io.element.android.libraries.matrix.api.core.EventId import io.element.android.libraries.matrix.api.room.MatrixRoom import io.element.android.libraries.preferences.api.store.AppPreferencesStore @@ -60,6 +62,7 @@ class DefaultActionListPresenter @AssistedInject constructor( private val isPinnedMessagesFeatureEnabled: IsPinnedMessagesFeatureEnabled, private val room: MatrixRoom, private val userSendFailureFactory: VerifiedUserSendFailureFactory, + private val featureFlagService: FeatureFlagService, ) : ActionListPresenter { @AssistedFactory @ContributesBinding(RoomScope::class) @@ -134,7 +137,7 @@ class DefaultActionListPresenter @AssistedInject constructor( } } - private fun buildActions( + private suspend fun buildActions( timelineItem: TimelineItem.Event, usersEventPermissions: UserEventPermissions, isDeveloperModeEnabled: Boolean, @@ -157,7 +160,9 @@ class DefaultActionListPresenter @AssistedInject constructor( if (timelineItem.content is TimelineItemEventContentWithAttachment) { // Caption if (timelineItem.content.caption == null) { - add(TimelineItemAction.AddCaption) + if (featureFlagService.isFeatureEnabled(FeatureFlags.MediaCaptionCreation)) { + add(TimelineItemAction.AddCaption) + } } else { add(TimelineItemAction.EditCaption) add(TimelineItemAction.RemoveCaption) diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/attachments/preview/AttachmentsPreviewPresenter.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/attachments/preview/AttachmentsPreviewPresenter.kt index 69d28d8f202..606e91863d3 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/attachments/preview/AttachmentsPreviewPresenter.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/attachments/preview/AttachmentsPreviewPresenter.kt @@ -10,6 +10,7 @@ package io.element.android.features.messages.impl.attachments.preview import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.MutableState +import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember @@ -46,7 +47,7 @@ class AttachmentsPreviewPresenter @AssistedInject constructor( private val mediaSender: MediaSender, private val permalinkBuilder: PermalinkBuilder, private val temporaryUriDeleter: TemporaryUriDeleter, - private val featureFlagsService: FeatureFlagService, + private val featureFlagService: FeatureFlagService, ) : Presenter { @AssistedFactory interface Factory { @@ -72,6 +73,7 @@ class AttachmentsPreviewPresenter @AssistedInject constructor( val ongoingSendAttachmentJob = remember { mutableStateOf(null) } val userSentAttachment = remember { mutableStateOf(false) } + val allowCaption by featureFlagService.isFeatureEnabledFlow(FeatureFlags.MediaCaptionCreation).collectAsState(initial = false) val mediaUploadInfoState = remember { mutableStateOf>(AsyncData.Uninitialized) } LaunchedEffect(Unit) { @@ -112,7 +114,7 @@ class AttachmentsPreviewPresenter @AssistedInject constructor( fun handleEvents(attachmentsPreviewEvents: AttachmentsPreviewEvents) { when (attachmentsPreviewEvents) { is AttachmentsPreviewEvents.SendAttachment -> coroutineScope.launch { - val useSendQueue = featureFlagsService.isFeatureEnabled(FeatureFlags.MediaUploadOnSendQueue) + val useSendQueue = featureFlagService.isFeatureEnabled(FeatureFlags.MediaUploadOnSendQueue) userSentAttachment.value = true val instantSending = mediaUploadInfoState.value.isReady() && useSendQueue sendActionState.value = if (instantSending) { @@ -142,6 +144,7 @@ class AttachmentsPreviewPresenter @AssistedInject constructor( attachment = attachment, sendActionState = sendActionState.value, textEditorState = textEditorState, + allowCaption = allowCaption, eventSink = ::handleEvents ) } diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/attachments/preview/AttachmentsPreviewState.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/attachments/preview/AttachmentsPreviewState.kt index 0e9724c4606..0878b52f803 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/attachments/preview/AttachmentsPreviewState.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/attachments/preview/AttachmentsPreviewState.kt @@ -15,11 +15,9 @@ data class AttachmentsPreviewState( val attachment: Attachment, val sendActionState: SendActionState, val textEditorState: TextEditorState, + val allowCaption: Boolean, val eventSink: (AttachmentsPreviewEvents) -> Unit -) { - // Keep the val to eventually set to false for some mimetypes. - val allowCaption: Boolean = true -} +) @Immutable sealed interface SendActionState { diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/attachments/preview/AttachmentsPreviewStateProvider.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/attachments/preview/AttachmentsPreviewStateProvider.kt index 1c55245e469..f7e215fa222 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/attachments/preview/AttachmentsPreviewStateProvider.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/attachments/preview/AttachmentsPreviewStateProvider.kt @@ -29,6 +29,7 @@ open class AttachmentsPreviewStateProvider : PreviewParameterProvider> { _, _, _, _, _ -> @@ -420,6 +442,7 @@ class AttachmentsPreviewPresenterTest { temporaryUriDeleter: TemporaryUriDeleter = FakeTemporaryUriDeleter(), onDoneListener: OnDoneListener = OnDoneListener { lambdaError() }, mediaUploadOnSendQueueEnabled: Boolean = true, + allowCaption: Boolean = true, ): AttachmentsPreviewPresenter { return AttachmentsPreviewPresenter( attachment = aMediaAttachment(localMedia), @@ -427,8 +450,11 @@ class AttachmentsPreviewPresenterTest { mediaSender = MediaSender(mediaPreProcessor, room, InMemorySessionPreferencesStore()), permalinkBuilder = permalinkBuilder, temporaryUriDeleter = temporaryUriDeleter, - featureFlagsService = FakeFeatureFlagService( - initialState = mapOf(FeatureFlags.MediaUploadOnSendQueue.key to mediaUploadOnSendQueueEnabled), + featureFlagService = FakeFeatureFlagService( + initialState = mapOf( + FeatureFlags.MediaUploadOnSendQueue.key to mediaUploadOnSendQueueEnabled, + FeatureFlags.MediaCaptionCreation.key to allowCaption, + ), ) ) } 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 490c12ebe0d..42d9f309207 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 @@ -140,4 +140,11 @@ enum class FeatureFlags( defaultValue = { buildMeta -> buildMeta.buildType != BuildType.RELEASE }, isFinished = false, ), + MediaCaptionCreation( + key = "feature.media_caption_creation", + title = "Allow creation of media captions", + description = null, + defaultValue = { buildMeta -> buildMeta.buildType != BuildType.RELEASE }, + isFinished = false, + ), } diff --git a/tests/uitests/src/test/snapshots/images/features.messages.impl.attachments.preview_AttachmentsView_7_en.png b/tests/uitests/src/test/snapshots/images/features.messages.impl.attachments.preview_AttachmentsView_7_en.png new file mode 100644 index 00000000000..6920a089ef4 --- /dev/null +++ b/tests/uitests/src/test/snapshots/images/features.messages.impl.attachments.preview_AttachmentsView_7_en.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:507c7dffae1aabfa687174f1f964e2c40b004183b6bc3a70b56d764e0d308b47 +size 392923