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 {
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.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)
}

View File

@@ -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,

View File

@@ -35,30 +35,15 @@ class RustNotificationSettingsService(
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()
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)
}