From ca1c2ae4a41ad710c18bd243b0754779450dc652 Mon Sep 17 00:00:00 2001 From: ganfra Date: Wed, 9 Apr 2025 21:30:54 +0200 Subject: [PATCH] change (preferences) : bind timeline media preview settings --- .../protection/TimelineProtectionPresenter.kt | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/protection/TimelineProtectionPresenter.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/protection/TimelineProtectionPresenter.kt index ad486bd2c5..d9c68403f4 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/protection/TimelineProtectionPresenter.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/protection/TimelineProtectionPresenter.kt @@ -17,23 +17,38 @@ import androidx.compose.runtime.setValue import io.element.android.libraries.architecture.Presenter import io.element.android.libraries.matrix.api.core.EventId import io.element.android.libraries.matrix.api.media.MediaPreviewValue +import io.element.android.libraries.matrix.api.room.MatrixRoom import io.element.android.libraries.preferences.api.store.AppPreferencesStore import kotlinx.collections.immutable.toImmutableSet import javax.inject.Inject class TimelineProtectionPresenter @Inject constructor( private val appPreferencesStore: AppPreferencesStore, + private val room: MatrixRoom, ) : Presenter { @Composable override fun present(): TimelineProtectionState { - val mediaPreviewValue = appPreferencesStore.getTimelineMediaPreviewValueFlow().collectAsState(initial = MediaPreviewValue.Off) + val mediaPreviewValue = remember { + appPreferencesStore.getTimelineMediaPreviewValueFlow() + }.collectAsState(initial = MediaPreviewValue.Off) var allowedEvents by remember { mutableStateOf>(setOf()) } + val roomInfo = room.roomInfoFlow.collectAsState() val protectionState by remember { derivedStateOf { - if (mediaPreviewValue.value == MediaPreviewValue.On) { - ProtectionState.RenderAll - } else { - ProtectionState.RenderOnly(eventIds = allowedEvents.toImmutableSet()) + when (mediaPreviewValue.value) { + MediaPreviewValue.On -> { + ProtectionState.RenderAll + } + MediaPreviewValue.Off -> { + ProtectionState.RenderOnly(eventIds = allowedEvents.toImmutableSet()) + } + MediaPreviewValue.Private -> { + if (roomInfo.value.isPublic) { + ProtectionState.RenderOnly(eventIds = allowedEvents.toImmutableSet()) + } else { + ProtectionState.RenderAll + } + } } } }