Fix edition

This commit is contained in:
yostyle 2023-08-01 15:20:20 +02:00
parent bfb6bd9d08
commit 6895f8bcae
4 changed files with 14 additions and 34 deletions

View file

@ -20,5 +20,5 @@ import io.element.android.libraries.matrix.api.room.RoomNotificationMode
sealed interface RoomNotificationSettingsEvents { sealed interface RoomNotificationSettingsEvents {
data class RoomNotificationModeChanged(val mode: RoomNotificationMode) : RoomNotificationSettingsEvents data class RoomNotificationModeChanged(val mode: RoomNotificationMode) : RoomNotificationSettingsEvents
object DefaultNotificationModeSelected: RoomNotificationSettingsEvents data class SetNotificationMode(val isDefault: Boolean): RoomNotificationSettingsEvents
} }

View file

@ -30,12 +30,9 @@ import io.element.android.libraries.matrix.api.room.MatrixRoom
import io.element.android.libraries.matrix.api.room.RoomNotificationMode import io.element.android.libraries.matrix.api.room.RoomNotificationMode
import io.element.android.libraries.matrix.api.room.roomNotificationSettings import io.element.android.libraries.matrix.api.room.roomNotificationSettings
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.buffer
import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
class RoomNotificationSettingsPresenter @Inject constructor( class RoomNotificationSettingsPresenter @Inject constructor(
@ -62,8 +59,14 @@ class RoomNotificationSettingsPresenter @Inject constructor(
is RoomNotificationSettingsEvents.RoomNotificationModeChanged -> { is RoomNotificationSettingsEvents.RoomNotificationModeChanged -> {
localCoroutineScope.setRoomNotificationMode(event.mode) localCoroutineScope.setRoomNotificationMode(event.mode)
} }
RoomNotificationSettingsEvents.DefaultNotificationModeSelected -> { is RoomNotificationSettingsEvents.SetNotificationMode -> {
localCoroutineScope.restoreDefaultRoomNotificationMode() if (event.isDefault) {
localCoroutineScope.restoreDefaultRoomNotificationMode()
} else {
defaultRoomNotificationMode.value?.let {
localCoroutineScope.setRoomNotificationMode(it)
}
}
} }
} }
} }
@ -76,9 +79,8 @@ class RoomNotificationSettingsPresenter @Inject constructor(
} }
private fun CoroutineScope.observeNotificationSettings() { private fun CoroutineScope.observeNotificationSettings() {
notificationSettingsService.notificationSettingsChangeFlow.buffer(Channel.UNLIMITED).onEach { notificationSettingsService.notificationSettingsChangeFlow.onEach {
//room.updateRoomNotificationSettings() room.updateRoomNotificationSettings()
Timber.d("emit is called")
}.launchIn(this) }.launchIn(this)
} }

View file

@ -66,13 +66,6 @@ fun RoomNotificationSettingsView(
.consumeWindowInsets(padding), .consumeWindowInsets(padding),
verticalArrangement = Arrangement.spacedBy(16.dp), verticalArrangement = Arrangement.spacedBy(16.dp),
) { ) {
// PreferenceSwitch(
// isChecked = state.formState.sendLogs,
// onCheckedChange = { eventSink(BugReportEvents.SetSendLog(it)) },
// enabled = isFormEnabled,
// title = stringResource(id = R.string.screen_bug_report_include_logs),
// subtitle = stringResource(id = R.string.screen_bug_report_logs_description),
// )
val subtitle = when(state.defaultRoomNotificationMode) { val subtitle = when(state.defaultRoomNotificationMode) {
RoomNotificationMode.ALL_MESSAGES -> "All messages" RoomNotificationMode.ALL_MESSAGES -> "All messages"
RoomNotificationMode.MENTIONS_AND_KEYWORDS_ONLY -> "Mentions and keywords" RoomNotificationMode.MENTIONS_AND_KEYWORDS_ONLY -> "Mentions and keywords"
@ -85,7 +78,7 @@ fun RoomNotificationSettingsView(
PreferenceSwitch( PreferenceSwitch(
isChecked = state.roomNotificationSettings?.isDefault.orTrue(), isChecked = state.roomNotificationSettings?.isDefault.orTrue(),
onCheckedChange = { onCheckedChange = {
state.eventSink(RoomNotificationSettingsEvents.DefaultNotificationModeSelected) state.eventSink(RoomNotificationSettingsEvents.SetNotificationMode(it))
}, },
title = "Match default setting", title = "Match default setting",
subtitle = subtitle, subtitle = subtitle,

View file

@ -35,30 +35,15 @@ class RustNotificationSettingsService(
private val notificationSettings: NotificationSettings = client.getNotificationSettings() private val notificationSettings: NotificationSettings = client.getNotificationSettings()
private val _notificationSettingsChangeFlow = MutableSharedFlow<Unit>(onBufferOverflow = BufferOverflow.DROP_OLDEST) private val _notificationSettingsChangeFlow = MutableSharedFlow<Unit>(extraBufferCapacity = 1, onBufferOverflow = BufferOverflow.DROP_OLDEST)
override val notificationSettingsChangeFlow: SharedFlow<Unit> = _notificationSettingsChangeFlow.asSharedFlow() override val notificationSettingsChangeFlow: SharedFlow<Unit> = _notificationSettingsChangeFlow.asSharedFlow()
private var notificationSettingsDelegate = object : NotificationSettingsDelegate { private var notificationSettingsDelegate = object : NotificationSettingsDelegate {
override fun settingsDidChange() { override fun settingsDidChange() {
Timber.d("emit ${_notificationSettingsChangeFlow.subscriptionCount.value}") _notificationSettingsChangeFlow.tryEmit(Unit)
val ok = _notificationSettingsChangeFlow.tryEmit(Unit)
Timber.d("emit $ok")
} }
} }
// override val notificationSettingsChangeFlow = callbackFlow {
// val delegate = object:NotificationSettingsDelegate {
// override fun notificationSettingsDidChange() {
// trySendBlocking(Unit)
// }
// }
// send(Unit)
// notificationSettings.setDelegate(delegate)
// awaitClose {
// // notificationSettings.setDelegate(null)
// }
// }.buffer(Channel.UNLIMITED)
init { init {
notificationSettings.setDelegate(notificationSettingsDelegate) notificationSettings.setDelegate(notificationSettingsDelegate)
} }