mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-02 21:32:34 +00:00
Let RustNotificationSettingsService handle the lifecycle of notificationSettings, and call setDelegate(null)
This commit is contained in:
committed by
Benoit Marty
parent
5b0a4fba83
commit
1779e53e93
+3
-5
@@ -119,10 +119,9 @@ class RustMatrixClient constructor(
|
|||||||
.filterByPushRules()
|
.filterByPushRules()
|
||||||
.finish()
|
.finish()
|
||||||
}
|
}
|
||||||
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, dispatchers)
|
private val notificationSettingsService = RustNotificationSettingsService(client, dispatchers)
|
||||||
|
.also { it.start() }
|
||||||
private val roomSyncSubscriber = RoomSyncSubscriber(innerRoomListService, dispatchers)
|
private val roomSyncSubscriber = RoomSyncSubscriber(innerRoomListService, dispatchers)
|
||||||
private val encryptionService = RustEncryptionService(
|
private val encryptionService = RustEncryptionService(
|
||||||
client = client,
|
client = client,
|
||||||
@@ -346,8 +345,7 @@ class RustMatrixClient constructor(
|
|||||||
override fun close() {
|
override fun close() {
|
||||||
sessionCoroutineScope.cancel()
|
sessionCoroutineScope.cancel()
|
||||||
clientDelegateTaskHandle?.cancelAndDestroy()
|
clientDelegateTaskHandle?.cancelAndDestroy()
|
||||||
notificationSettings.setDelegate(null)
|
notificationSettingsService.destroy()
|
||||||
notificationSettings.destroy()
|
|
||||||
verificationService.destroy()
|
verificationService.destroy()
|
||||||
syncService.destroy()
|
syncService.destroy()
|
||||||
innerRoomListService.destroy()
|
innerRoomListService.destroy()
|
||||||
|
|||||||
+9
-4
@@ -26,16 +26,16 @@ 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 kotlinx.coroutines.withContext
|
||||||
import org.matrix.rustcomponents.sdk.NotificationSettings
|
import org.matrix.rustcomponents.sdk.Client
|
||||||
import org.matrix.rustcomponents.sdk.NotificationSettingsDelegate
|
import org.matrix.rustcomponents.sdk.NotificationSettingsDelegate
|
||||||
import org.matrix.rustcomponents.sdk.NotificationSettingsException
|
import org.matrix.rustcomponents.sdk.NotificationSettingsException
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
class RustNotificationSettingsService(
|
class RustNotificationSettingsService(
|
||||||
private val notificationSettings: NotificationSettings,
|
client: Client,
|
||||||
private val dispatchers: CoroutineDispatchers,
|
private val dispatchers: CoroutineDispatchers,
|
||||||
) : NotificationSettingsService {
|
) : NotificationSettingsService {
|
||||||
|
private val notificationSettings = client.getNotificationSettings()
|
||||||
private val _notificationSettingsChangeFlow = MutableSharedFlow<Unit>(extraBufferCapacity = 1, 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()
|
||||||
|
|
||||||
@@ -45,10 +45,15 @@ class RustNotificationSettingsService(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
fun start() {
|
||||||
notificationSettings.setDelegate(notificationSettingsDelegate)
|
notificationSettings.setDelegate(notificationSettingsDelegate)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun destroy() {
|
||||||
|
notificationSettings.setDelegate(null)
|
||||||
|
notificationSettings.destroy()
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun getRoomNotificationSettings(roomId: RoomId, isEncrypted: Boolean, isOneToOne: Boolean): Result<RoomNotificationSettings> =
|
override suspend fun getRoomNotificationSettings(roomId: RoomId, isEncrypted: Boolean, isOneToOne: Boolean): Result<RoomNotificationSettings> =
|
||||||
runCatching {
|
runCatching {
|
||||||
notificationSettings.getRoomNotificationSettings(roomId.value, isEncrypted, isOneToOne).let(RoomNotificationSettingsMapper::map)
|
notificationSettings.getRoomNotificationSettings(roomId.value, isEncrypted, isOneToOne).let(RoomNotificationSettingsMapper::map)
|
||||||
|
|||||||
Reference in New Issue
Block a user