diff --git a/vector/src/main/java/im/vector/app/core/notification/NotificationsSettingUpdater.kt b/vector/src/main/java/im/vector/app/core/notification/NotificationsSettingUpdater.kt index 4a16f37cfe..a4d18baa64 100644 --- a/vector/src/main/java/im/vector/app/core/notification/NotificationsSettingUpdater.kt +++ b/vector/src/main/java/im/vector/app/core/notification/NotificationsSettingUpdater.kt @@ -16,11 +16,7 @@ package im.vector.app.core.notification -import android.content.SharedPreferences.OnSharedPreferenceChangeListener import im.vector.app.features.session.coroutineScope -import im.vector.app.features.settings.VectorPreferences -import im.vector.app.features.settings.VectorPreferences.Companion.SETTINGS_FDROID_BACKGROUND_SYNC_MODE -import im.vector.app.features.settings.devices.v2.notification.UpdateNotificationSettingsAccountDataUseCase import kotlinx.coroutines.Job import kotlinx.coroutines.launch import org.matrix.android.sdk.api.session.Session @@ -29,21 +25,16 @@ import javax.inject.Singleton /** * Listen changes in Pusher or Account Data to update the local setting for notification toggle. - * Listen changes on background sync mode preference to update the corresponding Account Data event. */ @Singleton class NotificationsSettingUpdater @Inject constructor( private val updateEnableNotificationsSettingOnChangeUseCase: UpdateEnableNotificationsSettingOnChangeUseCase, - private val vectorPreferences: VectorPreferences, - private val updateNotificationSettingsAccountDataUseCase: UpdateNotificationSettingsAccountDataUseCase, ) { private var job: Job? = null - private var prefChangeListener: OnSharedPreferenceChangeListener? = null fun onSessionStarted(session: Session) { updateEnableNotificationsSettingOnChange(session) - updateAccountDataOnBackgroundSyncChange(session) } private fun updateEnableNotificationsSettingOnChange(session: Session) { @@ -52,22 +43,4 @@ class NotificationsSettingUpdater @Inject constructor( updateEnableNotificationsSettingOnChangeUseCase.execute(session) } } - - private fun updateAccountDataOnBackgroundSyncChange(session: Session) { - prefChangeListener?.let { vectorPreferences.unsubscribeToChanges(it) } - prefChangeListener = null - prefChangeListener = createPrefListener(session).also { - vectorPreferences.subscribeToChanges(it) - } - } - - private fun createPrefListener(session: Session): OnSharedPreferenceChangeListener { - return OnSharedPreferenceChangeListener { _, key -> - session.coroutineScope.launch { - if (key == SETTINGS_FDROID_BACKGROUND_SYNC_MODE) { - updateNotificationSettingsAccountDataUseCase.execute(session) - } - } - } - } } diff --git a/vector/src/test/java/im/vector/app/core/notification/NotificationsSettingUpdaterTest.kt b/vector/src/test/java/im/vector/app/core/notification/NotificationsSettingUpdaterTest.kt index 386b52e61e..0920ee4716 100644 --- a/vector/src/test/java/im/vector/app/core/notification/NotificationsSettingUpdaterTest.kt +++ b/vector/src/test/java/im/vector/app/core/notification/NotificationsSettingUpdaterTest.kt @@ -17,10 +17,7 @@ package im.vector.app.core.notification import im.vector.app.features.session.coroutineScope -import im.vector.app.features.settings.VectorPreferences -import im.vector.app.features.settings.devices.v2.notification.UpdateNotificationSettingsAccountDataUseCase import im.vector.app.test.fakes.FakeSession -import im.vector.app.test.fakes.FakeVectorPreferences import io.mockk.coJustRun import io.mockk.coVerify import io.mockk.every @@ -36,13 +33,9 @@ import org.junit.Test class NotificationsSettingUpdaterTest { private val fakeUpdateEnableNotificationsSettingOnChangeUseCase = mockk() - private val fakeVectorPreferences = FakeVectorPreferences() - private val fakeUpdateNotificationSettingsAccountDataUseCase = mockk() private val notificationsSettingUpdater = NotificationsSettingUpdater( updateEnableNotificationsSettingOnChangeUseCase = fakeUpdateEnableNotificationsSettingOnChangeUseCase, - vectorPreferences = fakeVectorPreferences.instance, - updateNotificationSettingsAccountDataUseCase = fakeUpdateNotificationSettingsAccountDataUseCase, ) @Before @@ -69,38 +62,4 @@ class NotificationsSettingUpdaterTest { // Then coVerify { fakeUpdateEnableNotificationsSettingOnChangeUseCase.execute(aSession) } } - - @Test - fun `given a session when calling onSessionStarted then update account data on background sync preference change`() = runTest { - // Given - val aSession = FakeSession() - every { aSession.coroutineScope } returns this - coJustRun { fakeUpdateEnableNotificationsSettingOnChangeUseCase.execute(any()) } - coJustRun { fakeUpdateNotificationSettingsAccountDataUseCase.execute(any()) } - fakeVectorPreferences.givenChangeOnPreference(VectorPreferences.SETTINGS_FDROID_BACKGROUND_SYNC_MODE) - - // When - notificationsSettingUpdater.onSessionStarted(aSession) - advanceUntilIdle() - - // Then - coVerify { fakeUpdateNotificationSettingsAccountDataUseCase.execute(aSession) } - } - - @Test - fun `given a session when calling onSessionStarted then account data is not updated on other preference change`() = runTest { - // Given - val aSession = FakeSession() - every { aSession.coroutineScope } returns this - coJustRun { fakeUpdateEnableNotificationsSettingOnChangeUseCase.execute(any()) } - coJustRun { fakeUpdateNotificationSettingsAccountDataUseCase.execute(any()) } - fakeVectorPreferences.givenChangeOnPreference("key") - - // When - notificationsSettingUpdater.onSessionStarted(aSession) - advanceUntilIdle() - - // Then - coVerify(inverse = true) { fakeUpdateNotificationSettingsAccountDataUseCase.execute(aSession) } - } }