Update dispatcher

This commit is contained in:
yostyle 2023-08-17 09:55:05 +02:00
parent ba06c15809
commit 7f06c321cc
3 changed files with 8 additions and 4 deletions

View file

@ -31,7 +31,7 @@ enum class FeatureFlags(
title = "Polls", title = "Polls",
description = "Render poll events in the timeline", description = "Render poll events in the timeline",
defaultValue = false, defaultValue = false,
) ),
NotificationSettings( NotificationSettings(
key = "feature.notificationsettings", key = "feature.notificationsettings",
title = "Show notification settings", title = "Show notification settings",

View file

@ -106,7 +106,7 @@ class RustMatrixClient constructor(
private val notificationSettings = client.getNotificationSettings() private val notificationSettings = client.getNotificationSettings()
private val notificationService = RustNotificationService(sessionId, notificationClient, dispatchers, clock) private val notificationService = RustNotificationService(sessionId, notificationClient, dispatchers, clock)
private val notificationSettingsService = RustNotificationSettingsService(notificationSettings) private val notificationSettingsService = RustNotificationSettingsService(notificationSettings, dispatchers)
private val isLoggingOut = AtomicBoolean(false) private val isLoggingOut = AtomicBoolean(false)

View file

@ -16,6 +16,7 @@
package io.element.android.libraries.matrix.impl.notificationsettings package io.element.android.libraries.matrix.impl.notificationsettings
import io.element.android.libraries.core.coroutine.CoroutineDispatchers
import io.element.android.libraries.matrix.api.core.RoomId import io.element.android.libraries.matrix.api.core.RoomId
import io.element.android.libraries.matrix.api.notificationsettings.NotificationSettingsService import io.element.android.libraries.matrix.api.notificationsettings.NotificationSettingsService
import io.element.android.libraries.matrix.api.room.RoomNotificationMode import io.element.android.libraries.matrix.api.room.RoomNotificationMode
@ -24,13 +25,15 @@ import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.SharedFlow import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.asSharedFlow import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.withContext
import org.matrix.rustcomponents.sdk.Client import org.matrix.rustcomponents.sdk.Client
import org.matrix.rustcomponents.sdk.NotificationClient import org.matrix.rustcomponents.sdk.NotificationClient
import org.matrix.rustcomponents.sdk.NotificationSettings import org.matrix.rustcomponents.sdk.NotificationSettings
import org.matrix.rustcomponents.sdk.NotificationSettingsDelegate import org.matrix.rustcomponents.sdk.NotificationSettingsDelegate
class RustNotificationSettingsService( class RustNotificationSettingsService(
private val notificationSettings: NotificationSettings private val notificationSettings: NotificationSettings,
private val dispatchers: CoroutineDispatchers,
) : NotificationSettingsService { ) : NotificationSettingsService {
private val _notificationSettingsChangeFlow = MutableSharedFlow<Unit>(extraBufferCapacity = 1, onBufferOverflow = BufferOverflow.DROP_OLDEST) private val _notificationSettingsChangeFlow = MutableSharedFlow<Unit>(extraBufferCapacity = 1, onBufferOverflow = BufferOverflow.DROP_OLDEST)
@ -56,10 +59,11 @@ class RustNotificationSettingsService(
notificationSettings.getDefaultRoomNotificationMode(isEncrypted, membersCount).let(RoomNotificationSettingsMapper::mapMode) notificationSettings.getDefaultRoomNotificationMode(isEncrypted, membersCount).let(RoomNotificationSettingsMapper::mapMode)
} }
override suspend fun setRoomNotificationMode(roomId: RoomId, mode: RoomNotificationMode): Result<Unit> = override suspend fun setRoomNotificationMode(roomId: RoomId, mode: RoomNotificationMode): Result<Unit> = withContext(dispatchers.io) {
runCatching { runCatching {
notificationSettings.setRoomNotificationMode(roomId.value, mode.let(RoomNotificationSettingsMapper::mapMode)) notificationSettings.setRoomNotificationMode(roomId.value, mode.let(RoomNotificationSettingsMapper::mapMode))
} }
}
override suspend fun restoreDefaultRoomNotificationMode(roomId: RoomId): Result<Unit> = override suspend fun restoreDefaultRoomNotificationMode(roomId: RoomId): Result<Unit> =
runCatching { runCatching {