diff --git a/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/notificationsettings/RoomNotificationSettingsEvents.kt b/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/notificationsettings/RoomNotificationSettingsEvents.kt index 4b511a5be0..bbe756b154 100644 --- a/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/notificationsettings/RoomNotificationSettingsEvents.kt +++ b/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/notificationsettings/RoomNotificationSettingsEvents.kt @@ -20,5 +20,5 @@ import io.element.android.libraries.matrix.api.room.RoomNotificationMode sealed interface RoomNotificationSettingsEvents { data class RoomNotificationModeChanged(val mode: RoomNotificationMode) : RoomNotificationSettingsEvents - object DefaultNotificationModeSelected: RoomNotificationSettingsEvents + data class SetNotificationMode(val isDefault: Boolean): RoomNotificationSettingsEvents } diff --git a/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/notificationsettings/RoomNotificationSettingsPresenter.kt b/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/notificationsettings/RoomNotificationSettingsPresenter.kt index c2528ca6d5..0b9442fd47 100644 --- a/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/notificationsettings/RoomNotificationSettingsPresenter.kt +++ b/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/notificationsettings/RoomNotificationSettingsPresenter.kt @@ -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.roomNotificationSettings import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.channels.Channel -import kotlinx.coroutines.flow.buffer import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch -import timber.log.Timber import javax.inject.Inject class RoomNotificationSettingsPresenter @Inject constructor( @@ -62,8 +59,14 @@ class RoomNotificationSettingsPresenter @Inject constructor( is RoomNotificationSettingsEvents.RoomNotificationModeChanged -> { localCoroutineScope.setRoomNotificationMode(event.mode) } - RoomNotificationSettingsEvents.DefaultNotificationModeSelected -> { - localCoroutineScope.restoreDefaultRoomNotificationMode() + is RoomNotificationSettingsEvents.SetNotificationMode -> { + if (event.isDefault) { + localCoroutineScope.restoreDefaultRoomNotificationMode() + } else { + defaultRoomNotificationMode.value?.let { + localCoroutineScope.setRoomNotificationMode(it) + } + } } } } @@ -76,9 +79,8 @@ class RoomNotificationSettingsPresenter @Inject constructor( } private fun CoroutineScope.observeNotificationSettings() { - notificationSettingsService.notificationSettingsChangeFlow.buffer(Channel.UNLIMITED).onEach { - //room.updateRoomNotificationSettings() - Timber.d("emit is called") + notificationSettingsService.notificationSettingsChangeFlow.onEach { + room.updateRoomNotificationSettings() }.launchIn(this) } diff --git a/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/notificationsettings/RoomNotificationSettingsView.kt b/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/notificationsettings/RoomNotificationSettingsView.kt index 7c9bf11fc6..6452b412a0 100644 --- a/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/notificationsettings/RoomNotificationSettingsView.kt +++ b/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/notificationsettings/RoomNotificationSettingsView.kt @@ -66,13 +66,6 @@ fun RoomNotificationSettingsView( .consumeWindowInsets(padding), 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) { RoomNotificationMode.ALL_MESSAGES -> "All messages" RoomNotificationMode.MENTIONS_AND_KEYWORDS_ONLY -> "Mentions and keywords" @@ -85,7 +78,7 @@ fun RoomNotificationSettingsView( PreferenceSwitch( isChecked = state.roomNotificationSettings?.isDefault.orTrue(), onCheckedChange = { - state.eventSink(RoomNotificationSettingsEvents.DefaultNotificationModeSelected) + state.eventSink(RoomNotificationSettingsEvents.SetNotificationMode(it)) }, title = "Match default setting", subtitle = subtitle, diff --git a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/notificationsettings/RustNotificationSettingsService.kt b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/notificationsettings/RustNotificationSettingsService.kt index e8342952a9..dc2fb33372 100644 --- a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/notificationsettings/RustNotificationSettingsService.kt +++ b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/notificationsettings/RustNotificationSettingsService.kt @@ -35,30 +35,15 @@ class RustNotificationSettingsService( private val notificationSettings: NotificationSettings = client.getNotificationSettings() - private val _notificationSettingsChangeFlow = MutableSharedFlow(onBufferOverflow = BufferOverflow.DROP_OLDEST) + private val _notificationSettingsChangeFlow = MutableSharedFlow(extraBufferCapacity = 1, onBufferOverflow = BufferOverflow.DROP_OLDEST) override val notificationSettingsChangeFlow: SharedFlow = _notificationSettingsChangeFlow.asSharedFlow() private var notificationSettingsDelegate = object : NotificationSettingsDelegate { override fun settingsDidChange() { - Timber.d("emit ${_notificationSettingsChangeFlow.subscriptionCount.value}") - val ok = _notificationSettingsChangeFlow.tryEmit(Unit) - Timber.d("emit $ok") + _notificationSettingsChangeFlow.tryEmit(Unit) } } -// 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 { notificationSettings.setDelegate(notificationSettingsDelegate) }