diff --git a/vector/src/main/java/im/vector/app/core/session/ConfigureAndStartSessionUseCase.kt b/vector/src/main/java/im/vector/app/core/session/ConfigureAndStartSessionUseCase.kt index dfcb92af24..a5e1fe68bd 100644 --- a/vector/src/main/java/im/vector/app/core/session/ConfigureAndStartSessionUseCase.kt +++ b/vector/src/main/java/im/vector/app/core/session/ConfigureAndStartSessionUseCase.kt @@ -21,6 +21,7 @@ import dagger.hilt.android.qualifiers.ApplicationContext import im.vector.app.core.extensions.startSyncing import im.vector.app.core.session.clientinfo.UpdateMatrixClientInfoUseCase import im.vector.app.features.call.webrtc.WebRtcCallManager +import im.vector.app.features.settings.VectorPreferences import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.sync.FilterService import timber.log.Timber @@ -30,6 +31,7 @@ class ConfigureAndStartSessionUseCase @Inject constructor( @ApplicationContext private val context: Context, private val webRtcCallManager: WebRtcCallManager, private val updateMatrixClientInfoUseCase: UpdateMatrixClientInfoUseCase, + private val vectorPreferences: VectorPreferences, ) { suspend fun execute(session: Session, startSyncing: Boolean = true) { @@ -41,6 +43,8 @@ class ConfigureAndStartSessionUseCase @Inject constructor( } session.pushersService().refreshPushers() webRtcCallManager.checkForProtocolsSupportIfNeeded() - updateMatrixClientInfoUseCase.execute(session) + if (vectorPreferences.isClientInfoRecordingEnabled()) { + updateMatrixClientInfoUseCase.execute(session) + } } } diff --git a/vector/src/test/java/im/vector/app/core/session/ConfigureAndStartSessionUseCaseTest.kt b/vector/src/test/java/im/vector/app/core/session/ConfigureAndStartSessionUseCaseTest.kt index b879806930..5e1cba0b24 100644 --- a/vector/src/test/java/im/vector/app/core/session/ConfigureAndStartSessionUseCaseTest.kt +++ b/vector/src/test/java/im/vector/app/core/session/ConfigureAndStartSessionUseCaseTest.kt @@ -20,6 +20,7 @@ import im.vector.app.core.extensions.startSyncing import im.vector.app.core.session.clientinfo.UpdateMatrixClientInfoUseCase import im.vector.app.test.fakes.FakeContext import im.vector.app.test.fakes.FakeSession +import im.vector.app.test.fakes.FakeVectorPreferences import im.vector.app.test.fakes.FakeWebRtcCallManager import io.mockk.coJustRun import io.mockk.coVerify @@ -41,11 +42,13 @@ class ConfigureAndStartSessionUseCaseTest { private val fakeContext = FakeContext() private val fakeWebRtcCallManager = FakeWebRtcCallManager() private val fakeUpdateMatrixClientInfoUseCase = mockk() + private val fakeVectorPreferences = FakeVectorPreferences() private val configureAndStartSessionUseCase = ConfigureAndStartSessionUseCase( context = fakeContext.instance, webRtcCallManager = fakeWebRtcCallManager.instance, updateMatrixClientInfoUseCase = fakeUpdateMatrixClientInfoUseCase, + vectorPreferences = fakeVectorPreferences.instance, ) @Before @@ -59,11 +62,12 @@ class ConfigureAndStartSessionUseCaseTest { } @Test - fun `given a session and start sync needed when configuring and starting the session then it should be configured properly`() = runTest { + fun `given start sync needed and client info recording enabled when configuring and starting the session then it should be configured properly`() = runTest { // Given val fakeSession = givenASession() fakeWebRtcCallManager.givenCheckForProtocolsSupportIfNeededSucceeds() coJustRun { fakeUpdateMatrixClientInfoUseCase.execute(any()) } + fakeVectorPreferences.givenIsClientInfoRecordingEnabled(isEnabled = true) // When configureAndStartSessionUseCase.execute(fakeSession, startSyncing = true) @@ -76,12 +80,32 @@ class ConfigureAndStartSessionUseCaseTest { coVerify { fakeUpdateMatrixClientInfoUseCase.execute(fakeSession) } } + @Test + fun `given start sync needed and client info recording disabled when configuring and starting the session then it should be configured properly`() = runTest { + // Given + val fakeSession = givenASession() + fakeWebRtcCallManager.givenCheckForProtocolsSupportIfNeededSucceeds() + coJustRun { fakeUpdateMatrixClientInfoUseCase.execute(any()) } + fakeVectorPreferences.givenIsClientInfoRecordingEnabled(isEnabled = false) + + // When + configureAndStartSessionUseCase.execute(fakeSession, startSyncing = true) + + // Then + verify { fakeSession.startSyncing(fakeContext.instance) } + fakeSession.fakeFilterService.verifySetFilter(FilterService.FilterPreset.ElementFilter) + fakeSession.fakePushersService.verifyRefreshPushers() + fakeWebRtcCallManager.verifyCheckForProtocolsSupportIfNeeded() + coVerify(inverse = true) { fakeUpdateMatrixClientInfoUseCase.execute(fakeSession) } + } + @Test fun `given a session and no start sync needed when configuring and starting the session then it should be configured properly`() = runTest { // Given val fakeSession = givenASession() fakeWebRtcCallManager.givenCheckForProtocolsSupportIfNeededSucceeds() coJustRun { fakeUpdateMatrixClientInfoUseCase.execute(any()) } + fakeVectorPreferences.givenIsClientInfoRecordingEnabled(isEnabled = true) // When configureAndStartSessionUseCase.execute(fakeSession, startSyncing = false) diff --git a/vector/src/test/java/im/vector/app/test/fakes/FakeVectorPreferences.kt b/vector/src/test/java/im/vector/app/test/fakes/FakeVectorPreferences.kt index bc761d9016..8b0630c24f 100644 --- a/vector/src/test/java/im/vector/app/test/fakes/FakeVectorPreferences.kt +++ b/vector/src/test/java/im/vector/app/test/fakes/FakeVectorPreferences.kt @@ -36,4 +36,8 @@ class FakeVectorPreferences { fun verifySetSpaceBackstack(value: List, inverse: Boolean = false) { verify(inverse = inverse) { instance.setSpaceBackstack(value) } } + + fun givenIsClientInfoRecordingEnabled(isEnabled: Boolean) { + every { instance.isClientInfoRecordingEnabled() } returns isEnabled + } }