diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/notification/UpdateNotificationSettingsAccountDataUseCase.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/notification/UpdateNotificationSettingsAccountDataUseCase.kt index 7791c1dd4b..9296bcd912 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/notification/UpdateNotificationSettingsAccountDataUseCase.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/notification/UpdateNotificationSettingsAccountDataUseCase.kt @@ -16,6 +16,7 @@ package im.vector.app.features.settings.devices.v2.notification +import im.vector.app.core.pushers.UnifiedPushHelper import im.vector.app.features.settings.VectorPreferences import org.matrix.android.sdk.api.account.LocalNotificationSettingsContent import org.matrix.android.sdk.api.session.Session @@ -27,13 +28,14 @@ import javax.inject.Inject */ class UpdateNotificationSettingsAccountDataUseCase @Inject constructor( private val vectorPreferences: VectorPreferences, + private val unifiedPushHelper: UnifiedPushHelper, private val getNotificationSettingsAccountDataUseCase: GetNotificationSettingsAccountDataUseCase, private val setNotificationSettingsAccountDataUseCase: SetNotificationSettingsAccountDataUseCase, private val deleteNotificationSettingsAccountDataUseCase: DeleteNotificationSettingsAccountDataUseCase, ) { suspend fun execute(session: Session) { - if (vectorPreferences.isBackgroundSyncEnabled()) { + if (unifiedPushHelper.isBackgroundSync()) { setCurrentNotificationStatus(session) } else { deleteCurrentNotificationStatus(session) diff --git a/vector/src/test/java/im/vector/app/features/settings/devices/v2/notification/UpdateNotificationSettingsAccountDataUseCaseTest.kt b/vector/src/test/java/im/vector/app/features/settings/devices/v2/notification/UpdateNotificationSettingsAccountDataUseCaseTest.kt index 3bca0da84e..f82663f6e4 100644 --- a/vector/src/test/java/im/vector/app/features/settings/devices/v2/notification/UpdateNotificationSettingsAccountDataUseCaseTest.kt +++ b/vector/src/test/java/im/vector/app/features/settings/devices/v2/notification/UpdateNotificationSettingsAccountDataUseCaseTest.kt @@ -17,6 +17,7 @@ package im.vector.app.features.settings.devices.v2.notification import im.vector.app.test.fakes.FakeSession +import im.vector.app.test.fakes.FakeUnifiedPushHelper import im.vector.app.test.fakes.FakeVectorPreferences import io.mockk.coJustRun import io.mockk.coVerify @@ -30,12 +31,14 @@ import org.matrix.android.sdk.api.account.LocalNotificationSettingsContent class UpdateNotificationSettingsAccountDataUseCaseTest { private val fakeVectorPreferences = FakeVectorPreferences() + private val fakeUnifiedPushHelper = FakeUnifiedPushHelper() private val fakeGetNotificationSettingsAccountDataUseCase = mockk<GetNotificationSettingsAccountDataUseCase>() private val fakeSetNotificationSettingsAccountDataUseCase = mockk<SetNotificationSettingsAccountDataUseCase>() private val fakeDeleteNotificationSettingsAccountDataUseCase = mockk<DeleteNotificationSettingsAccountDataUseCase>() private val updateNotificationSettingsAccountDataUseCase = UpdateNotificationSettingsAccountDataUseCase( vectorPreferences = fakeVectorPreferences.instance, + unifiedPushHelper = fakeUnifiedPushHelper.instance, getNotificationSettingsAccountDataUseCase = fakeGetNotificationSettingsAccountDataUseCase, setNotificationSettingsAccountDataUseCase = fakeSetNotificationSettingsAccountDataUseCase, deleteNotificationSettingsAccountDataUseCase = fakeDeleteNotificationSettingsAccountDataUseCase, @@ -50,7 +53,7 @@ class UpdateNotificationSettingsAccountDataUseCaseTest { coJustRun { fakeSetNotificationSettingsAccountDataUseCase.execute(any(), any(), any()) } val areNotificationsEnabled = true fakeVectorPreferences.givenAreNotificationEnabled(areNotificationsEnabled) - fakeVectorPreferences.givenIsBackgroundSyncEnabled(true) + fakeUnifiedPushHelper.givenIsBackgroundSyncReturns(true) every { fakeGetNotificationSettingsAccountDataUseCase.execute(any(), any()) } returns LocalNotificationSettingsContent( isSilenced = null @@ -64,7 +67,7 @@ class UpdateNotificationSettingsAccountDataUseCaseTest { // Then verify { - fakeVectorPreferences.instance.isBackgroundSyncEnabled() + fakeUnifiedPushHelper.instance.isBackgroundSync() fakeVectorPreferences.instance.areNotificationEnabledForDevice() fakeGetNotificationSettingsAccountDataUseCase.execute(aSession, aDeviceId) } @@ -81,7 +84,7 @@ class UpdateNotificationSettingsAccountDataUseCaseTest { coJustRun { fakeSetNotificationSettingsAccountDataUseCase.execute(any(), any(), any()) } val areNotificationsEnabled = true fakeVectorPreferences.givenAreNotificationEnabled(areNotificationsEnabled) - fakeVectorPreferences.givenIsBackgroundSyncEnabled(true) + fakeUnifiedPushHelper.givenIsBackgroundSyncReturns(true) every { fakeGetNotificationSettingsAccountDataUseCase.execute(any(), any()) } returns LocalNotificationSettingsContent( isSilenced = false @@ -95,7 +98,7 @@ class UpdateNotificationSettingsAccountDataUseCaseTest { // Then verify { - fakeVectorPreferences.instance.isBackgroundSyncEnabled() + fakeUnifiedPushHelper.instance.isBackgroundSync() fakeVectorPreferences.instance.areNotificationEnabledForDevice() fakeGetNotificationSettingsAccountDataUseCase.execute(aSession, aDeviceId) } @@ -110,14 +113,14 @@ class UpdateNotificationSettingsAccountDataUseCaseTest { val aSession = FakeSession() aSession.givenSessionId(aDeviceId) coJustRun { fakeDeleteNotificationSettingsAccountDataUseCase.execute(any()) } - fakeVectorPreferences.givenIsBackgroundSyncEnabled(false) + fakeUnifiedPushHelper.givenIsBackgroundSyncReturns(false) // When updateNotificationSettingsAccountDataUseCase.execute(aSession) // Then verify { - fakeVectorPreferences.instance.isBackgroundSyncEnabled() + fakeUnifiedPushHelper.instance.isBackgroundSync() } coVerify { fakeDeleteNotificationSettingsAccountDataUseCase.execute(aSession) } coVerify(inverse = true) { fakeSetNotificationSettingsAccountDataUseCase.execute(aSession, aDeviceId, any()) } diff --git a/vector/src/test/java/im/vector/app/test/fakes/FakeUnifiedPushHelper.kt b/vector/src/test/java/im/vector/app/test/fakes/FakeUnifiedPushHelper.kt index 99b5b75874..1a09783fad 100644 --- a/vector/src/test/java/im/vector/app/test/fakes/FakeUnifiedPushHelper.kt +++ b/vector/src/test/java/im/vector/app/test/fakes/FakeUnifiedPushHelper.kt @@ -31,4 +31,8 @@ class FakeUnifiedPushHelper { fun givenGetEndpointOrTokenReturns(endpoint: String?) { every { instance.getEndpointOrToken() } returns endpoint } + + fun givenIsBackgroundSyncReturns(enabled: Boolean) { + every { instance.isBackgroundSync() } returns enabled + } }