From 1779e53e93da7cc03105707f8efe4cfaa18f6bb0 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 1 Dec 2023 15:02:42 +0100 Subject: [PATCH 1/8] Let RustNotificationSettingsService handle the lifecycle of `notificationSettings`, and call `setDelegate(null)` --- .../libraries/matrix/impl/RustMatrixClient.kt | 8 +++----- .../RustNotificationSettingsService.kt | 13 +++++++++---- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/RustMatrixClient.kt b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/RustMatrixClient.kt index 9c03bd7a0ae..30229fbe8a7 100644 --- a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/RustMatrixClient.kt +++ b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/RustMatrixClient.kt @@ -119,10 +119,9 @@ class RustMatrixClient constructor( .filterByPushRules() .finish() } - private val notificationSettings = client.getNotificationSettings() - 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 encryptionService = RustEncryptionService( client = client, @@ -346,8 +345,7 @@ class RustMatrixClient constructor( override fun close() { sessionCoroutineScope.cancel() clientDelegateTaskHandle?.cancelAndDestroy() - notificationSettings.setDelegate(null) - notificationSettings.destroy() + notificationSettingsService.destroy() verificationService.destroy() syncService.destroy() innerRoomListService.destroy() 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 42b2662a6da..c857de56ddc 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 @@ -26,16 +26,16 @@ import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.SharedFlow import kotlinx.coroutines.flow.asSharedFlow 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.NotificationSettingsException import timber.log.Timber class RustNotificationSettingsService( - private val notificationSettings: NotificationSettings, + client: Client, private val dispatchers: CoroutineDispatchers, ) : NotificationSettingsService { - + private val notificationSettings = client.getNotificationSettings() private val _notificationSettingsChangeFlow = MutableSharedFlow(extraBufferCapacity = 1, onBufferOverflow = BufferOverflow.DROP_OLDEST) override val notificationSettingsChangeFlow: SharedFlow = _notificationSettingsChangeFlow.asSharedFlow() @@ -45,10 +45,15 @@ class RustNotificationSettingsService( } } - init { + fun start() { notificationSettings.setDelegate(notificationSettingsDelegate) } + fun destroy() { + notificationSettings.setDelegate(null) + notificationSettings.destroy() + } + override suspend fun getRoomNotificationSettings(roomId: RoomId, isEncrypted: Boolean, isOneToOne: Boolean): Result = runCatching { notificationSettings.getRoomNotificationSettings(roomId.value, isEncrypted, isOneToOne).let(RoomNotificationSettingsMapper::map) From 0573dda8746e5b1a4f4c5be88f06fb0c9ba566fe Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 4 Dec 2023 12:15:49 +0100 Subject: [PATCH 2/8] Fix issue in link. --- docs/_developer_onboarding.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/_developer_onboarding.md b/docs/_developer_onboarding.md index a100a2bebaf..92610dc8cb6 100644 --- a/docs/_developer_onboarding.md +++ b/docs/_developer_onboarding.md @@ -117,7 +117,7 @@ You can also have access to the aars through the [release](https://github.com/ma #### Build the SDK locally -Easiest way: run the script [./tools/sdk/build_rust_sdk.sh](./tools/sdk/build_rust_sdk.sh) and just answer the questions. +Easiest way: run the script [../tools/sdk/build_rust_sdk.sh](../tools/sdk/build_rust_sdk.sh) and just answer the questions. Legacy way: From 66ac1e271f533df8884b7507ce6da3d04931bd6a Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 4 Dec 2023 13:07:21 +0100 Subject: [PATCH 3/8] Add notification setting to enable/disable being notified for room invite (#1944) --- .../NotificationSettingsEvents.kt | 2 +- .../NotificationSettingsPresenter.kt | 11 +++++++++ .../NotificationSettingsState.kt | 1 + .../NotificationSettingsStateProvider.kt | 1 + .../notifications/NotificationSettingsView.kt | 15 +++++++++--- .../impl/src/main/res/values/localazy.xml | 1 + .../NotificationSettingsPresenterTests.kt | 23 +++++++++++++++++++ .../NotificationSettingsService.kt | 2 ++ .../RustNotificationSettingsService.kt | 12 ++++++++++ .../FakeNotificationSettingsService.kt | 13 +++++++++-- 10 files changed, 75 insertions(+), 6 deletions(-) diff --git a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsEvents.kt b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsEvents.kt index 9e87675b3a2..f38c211b672 100644 --- a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsEvents.kt +++ b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsEvents.kt @@ -17,11 +17,11 @@ package io.element.android.features.preferences.impl.notifications sealed interface NotificationSettingsEvents { - data object RefreshSystemNotificationsEnabled : NotificationSettingsEvents data class SetNotificationsEnabled(val enabled: Boolean) : NotificationSettingsEvents data class SetAtRoomNotificationsEnabled(val enabled: Boolean) : NotificationSettingsEvents data class SetCallNotificationsEnabled(val enabled: Boolean) : NotificationSettingsEvents + data class SetInviteForMeNotificationsEnabled(val enabled: Boolean) : NotificationSettingsEvents data object FixConfigurationMismatch : NotificationSettingsEvents data object ClearConfigurationMismatchError : NotificationSettingsEvents data object ClearNotificationChangeError : NotificationSettingsEvents diff --git a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsPresenter.kt b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsPresenter.kt index 689cca8f66d..6252be1e5c4 100644 --- a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsPresenter.kt +++ b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsPresenter.kt @@ -76,6 +76,9 @@ class NotificationSettingsPresenter @Inject constructor( is NotificationSettingsEvents.SetCallNotificationsEnabled -> { localCoroutineScope.setCallNotificationsEnabled(event.enabled, changeNotificationSettingAction) } + is NotificationSettingsEvents.SetInviteForMeNotificationsEnabled -> { + localCoroutineScope.setInviteForMeNotificationsEnabled(event.enabled, changeNotificationSettingAction) + } is NotificationSettingsEvents.SetNotificationsEnabled -> localCoroutineScope.setNotificationsEnabled(userPushStore, event.enabled) NotificationSettingsEvents.ClearConfigurationMismatchError -> { matrixSettings.value = NotificationSettingsState.MatrixSettings.Invalid(fixFailed = false) @@ -123,10 +126,12 @@ class NotificationSettingsPresenter @Inject constructor( val callNotificationsEnabled = notificationSettingsService.isCallEnabled().getOrThrow() val atRoomNotificationsEnabled = notificationSettingsService.isRoomMentionEnabled().getOrThrow() + val inviteForMeNotificationsEnabled = notificationSettingsService.isInviteForMeEnabled().getOrThrow() target.value = NotificationSettingsState.MatrixSettings.Valid( atRoomNotificationsEnabled = atRoomNotificationsEnabled, callNotificationsEnabled = callNotificationsEnabled, + inviteForMeNotificationsEnabled = inviteForMeNotificationsEnabled, defaultGroupNotificationMode = encryptedGroupDefaultMode, defaultOneToOneNotificationMode = encryptedOneToOneDefaultMode, ) @@ -175,6 +180,12 @@ class NotificationSettingsPresenter @Inject constructor( }.runCatchingUpdatingState(action) } + private fun CoroutineScope.setInviteForMeNotificationsEnabled(enabled: Boolean, action: MutableState>) = launch { + suspend { + notificationSettingsService.setInviteForMeEnabled(enabled).getOrThrow() + }.runCatchingUpdatingState(action) + } + private fun CoroutineScope.setNotificationsEnabled(userPushStore: UserPushStore, enabled: Boolean) = launch { userPushStore.setNotificationEnabledForDevice(enabled) } diff --git a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsState.kt b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsState.kt index 2b0faa110cd..581f0e84758 100644 --- a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsState.kt +++ b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsState.kt @@ -32,6 +32,7 @@ data class NotificationSettingsState( data class Valid( val atRoomNotificationsEnabled: Boolean, val callNotificationsEnabled: Boolean, + val inviteForMeNotificationsEnabled: Boolean, val defaultGroupNotificationMode: RoomNotificationMode?, val defaultOneToOneNotificationMode: RoomNotificationMode?, ) : MatrixSettings diff --git a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsStateProvider.kt b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsStateProvider.kt index 9336857585a..f121a2fe600 100644 --- a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsStateProvider.kt +++ b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsStateProvider.kt @@ -35,6 +35,7 @@ fun aNotificationSettingsState( matrixSettings = NotificationSettingsState.MatrixSettings.Valid( atRoomNotificationsEnabled = true, callNotificationsEnabled = true, + inviteForMeNotificationsEnabled = true, defaultGroupNotificationMode = RoomNotificationMode.MENTIONS_AND_KEYWORDS_ONLY, defaultOneToOneNotificationMode = RoomNotificationMode.ALL_MESSAGES, ), diff --git a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsView.kt b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsView.kt index c2c52a07c9d..f1066b2e9d2 100644 --- a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsView.kt +++ b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsView.kt @@ -77,6 +77,7 @@ fun NotificationSettingsView( onMentionNotificationsChanged = { state.eventSink(NotificationSettingsEvents.SetAtRoomNotificationsEnabled(it)) }, // TODO We are removing the call notification toggle until support for call notifications has been added // onCallsNotificationsChanged = { state.eventSink(NotificationSettingsEvents.SetCallNotificationsEnabled(it)) }, + onInviteForMeNotificationsChanged = { state.eventSink(NotificationSettingsEvents.SetInviteForMeNotificationsEnabled(it)) }, ) } AsyncView( @@ -98,6 +99,7 @@ private fun NotificationSettingsContentView( onMentionNotificationsChanged: (Boolean) -> Unit, // TODO We are removing the call notification toggle until support for call notifications has been added // onCallsNotificationsChanged: (Boolean) -> Unit, + onInviteForMeNotificationsChanged: (Boolean) -> Unit, modifier: Modifier = Modifier, ) { val context = LocalContext.current @@ -147,8 +149,8 @@ private fun NotificationSettingsContentView( onCheckedChange = onMentionNotificationsChanged ) } - // TODO We are removing the call notification toggle until support for call notifications has been added -// PreferenceCategory(title = stringResource(id = CommonStrings.screen_notification_settings_additional_settings_section_title)) { + PreferenceCategory(title = stringResource(id = R.string.screen_notification_settings_additional_settings_section_title)) { + // TODO We are removing the call notification toggle until support for call notifications has been added // PreferenceSwitch( // modifier = Modifier, // title = stringResource(id = CommonStrings.screen_notification_settings_calls_label), @@ -156,7 +158,14 @@ private fun NotificationSettingsContentView( // switchAlignment = Alignment.Top, // onCheckedChange = onCallsNotificationsChanged // ) -// } + PreferenceSwitch( + modifier = Modifier, + title = stringResource(id = R.string.screen_notification_settings_invite_for_me_label), + isChecked = matrixSettings.inviteForMeNotificationsEnabled, + switchAlignment = Alignment.Top, + onCheckedChange = onInviteForMeNotificationsChanged + ) + } } } diff --git a/features/preferences/impl/src/main/res/values/localazy.xml b/features/preferences/impl/src/main/res/values/localazy.xml index c76c647bba7..55c43f05f46 100644 --- a/features/preferences/impl/src/main/res/values/localazy.xml +++ b/features/preferences/impl/src/main/res/values/localazy.xml @@ -29,6 +29,7 @@ If you proceed, some of your settings may change." "Enable notifications on this device" "The configuration has not been corrected, please try again." "Group chats" + "Invitations" "Your homeserver does not support this option in encrypted rooms, you may not get notified in some rooms." "Mentions" "All" diff --git a/features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsPresenterTests.kt b/features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsPresenterTests.kt index 52b1108273d..e55d7a1c801 100644 --- a/features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsPresenterTests.kt +++ b/features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsPresenterTests.kt @@ -50,6 +50,7 @@ class NotificationSettingsPresenterTests { val valid = loadedState.matrixSettings as? NotificationSettingsState.MatrixSettings.Valid assertThat(valid?.atRoomNotificationsEnabled).isFalse() assertThat(valid?.callNotificationsEnabled).isFalse() + assertThat(valid?.inviteForMeNotificationsEnabled).isFalse() assertThat(valid?.defaultGroupNotificationMode).isEqualTo(RoomNotificationMode.MENTIONS_AND_KEYWORDS_ONLY) assertThat(valid?.defaultOneToOneNotificationMode).isEqualTo(RoomNotificationMode.ALL_MESSAGES) cancelAndIgnoreRemainingEvents() @@ -166,6 +167,28 @@ class NotificationSettingsPresenterTests { } } + @Test + fun `present - set invite for me notifications enabled`() = runTest { + val presenter = createNotificationSettingsPresenter() + moleculeFlow(RecompositionMode.Immediate) { + presenter.present() + }.test { + val loadedState = consumeItemsUntilPredicate { + (it.matrixSettings as? NotificationSettingsState.MatrixSettings.Valid)?.inviteForMeNotificationsEnabled == false + }.last() + val validMatrixState = loadedState.matrixSettings as? NotificationSettingsState.MatrixSettings.Valid + Truth.assertThat(validMatrixState?.inviteForMeNotificationsEnabled).isFalse() + + loadedState.eventSink(NotificationSettingsEvents.SetInviteForMeNotificationsEnabled(true)) + val updatedState = consumeItemsUntilPredicate { + (it.matrixSettings as? NotificationSettingsState.MatrixSettings.Valid)?.inviteForMeNotificationsEnabled == true + }.last() + val updatedMatrixState = updatedState.matrixSettings as? NotificationSettingsState.MatrixSettings.Valid + Truth.assertThat(updatedMatrixState?.inviteForMeNotificationsEnabled).isTrue() + cancelAndIgnoreRemainingEvents() + } + } + @Test fun `present - set atRoom notifications enabled`() = runTest { val presenter = createNotificationSettingsPresenter() diff --git a/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/notificationsettings/NotificationSettingsService.kt b/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/notificationsettings/NotificationSettingsService.kt index 71d46a2b8e3..ca005e624a8 100644 --- a/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/notificationsettings/NotificationSettingsService.kt +++ b/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/notificationsettings/NotificationSettingsService.kt @@ -38,5 +38,7 @@ interface NotificationSettingsService { suspend fun setRoomMentionEnabled(enabled: Boolean): Result suspend fun isCallEnabled(): Result suspend fun setCallEnabled(enabled: Boolean): Result + suspend fun isInviteForMeEnabled(): Result + suspend fun setInviteForMeEnabled(enabled: Boolean): Result suspend fun getRoomsWithUserDefinedRules(): Result> } 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 c857de56ddc..6ddebfbe705 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 @@ -124,6 +124,18 @@ class RustNotificationSettingsService( } } + override suspend fun isInviteForMeEnabled(): Result = withContext(dispatchers.io) { + runCatching { + notificationSettings.isInviteForMeEnabled() + } + } + + override suspend fun setInviteForMeEnabled(enabled: Boolean): Result = withContext(dispatchers.io) { + runCatching { + notificationSettings.setInviteForMeEnabled(enabled) + } + } + override suspend fun getRoomsWithUserDefinedRules(): Result> = runCatching { notificationSettings.getRoomsWithUserDefinedRules(enabled = true) diff --git a/libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/notificationsettings/FakeNotificationSettingsService.kt b/libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/notificationsettings/FakeNotificationSettingsService.kt index 039b855e7ef..969acb9d257 100644 --- a/libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/notificationsettings/FakeNotificationSettingsService.kt +++ b/libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/notificationsettings/FakeNotificationSettingsService.kt @@ -41,6 +41,7 @@ class FakeNotificationSettingsService( private var roomNotificationMode: RoomNotificationMode = initialRoomMode private var roomNotificationModeIsDefault: Boolean = initialRoomModeIsDefault private var callNotificationsEnabled = false + private var inviteNotificationsEnabled = false private var atRoomNotificationsEnabled = false private var setNotificationModeError: Throwable? = null private var restoreDefaultNotificationModeError: Throwable? = null @@ -52,7 +53,7 @@ class FakeNotificationSettingsService( override suspend fun getRoomNotificationSettings(roomId: RoomId, isEncrypted: Boolean, isOneToOne: Boolean): Result { return Result.success( RoomNotificationSettings( - mode = if(roomNotificationModeIsDefault) defaultEncryptedGroupRoomNotificationMode else roomNotificationMode, + mode = if (roomNotificationModeIsDefault) defaultEncryptedGroupRoomNotificationMode else roomNotificationMode, isDefault = roomNotificationModeIsDefault ) ) @@ -149,6 +150,15 @@ class FakeNotificationSettingsService( return Result.success(Unit) } + override suspend fun isInviteForMeEnabled(): Result { + return Result.success(inviteNotificationsEnabled) + } + + override suspend fun setInviteForMeEnabled(enabled: Boolean): Result { + inviteNotificationsEnabled = enabled + return Result.success(Unit) + } + override suspend fun getRoomsWithUserDefinedRules(): Result> { return Result.success(if (roomNotificationModeIsDefault) listOf() else listOf(A_ROOM_ID.value)) } @@ -168,5 +178,4 @@ class FakeNotificationSettingsService( fun givenSetDefaultNotificationModeError(throwable: Throwable?) { setDefaultNotificationModeError = throwable } - } From 0c7ae98099a2bcfe57ab23ffe7703d5f0821f53d Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 4 Dec 2023 14:46:38 +0100 Subject: [PATCH 4/8] Remove empty lines --- .../NotificationSettingsPresenterTests.kt | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsPresenterTests.kt b/features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsPresenterTests.kt index e55d7a1c801..96eca14746c 100644 --- a/features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsPresenterTests.kt +++ b/features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsPresenterTests.kt @@ -41,7 +41,6 @@ class NotificationSettingsPresenterTests { assertThat(initialState.appSettings.appNotificationsEnabled).isFalse() assertThat(initialState.appSettings.systemNotificationsEnabled).isTrue() assertThat(initialState.matrixSettings).isEqualTo(NotificationSettingsState.MatrixSettings.Uninitialized) - val loadedState = consumeItemsUntilPredicate { it.matrixSettings is NotificationSettingsState.MatrixSettings.Valid }.last() @@ -64,7 +63,6 @@ class NotificationSettingsPresenterTests { moleculeFlow(RecompositionMode.Immediate) { presenter.present() }.test { - notificationSettingsService.setDefaultRoomNotificationMode(isEncrypted = true, isOneToOne = false, mode = RoomNotificationMode.ALL_MESSAGES) notificationSettingsService.setDefaultRoomNotificationMode(isEncrypted = false, isOneToOne = false, mode = RoomNotificationMode.ALL_MESSAGES) val updatedState = consumeItemsUntilPredicate { @@ -83,7 +81,6 @@ class NotificationSettingsPresenterTests { moleculeFlow(RecompositionMode.Immediate) { presenter.present() }.test { - notificationSettingsService.setDefaultRoomNotificationMode( isEncrypted = true, isOneToOne = false, @@ -119,7 +116,6 @@ class NotificationSettingsPresenterTests { val fixedState = consumeItemsUntilPredicate(timeout = 2000.milliseconds) { it.matrixSettings is NotificationSettingsState.MatrixSettings.Valid }.last() - val fixedMatrixState = fixedState.matrixSettings as? NotificationSettingsState.MatrixSettings.Valid assertThat(fixedMatrixState?.defaultGroupNotificationMode).isEqualTo(RoomNotificationMode.ALL_MESSAGES) } @@ -135,7 +131,6 @@ class NotificationSettingsPresenterTests { it.matrixSettings is NotificationSettingsState.MatrixSettings.Valid }.last() assertThat(loadedState.appSettings.appNotificationsEnabled).isTrue() - loadedState.eventSink(NotificationSettingsEvents.SetNotificationsEnabled(false)) val updatedState = consumeItemsUntilPredicate { !it.appSettings.appNotificationsEnabled @@ -156,7 +151,6 @@ class NotificationSettingsPresenterTests { }.last() val validMatrixState = loadedState.matrixSettings as? NotificationSettingsState.MatrixSettings.Valid assertThat(validMatrixState?.callNotificationsEnabled).isFalse() - loadedState.eventSink(NotificationSettingsEvents.SetCallNotificationsEnabled(true)) val updatedState = consumeItemsUntilPredicate { (it.matrixSettings as? NotificationSettingsState.MatrixSettings.Valid)?.callNotificationsEnabled == true @@ -177,14 +171,13 @@ class NotificationSettingsPresenterTests { (it.matrixSettings as? NotificationSettingsState.MatrixSettings.Valid)?.inviteForMeNotificationsEnabled == false }.last() val validMatrixState = loadedState.matrixSettings as? NotificationSettingsState.MatrixSettings.Valid - Truth.assertThat(validMatrixState?.inviteForMeNotificationsEnabled).isFalse() - + assertThat(validMatrixState?.inviteForMeNotificationsEnabled).isFalse() loadedState.eventSink(NotificationSettingsEvents.SetInviteForMeNotificationsEnabled(true)) val updatedState = consumeItemsUntilPredicate { (it.matrixSettings as? NotificationSettingsState.MatrixSettings.Valid)?.inviteForMeNotificationsEnabled == true }.last() val updatedMatrixState = updatedState.matrixSettings as? NotificationSettingsState.MatrixSettings.Valid - Truth.assertThat(updatedMatrixState?.inviteForMeNotificationsEnabled).isTrue() + assertThat(updatedMatrixState?.inviteForMeNotificationsEnabled).isTrue() cancelAndIgnoreRemainingEvents() } } @@ -200,7 +193,6 @@ class NotificationSettingsPresenterTests { }.last() val validMatrixState = loadedState.matrixSettings as? NotificationSettingsState.MatrixSettings.Valid assertThat(validMatrixState?.atRoomNotificationsEnabled).isFalse() - loadedState.eventSink(NotificationSettingsEvents.SetAtRoomNotificationsEnabled(true)) val updatedState = consumeItemsUntilPredicate { (it.matrixSettings as? NotificationSettingsState.MatrixSettings.Valid)?.atRoomNotificationsEnabled == true @@ -224,14 +216,12 @@ class NotificationSettingsPresenterTests { }.last() val validMatrixState = loadedState.matrixSettings as? NotificationSettingsState.MatrixSettings.Valid assertThat(validMatrixState?.atRoomNotificationsEnabled).isFalse() - loadedState.eventSink(NotificationSettingsEvents.SetAtRoomNotificationsEnabled(true)) val errorState = consumeItemsUntilPredicate { it.changeNotificationSettingAction.isFailure() }.last() assertThat(errorState.changeNotificationSettingAction.isFailure()).isTrue() errorState.eventSink(NotificationSettingsEvents.ClearNotificationChangeError) - val clearErrorState = consumeItemsUntilPredicate { it.changeNotificationSettingAction.isUninitialized() }.last() From 2066c2ff6b324be60d663a6854fad10b58448ef3 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 4 Dec 2023 14:56:09 +0100 Subject: [PATCH 5/8] Changelog --- changelog.d/1944.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/1944.misc diff --git a/changelog.d/1944.misc b/changelog.d/1944.misc new file mode 100644 index 00000000000..79e271fa8b5 --- /dev/null +++ b/changelog.d/1944.misc @@ -0,0 +1 @@ +Add toggle in the notification settings to disable notifications for room invites. From 4632ab690da79391f757c509da2323d8f809705c Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 4 Dec 2023 17:30:44 +0100 Subject: [PATCH 6/8] Use SDK 0.1.74 --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 2477644b1a9..da01b862908 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -147,7 +147,7 @@ jsoup = "org.jsoup:jsoup:1.17.1" appyx_core = { module = "com.bumble.appyx:core", version.ref = "appyx" } molecule-runtime = "app.cash.molecule:molecule-runtime:1.3.1" timber = "com.jakewharton.timber:timber:5.0.1" -matrix_sdk = "org.matrix.rustcomponents:sdk-android:0.1.73" +matrix_sdk = "org.matrix.rustcomponents:sdk-android:0.1.74" matrix_richtexteditor = { module = "io.element.android:wysiwyg", version.ref = "wysiwyg" } matrix_richtexteditor_compose = { module = "io.element.android:wysiwyg-compose", version.ref = "wysiwyg" } sqldelight-driver-android = { module = "app.cash.sqldelight:android-driver", version.ref = "sqldelight" } From f44a4a3a3143bc24a7c840db4f2f17ce52a727b0 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 4 Dec 2023 18:07:04 +0100 Subject: [PATCH 7/8] Fix `AlsoCouldBeApply` issue. --- .../element/android/libraries/matrix/impl/RustMatrixClient.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/RustMatrixClient.kt b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/RustMatrixClient.kt index 30229fbe8a7..2cf3d1f82c1 100644 --- a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/RustMatrixClient.kt +++ b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/RustMatrixClient.kt @@ -121,7 +121,7 @@ class RustMatrixClient constructor( } private val notificationService = RustNotificationService(sessionId, notificationClient, dispatchers, clock) private val notificationSettingsService = RustNotificationSettingsService(client, dispatchers) - .also { it.start() } + .apply { start() } private val roomSyncSubscriber = RoomSyncSubscriber(innerRoomListService, dispatchers) private val encryptionService = RustEncryptionService( client = client, From 2584d2fd9f4bf96f66eeb5bb56df3899623a0cec Mon Sep 17 00:00:00 2001 From: ElementBot Date: Mon, 4 Dec 2023 17:16:05 +0000 Subject: [PATCH 8/8] Update screenshots --- ...otificationSettingsView-Day-5_5_null_0,NEXUS_5,1.0,en].png | 4 ++-- ...otificationSettingsView-Day-5_5_null_1,NEXUS_5,1.0,en].png | 4 ++-- ...otificationSettingsView-Day-5_5_null_2,NEXUS_5,1.0,en].png | 4 ++-- ...ificationSettingsView-Night-5_6_null_0,NEXUS_5,1.0,en].png | 4 ++-- ...ificationSettingsView-Night-5_6_null_1,NEXUS_5,1.0,en].png | 4 ++-- ...ificationSettingsView-Night-5_6_null_2,NEXUS_5,1.0,en].png | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/uitests/src/test/snapshots/images/ui_S_t[f.preferences.impl.notifications_NotificationSettingsView_null_NotificationSettingsView-Day-5_5_null_0,NEXUS_5,1.0,en].png b/tests/uitests/src/test/snapshots/images/ui_S_t[f.preferences.impl.notifications_NotificationSettingsView_null_NotificationSettingsView-Day-5_5_null_0,NEXUS_5,1.0,en].png index 668e2a9f554..d143e02b070 100644 --- a/tests/uitests/src/test/snapshots/images/ui_S_t[f.preferences.impl.notifications_NotificationSettingsView_null_NotificationSettingsView-Day-5_5_null_0,NEXUS_5,1.0,en].png +++ b/tests/uitests/src/test/snapshots/images/ui_S_t[f.preferences.impl.notifications_NotificationSettingsView_null_NotificationSettingsView-Day-5_5_null_0,NEXUS_5,1.0,en].png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:2f9516130ee975b723283523d1d62eaa116ae075be3ce62477aaf0429eeff13c -size 52832 +oid sha256:a4b146a10957549dd4410bff3ce4793d25c31910607eec43db44b7be019af068 +size 60521 diff --git a/tests/uitests/src/test/snapshots/images/ui_S_t[f.preferences.impl.notifications_NotificationSettingsView_null_NotificationSettingsView-Day-5_5_null_1,NEXUS_5,1.0,en].png b/tests/uitests/src/test/snapshots/images/ui_S_t[f.preferences.impl.notifications_NotificationSettingsView_null_NotificationSettingsView-Day-5_5_null_1,NEXUS_5,1.0,en].png index c3d1b9b8992..b980dba66ae 100644 --- a/tests/uitests/src/test/snapshots/images/ui_S_t[f.preferences.impl.notifications_NotificationSettingsView_null_NotificationSettingsView-Day-5_5_null_1,NEXUS_5,1.0,en].png +++ b/tests/uitests/src/test/snapshots/images/ui_S_t[f.preferences.impl.notifications_NotificationSettingsView_null_NotificationSettingsView-Day-5_5_null_1,NEXUS_5,1.0,en].png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:3ae4c265af9ff1c5ffeff7f4aa6adfb5e0091ae9fd6360f46ee8261cf4ca213d -size 48895 +oid sha256:340808b11e072679e7b90c939bcb5367a723b9881f084dccc0b594de5f12d543 +size 54830 diff --git a/tests/uitests/src/test/snapshots/images/ui_S_t[f.preferences.impl.notifications_NotificationSettingsView_null_NotificationSettingsView-Day-5_5_null_2,NEXUS_5,1.0,en].png b/tests/uitests/src/test/snapshots/images/ui_S_t[f.preferences.impl.notifications_NotificationSettingsView_null_NotificationSettingsView-Day-5_5_null_2,NEXUS_5,1.0,en].png index 2a54285bdc3..dc7c28e2227 100644 --- a/tests/uitests/src/test/snapshots/images/ui_S_t[f.preferences.impl.notifications_NotificationSettingsView_null_NotificationSettingsView-Day-5_5_null_2,NEXUS_5,1.0,en].png +++ b/tests/uitests/src/test/snapshots/images/ui_S_t[f.preferences.impl.notifications_NotificationSettingsView_null_NotificationSettingsView-Day-5_5_null_2,NEXUS_5,1.0,en].png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e5b745897ee2bfb084a80ebbc585577532261d5a8d71926ad42c02008be46003 -size 48810 +oid sha256:ff00bafd64a4827472d757e6519955550327bb9dca97ea8a7163da4ce278f445 +size 54777 diff --git a/tests/uitests/src/test/snapshots/images/ui_S_t[f.preferences.impl.notifications_NotificationSettingsView_null_NotificationSettingsView-Night-5_6_null_0,NEXUS_5,1.0,en].png b/tests/uitests/src/test/snapshots/images/ui_S_t[f.preferences.impl.notifications_NotificationSettingsView_null_NotificationSettingsView-Night-5_6_null_0,NEXUS_5,1.0,en].png index 7848721702f..3b40c8cedae 100644 --- a/tests/uitests/src/test/snapshots/images/ui_S_t[f.preferences.impl.notifications_NotificationSettingsView_null_NotificationSettingsView-Night-5_6_null_0,NEXUS_5,1.0,en].png +++ b/tests/uitests/src/test/snapshots/images/ui_S_t[f.preferences.impl.notifications_NotificationSettingsView_null_NotificationSettingsView-Night-5_6_null_0,NEXUS_5,1.0,en].png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:3a68d87c82275e80a6774712ea0ab85b04cece2c2d2dc8c19133e6878d71a1b4 -size 49178 +oid sha256:d0b8f14d6bcd6309cf8a961104738c529164621a2de4c642ce7944a48217d609 +size 55838 diff --git a/tests/uitests/src/test/snapshots/images/ui_S_t[f.preferences.impl.notifications_NotificationSettingsView_null_NotificationSettingsView-Night-5_6_null_1,NEXUS_5,1.0,en].png b/tests/uitests/src/test/snapshots/images/ui_S_t[f.preferences.impl.notifications_NotificationSettingsView_null_NotificationSettingsView-Night-5_6_null_1,NEXUS_5,1.0,en].png index ed511c69805..68440b467ae 100644 --- a/tests/uitests/src/test/snapshots/images/ui_S_t[f.preferences.impl.notifications_NotificationSettingsView_null_NotificationSettingsView-Night-5_6_null_1,NEXUS_5,1.0,en].png +++ b/tests/uitests/src/test/snapshots/images/ui_S_t[f.preferences.impl.notifications_NotificationSettingsView_null_NotificationSettingsView-Night-5_6_null_1,NEXUS_5,1.0,en].png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:8ecc7a31d53543fae8950e2773da0aea2ebdb6c9b557254e0062ce000dcd79b3 -size 45061 +oid sha256:964fc455b25f442bfc89e917148c15f7f9301d9b6db5c94f2075d994b74a6eef +size 50975 diff --git a/tests/uitests/src/test/snapshots/images/ui_S_t[f.preferences.impl.notifications_NotificationSettingsView_null_NotificationSettingsView-Night-5_6_null_2,NEXUS_5,1.0,en].png b/tests/uitests/src/test/snapshots/images/ui_S_t[f.preferences.impl.notifications_NotificationSettingsView_null_NotificationSettingsView-Night-5_6_null_2,NEXUS_5,1.0,en].png index 33d23d70814..a6ff4a33176 100644 --- a/tests/uitests/src/test/snapshots/images/ui_S_t[f.preferences.impl.notifications_NotificationSettingsView_null_NotificationSettingsView-Night-5_6_null_2,NEXUS_5,1.0,en].png +++ b/tests/uitests/src/test/snapshots/images/ui_S_t[f.preferences.impl.notifications_NotificationSettingsView_null_NotificationSettingsView-Night-5_6_null_2,NEXUS_5,1.0,en].png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:8bb56b559b52efdd9f6ac41e0ae674054b6f511292b2cf88208bbf32afb765a9 -size 44414 +oid sha256:fccd2b3e6fff431b0b650cccef21c0b8129c838dfc3b1b0bc6ee83321dcfe698 +size 50386