change (preferences) : bind timeline media preview settings

This commit is contained in:
ganfra 2025-04-09 21:30:54 +02:00
parent e231ef7a0e
commit b9eb4c49b7

View file

@ -17,23 +17,38 @@ import androidx.compose.runtime.setValue
import io.element.android.libraries.architecture.Presenter import io.element.android.libraries.architecture.Presenter
import io.element.android.libraries.matrix.api.core.EventId 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.media.MediaPreviewValue
import io.element.android.libraries.matrix.api.room.MatrixRoom
import io.element.android.libraries.preferences.api.store.AppPreferencesStore import io.element.android.libraries.preferences.api.store.AppPreferencesStore
import kotlinx.collections.immutable.toImmutableSet import kotlinx.collections.immutable.toImmutableSet
import javax.inject.Inject import javax.inject.Inject
class TimelineProtectionPresenter @Inject constructor( class TimelineProtectionPresenter @Inject constructor(
private val appPreferencesStore: AppPreferencesStore, private val appPreferencesStore: AppPreferencesStore,
private val room: MatrixRoom,
) : Presenter<TimelineProtectionState> { ) : Presenter<TimelineProtectionState> {
@Composable @Composable
override fun present(): TimelineProtectionState { 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<Set<EventId>>(setOf()) } var allowedEvents by remember { mutableStateOf<Set<EventId>>(setOf()) }
val roomInfo = room.roomInfoFlow.collectAsState()
val protectionState by remember { val protectionState by remember {
derivedStateOf { derivedStateOf {
if (mediaPreviewValue.value == MediaPreviewValue.On) { when (mediaPreviewValue.value) {
ProtectionState.RenderAll MediaPreviewValue.On -> {
} else { ProtectionState.RenderAll
ProtectionState.RenderOnly(eventIds = allowedEvents.toImmutableSet()) }
MediaPreviewValue.Off -> {
ProtectionState.RenderOnly(eventIds = allowedEvents.toImmutableSet())
}
MediaPreviewValue.Private -> {
if (roomInfo.value.isPublic) {
ProtectionState.RenderOnly(eventIds = allowedEvents.toImmutableSet())
} else {
ProtectionState.RenderAll
}
}
} }
} }
} }