diff --git a/appnav/src/main/kotlin/io/element/android/appnav/loggedin/LoggedInPresenter.kt b/appnav/src/main/kotlin/io/element/android/appnav/loggedin/LoggedInPresenter.kt index f1c28b7a82..91f5d7da19 100644 --- a/appnav/src/main/kotlin/io/element/android/appnav/loggedin/LoggedInPresenter.kt +++ b/appnav/src/main/kotlin/io/element/android/appnav/loggedin/LoggedInPresenter.kt @@ -147,7 +147,7 @@ class LoggedInPresenter @Inject constructor( .also { pusherRegistrationState.value = AsyncData.Failure(PusherRegistrationFailure.NoDistributorsAvailable()) } pushService.registerWith(matrixClient, pushProvider, distributor) } else { - val currentPushDistributor = currentPushProvider.getCurrentDistributor(matrixClient) + val currentPushDistributor = currentPushProvider.getCurrentDistributor(matrixClient.sessionId) if (currentPushDistributor == null) { Timber.tag(pusherTag.value).d("Register with the first available distributor") val distributor = currentPushProvider.getDistributors().firstOrNull() 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 66574f4c28..b245b9ff9a 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 @@ -93,7 +93,7 @@ class NotificationSettingsPresenter @Inject constructor( LaunchedEffect(refreshPushProvider) { val p = pushService.getCurrentPushProvider() - val name = p?.getCurrentDistributor(matrixClient)?.name + val name = p?.getCurrentDistributor(matrixClient.sessionId)?.name currentDistributorName = if (name != null) { AsyncData.Success(name) } else { diff --git a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/DefaultPushService.kt b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/DefaultPushService.kt index 262d8901ef..4e91940bdc 100644 --- a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/DefaultPushService.kt +++ b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/DefaultPushService.kt @@ -58,7 +58,7 @@ class DefaultPushService @Inject constructor( val userPushStore = userPushStoreFactory.getOrCreate(matrixClient.sessionId) val currentPushProviderName = userPushStore.getPushProviderName() val currentPushProvider = pushProviders.find { it.name == currentPushProviderName } - val currentDistributorValue = currentPushProvider?.getCurrentDistributor(matrixClient)?.value + val currentDistributorValue = currentPushProvider?.getCurrentDistributor(matrixClient.sessionId)?.value if (currentPushProviderName != pushProvider.name || currentDistributorValue != distributor.value) { // Unregister previous one if any currentPushProvider diff --git a/libraries/pushproviders/api/src/main/kotlin/io/element/android/libraries/pushproviders/api/PushProvider.kt b/libraries/pushproviders/api/src/main/kotlin/io/element/android/libraries/pushproviders/api/PushProvider.kt index c5a436985e..3c82113798 100644 --- a/libraries/pushproviders/api/src/main/kotlin/io/element/android/libraries/pushproviders/api/PushProvider.kt +++ b/libraries/pushproviders/api/src/main/kotlin/io/element/android/libraries/pushproviders/api/PushProvider.kt @@ -37,7 +37,7 @@ interface PushProvider { /** * Return the current distributor, or null if none. */ - suspend fun getCurrentDistributor(matrixClient: MatrixClient): Distributor? + suspend fun getCurrentDistributor(sessionId: SessionId): Distributor? /** * Unregister the pusher. diff --git a/libraries/pushproviders/firebase/src/main/kotlin/io/element/android/libraries/pushproviders/firebase/FirebasePushProvider.kt b/libraries/pushproviders/firebase/src/main/kotlin/io/element/android/libraries/pushproviders/firebase/FirebasePushProvider.kt index 6f3d256d88..9b384a6e65 100644 --- a/libraries/pushproviders/firebase/src/main/kotlin/io/element/android/libraries/pushproviders/firebase/FirebasePushProvider.kt +++ b/libraries/pushproviders/firebase/src/main/kotlin/io/element/android/libraries/pushproviders/firebase/FirebasePushProvider.kt @@ -52,7 +52,7 @@ class FirebasePushProvider @Inject constructor( ) } - override suspend fun getCurrentDistributor(matrixClient: MatrixClient) = firebaseDistributor + override suspend fun getCurrentDistributor(sessionId: SessionId) = firebaseDistributor override suspend fun unregister(matrixClient: MatrixClient): Result { val pushKey = firebaseStore.getFcmToken() diff --git a/libraries/pushproviders/firebase/src/test/kotlin/io/element/android/libraries/pushproviders/firebase/FirebasePushProviderTest.kt b/libraries/pushproviders/firebase/src/test/kotlin/io/element/android/libraries/pushproviders/firebase/FirebasePushProviderTest.kt index db0fc85e94..b5bac64b09 100644 --- a/libraries/pushproviders/firebase/src/test/kotlin/io/element/android/libraries/pushproviders/firebase/FirebasePushProviderTest.kt +++ b/libraries/pushproviders/firebase/src/test/kotlin/io/element/android/libraries/pushproviders/firebase/FirebasePushProviderTest.kt @@ -48,9 +48,9 @@ class FirebasePushProviderTest { } @Test - fun `getCurrentDistributor always return the unique distributor`() = runTest { + fun `getCurrentDistributor always returns the unique distributor`() = runTest { val firebasePushProvider = createFirebasePushProvider() - val result = firebasePushProvider.getCurrentDistributor(FakeMatrixClient()) + val result = firebasePushProvider.getCurrentDistributor(A_SESSION_ID) assertThat(result).isEqualTo(Distributor("Firebase", "Firebase")) } diff --git a/libraries/pushproviders/test/src/main/kotlin/io/element/android/libraries/pushproviders/test/FakePushProvider.kt b/libraries/pushproviders/test/src/main/kotlin/io/element/android/libraries/pushproviders/test/FakePushProvider.kt index 076d89076f..4d8006b9e3 100644 --- a/libraries/pushproviders/test/src/main/kotlin/io/element/android/libraries/pushproviders/test/FakePushProvider.kt +++ b/libraries/pushproviders/test/src/main/kotlin/io/element/android/libraries/pushproviders/test/FakePushProvider.kt @@ -32,7 +32,7 @@ class FakePushProvider( return registerWithResult(matrixClient, distributor) } - override suspend fun getCurrentDistributor(matrixClient: MatrixClient): Distributor? { + override suspend fun getCurrentDistributor(sessionId: SessionId): Distributor? { return currentDistributor() } diff --git a/libraries/pushproviders/unifiedpush/src/main/kotlin/io/element/android/libraries/pushproviders/unifiedpush/UnifiedPushProvider.kt b/libraries/pushproviders/unifiedpush/src/main/kotlin/io/element/android/libraries/pushproviders/unifiedpush/UnifiedPushProvider.kt index 329232231c..b598d3371e 100644 --- a/libraries/pushproviders/unifiedpush/src/main/kotlin/io/element/android/libraries/pushproviders/unifiedpush/UnifiedPushProvider.kt +++ b/libraries/pushproviders/unifiedpush/src/main/kotlin/io/element/android/libraries/pushproviders/unifiedpush/UnifiedPushProvider.kt @@ -41,8 +41,8 @@ class UnifiedPushProvider @Inject constructor( } } - override suspend fun getCurrentDistributor(matrixClient: MatrixClient): Distributor? { - val distributorValue = unifiedPushStore.getDistributorValue(matrixClient.sessionId) + override suspend fun getCurrentDistributor(sessionId: SessionId): Distributor? { + val distributorValue = unifiedPushStore.getDistributorValue(sessionId) return getDistributors().find { it.value == distributorValue } } diff --git a/libraries/pushproviders/unifiedpush/src/test/kotlin/io/element/android/libraries/pushproviders/unifiedpush/UnifiedPushProviderTest.kt b/libraries/pushproviders/unifiedpush/src/test/kotlin/io/element/android/libraries/pushproviders/unifiedpush/UnifiedPushProviderTest.kt index daf2506e06..8282cbcbe6 100644 --- a/libraries/pushproviders/unifiedpush/src/test/kotlin/io/element/android/libraries/pushproviders/unifiedpush/UnifiedPushProviderTest.kt +++ b/libraries/pushproviders/unifiedpush/src/test/kotlin/io/element/android/libraries/pushproviders/unifiedpush/UnifiedPushProviderTest.kt @@ -162,7 +162,6 @@ class UnifiedPushProviderTest { @Test fun `getCurrentDistributor ok`() = runTest { val distributor = Distributor("value", "Name") - val matrixClient = FakeMatrixClient() val unifiedPushProvider = createUnifiedPushProvider( unifiedPushStore = FakeUnifiedPushStore( getDistributorValueResult = { distributor.value } @@ -174,14 +173,13 @@ class UnifiedPushProviderTest { ) ) ) - val result = unifiedPushProvider.getCurrentDistributor(matrixClient) + val result = unifiedPushProvider.getCurrentDistributor(A_SESSION_ID) assertThat(result).isEqualTo(distributor) } @Test fun `getCurrentDistributor not know`() = runTest { val distributor = Distributor("value", "Name") - val matrixClient = FakeMatrixClient() val unifiedPushProvider = createUnifiedPushProvider( unifiedPushStore = FakeUnifiedPushStore( getDistributorValueResult = { "unknown" } @@ -192,14 +190,13 @@ class UnifiedPushProviderTest { ) ) ) - val result = unifiedPushProvider.getCurrentDistributor(matrixClient) + val result = unifiedPushProvider.getCurrentDistributor(A_SESSION_ID) assertThat(result).isNull() } @Test fun `getCurrentDistributor not found`() = runTest { val distributor = Distributor("value", "Name") - val matrixClient = FakeMatrixClient() val unifiedPushProvider = createUnifiedPushProvider( unifiedPushStore = FakeUnifiedPushStore( getDistributorValueResult = { distributor.value } @@ -208,7 +205,7 @@ class UnifiedPushProviderTest { getDistributorsResult = emptyList() ) ) - val result = unifiedPushProvider.getCurrentDistributor(matrixClient) + val result = unifiedPushProvider.getCurrentDistributor(A_SESSION_ID) assertThat(result).isNull() }