Change signature of getCurrentDistributor.
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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<Unit> {
|
||||
val pushKey = firebaseStore.getFcmToken()
|
||||
|
||||
@@ -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"))
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
|
||||
@@ -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 }
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user