Change signature of getCurrentDistributor.
This commit is contained in:
parent
40e727f2e4
commit
8e3c44b60b
9 changed files with 13 additions and 16 deletions
|
|
@ -147,7 +147,7 @@ class LoggedInPresenter @Inject constructor(
|
||||||
.also { pusherRegistrationState.value = AsyncData.Failure(PusherRegistrationFailure.NoDistributorsAvailable()) }
|
.also { pusherRegistrationState.value = AsyncData.Failure(PusherRegistrationFailure.NoDistributorsAvailable()) }
|
||||||
pushService.registerWith(matrixClient, pushProvider, distributor)
|
pushService.registerWith(matrixClient, pushProvider, distributor)
|
||||||
} else {
|
} else {
|
||||||
val currentPushDistributor = currentPushProvider.getCurrentDistributor(matrixClient)
|
val currentPushDistributor = currentPushProvider.getCurrentDistributor(matrixClient.sessionId)
|
||||||
if (currentPushDistributor == null) {
|
if (currentPushDistributor == null) {
|
||||||
Timber.tag(pusherTag.value).d("Register with the first available distributor")
|
Timber.tag(pusherTag.value).d("Register with the first available distributor")
|
||||||
val distributor = currentPushProvider.getDistributors().firstOrNull()
|
val distributor = currentPushProvider.getDistributors().firstOrNull()
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,7 @@ class NotificationSettingsPresenter @Inject constructor(
|
||||||
|
|
||||||
LaunchedEffect(refreshPushProvider) {
|
LaunchedEffect(refreshPushProvider) {
|
||||||
val p = pushService.getCurrentPushProvider()
|
val p = pushService.getCurrentPushProvider()
|
||||||
val name = p?.getCurrentDistributor(matrixClient)?.name
|
val name = p?.getCurrentDistributor(matrixClient.sessionId)?.name
|
||||||
currentDistributorName = if (name != null) {
|
currentDistributorName = if (name != null) {
|
||||||
AsyncData.Success(name)
|
AsyncData.Success(name)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ class DefaultPushService @Inject constructor(
|
||||||
val userPushStore = userPushStoreFactory.getOrCreate(matrixClient.sessionId)
|
val userPushStore = userPushStoreFactory.getOrCreate(matrixClient.sessionId)
|
||||||
val currentPushProviderName = userPushStore.getPushProviderName()
|
val currentPushProviderName = userPushStore.getPushProviderName()
|
||||||
val currentPushProvider = pushProviders.find { it.name == currentPushProviderName }
|
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) {
|
if (currentPushProviderName != pushProvider.name || currentDistributorValue != distributor.value) {
|
||||||
// Unregister previous one if any
|
// Unregister previous one if any
|
||||||
currentPushProvider
|
currentPushProvider
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ interface PushProvider {
|
||||||
/**
|
/**
|
||||||
* Return the current distributor, or null if none.
|
* Return the current distributor, or null if none.
|
||||||
*/
|
*/
|
||||||
suspend fun getCurrentDistributor(matrixClient: MatrixClient): Distributor?
|
suspend fun getCurrentDistributor(sessionId: SessionId): Distributor?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unregister the pusher.
|
* 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> {
|
override suspend fun unregister(matrixClient: MatrixClient): Result<Unit> {
|
||||||
val pushKey = firebaseStore.getFcmToken()
|
val pushKey = firebaseStore.getFcmToken()
|
||||||
|
|
|
||||||
|
|
@ -48,9 +48,9 @@ class FirebasePushProviderTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `getCurrentDistributor always return the unique distributor`() = runTest {
|
fun `getCurrentDistributor always returns the unique distributor`() = runTest {
|
||||||
val firebasePushProvider = createFirebasePushProvider()
|
val firebasePushProvider = createFirebasePushProvider()
|
||||||
val result = firebasePushProvider.getCurrentDistributor(FakeMatrixClient())
|
val result = firebasePushProvider.getCurrentDistributor(A_SESSION_ID)
|
||||||
assertThat(result).isEqualTo(Distributor("Firebase", "Firebase"))
|
assertThat(result).isEqualTo(Distributor("Firebase", "Firebase"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ class FakePushProvider(
|
||||||
return registerWithResult(matrixClient, distributor)
|
return registerWithResult(matrixClient, distributor)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getCurrentDistributor(matrixClient: MatrixClient): Distributor? {
|
override suspend fun getCurrentDistributor(sessionId: SessionId): Distributor? {
|
||||||
return currentDistributor()
|
return currentDistributor()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,8 +41,8 @@ class UnifiedPushProvider @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getCurrentDistributor(matrixClient: MatrixClient): Distributor? {
|
override suspend fun getCurrentDistributor(sessionId: SessionId): Distributor? {
|
||||||
val distributorValue = unifiedPushStore.getDistributorValue(matrixClient.sessionId)
|
val distributorValue = unifiedPushStore.getDistributorValue(sessionId)
|
||||||
return getDistributors().find { it.value == distributorValue }
|
return getDistributors().find { it.value == distributorValue }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -162,7 +162,6 @@ class UnifiedPushProviderTest {
|
||||||
@Test
|
@Test
|
||||||
fun `getCurrentDistributor ok`() = runTest {
|
fun `getCurrentDistributor ok`() = runTest {
|
||||||
val distributor = Distributor("value", "Name")
|
val distributor = Distributor("value", "Name")
|
||||||
val matrixClient = FakeMatrixClient()
|
|
||||||
val unifiedPushProvider = createUnifiedPushProvider(
|
val unifiedPushProvider = createUnifiedPushProvider(
|
||||||
unifiedPushStore = FakeUnifiedPushStore(
|
unifiedPushStore = FakeUnifiedPushStore(
|
||||||
getDistributorValueResult = { distributor.value }
|
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)
|
assertThat(result).isEqualTo(distributor)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `getCurrentDistributor not know`() = runTest {
|
fun `getCurrentDistributor not know`() = runTest {
|
||||||
val distributor = Distributor("value", "Name")
|
val distributor = Distributor("value", "Name")
|
||||||
val matrixClient = FakeMatrixClient()
|
|
||||||
val unifiedPushProvider = createUnifiedPushProvider(
|
val unifiedPushProvider = createUnifiedPushProvider(
|
||||||
unifiedPushStore = FakeUnifiedPushStore(
|
unifiedPushStore = FakeUnifiedPushStore(
|
||||||
getDistributorValueResult = { "unknown" }
|
getDistributorValueResult = { "unknown" }
|
||||||
|
|
@ -192,14 +190,13 @@ class UnifiedPushProviderTest {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
val result = unifiedPushProvider.getCurrentDistributor(matrixClient)
|
val result = unifiedPushProvider.getCurrentDistributor(A_SESSION_ID)
|
||||||
assertThat(result).isNull()
|
assertThat(result).isNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `getCurrentDistributor not found`() = runTest {
|
fun `getCurrentDistributor not found`() = runTest {
|
||||||
val distributor = Distributor("value", "Name")
|
val distributor = Distributor("value", "Name")
|
||||||
val matrixClient = FakeMatrixClient()
|
|
||||||
val unifiedPushProvider = createUnifiedPushProvider(
|
val unifiedPushProvider = createUnifiedPushProvider(
|
||||||
unifiedPushStore = FakeUnifiedPushStore(
|
unifiedPushStore = FakeUnifiedPushStore(
|
||||||
getDistributorValueResult = { distributor.value }
|
getDistributorValueResult = { distributor.value }
|
||||||
|
|
@ -208,7 +205,7 @@ class UnifiedPushProviderTest {
|
||||||
getDistributorsResult = emptyList()
|
getDistributorsResult = emptyList()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
val result = unifiedPushProvider.getCurrentDistributor(matrixClient)
|
val result = unifiedPushProvider.getCurrentDistributor(A_SESSION_ID)
|
||||||
assertThat(result).isNull()
|
assertThat(result).isNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue