Skip to content

Commit ca1c2ae

Browse files
committed
change (preferences) : bind timeline media preview settings
1 parent 58fc1f9 commit ca1c2ae

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/protection/TimelineProtectionPresenter.kt

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,38 @@ import androidx.compose.runtime.setValue
1717
import io.element.android.libraries.architecture.Presenter
1818
import io.element.android.libraries.matrix.api.core.EventId
1919
import io.element.android.libraries.matrix.api.media.MediaPreviewValue
20+
import io.element.android.libraries.matrix.api.room.MatrixRoom
2021
import io.element.android.libraries.preferences.api.store.AppPreferencesStore
2122
import kotlinx.collections.immutable.toImmutableSet
2223
import javax.inject.Inject
2324

2425
class TimelineProtectionPresenter @Inject constructor(
2526
private val appPreferencesStore: AppPreferencesStore,
27+
private val room: MatrixRoom,
2628
) : Presenter<TimelineProtectionState> {
2729
@Composable
2830
override fun present(): TimelineProtectionState {
29-
val mediaPreviewValue = appPreferencesStore.getTimelineMediaPreviewValueFlow().collectAsState(initial = MediaPreviewValue.Off)
31+
val mediaPreviewValue = remember {
32+
appPreferencesStore.getTimelineMediaPreviewValueFlow()
33+
}.collectAsState(initial = MediaPreviewValue.Off)
3034
var allowedEvents by remember { mutableStateOf<Set<EventId>>(setOf()) }
35+
val roomInfo = room.roomInfoFlow.collectAsState()
3136
val protectionState by remember {
3237
derivedStateOf {
33-
if (mediaPreviewValue.value == MediaPreviewValue.On) {
34-
ProtectionState.RenderAll
35-
} else {
36-
ProtectionState.RenderOnly(eventIds = allowedEvents.toImmutableSet())
38+
when (mediaPreviewValue.value) {
39+
MediaPreviewValue.On -> {
40+
ProtectionState.RenderAll
41+
}
42+
MediaPreviewValue.Off -> {
43+
ProtectionState.RenderOnly(eventIds = allowedEvents.toImmutableSet())
44+
}
45+
MediaPreviewValue.Private -> {
46+
if (roomInfo.value.isPublic) {
47+
ProtectionState.RenderOnly(eventIds = allowedEvents.toImmutableSet())
48+
} else {
49+
ProtectionState.RenderAll
50+
}
51+
}
3752
}
3853
}
3954
}

0 commit comments

Comments
 (0)