Ignore local errors when unregistering UnifiedPush, to not block switching to another push provider.
This commit is contained in:
parent
d275ed9150
commit
35e14a3d46
2 changed files with 30 additions and 5 deletions
|
|
@ -23,6 +23,7 @@ import io.element.android.libraries.di.ApplicationContext
|
||||||
import io.element.android.libraries.matrix.api.MatrixClient
|
import io.element.android.libraries.matrix.api.MatrixClient
|
||||||
import io.element.android.libraries.pushproviders.api.PusherSubscriber
|
import io.element.android.libraries.pushproviders.api.PusherSubscriber
|
||||||
import org.unifiedpush.android.connector.UnifiedPush
|
import org.unifiedpush.android.connector.UnifiedPush
|
||||||
|
import timber.log.Timber
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
interface UnregisterUnifiedPushUseCase {
|
interface UnregisterUnifiedPushUseCase {
|
||||||
|
|
@ -39,7 +40,11 @@ class DefaultUnregisterUnifiedPushUseCase @Inject constructor(
|
||||||
val endpoint = unifiedPushStore.getEndpoint(clientSecret)
|
val endpoint = unifiedPushStore.getEndpoint(clientSecret)
|
||||||
val gateway = unifiedPushStore.getPushGateway(clientSecret)
|
val gateway = unifiedPushStore.getPushGateway(clientSecret)
|
||||||
if (endpoint == null || gateway == null) {
|
if (endpoint == null || gateway == null) {
|
||||||
return Result.failure(IllegalStateException("No endpoint or gateway found for client secret"))
|
Timber.w("No endpoint or gateway found for client secret")
|
||||||
|
// Ensure we don't have any remaining data, but ignore this error
|
||||||
|
unifiedPushStore.storeUpEndpoint(clientSecret, null)
|
||||||
|
unifiedPushStore.storePushGateway(clientSecret, null)
|
||||||
|
return Result.success(Unit)
|
||||||
}
|
}
|
||||||
return pusherSubscriber.unregisterPusher(matrixClient, endpoint, gateway)
|
return pusherSubscriber.unregisterPusher(matrixClient, endpoint, gateway)
|
||||||
.onSuccess {
|
.onSuccess {
|
||||||
|
|
|
||||||
|
|
@ -64,29 +64,49 @@ class DefaultUnregisterUnifiedPushUseCaseTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `test un registration error - no endpoint`() = runTest {
|
fun `test un registration error - no endpoint - will not unregister but return success`() = runTest {
|
||||||
val matrixClient = FakeMatrixClient()
|
val matrixClient = FakeMatrixClient()
|
||||||
|
val storeUpEndpointResult = lambdaRecorder { _: String, _: String? -> }
|
||||||
|
val storePushGatewayResult = lambdaRecorder { _: String, _: String? -> }
|
||||||
val useCase = createDefaultUnregisterUnifiedPushUseCase(
|
val useCase = createDefaultUnregisterUnifiedPushUseCase(
|
||||||
unifiedPushStore = FakeUnifiedPushStore(
|
unifiedPushStore = FakeUnifiedPushStore(
|
||||||
getEndpointResult = { null },
|
getEndpointResult = { null },
|
||||||
getPushGatewayResult = { "aGateway" },
|
getPushGatewayResult = { "aGateway" },
|
||||||
|
storeUpEndpointResult = storeUpEndpointResult,
|
||||||
|
storePushGatewayResult = storePushGatewayResult,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
val result = useCase.execute(matrixClient, A_SECRET)
|
val result = useCase.execute(matrixClient, A_SECRET)
|
||||||
assertThat(result.isFailure).isTrue()
|
assertThat(result.isSuccess).isTrue()
|
||||||
|
storeUpEndpointResult.assertions()
|
||||||
|
.isCalledOnce()
|
||||||
|
.with(value(A_SECRET), value(null))
|
||||||
|
storePushGatewayResult.assertions()
|
||||||
|
.isCalledOnce()
|
||||||
|
.with(value(A_SECRET), value(null))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `test un registration error - no gateway`() = runTest {
|
fun `test un registration error - no gateway - will not unregister but return success`() = runTest {
|
||||||
val matrixClient = FakeMatrixClient()
|
val matrixClient = FakeMatrixClient()
|
||||||
|
val storeUpEndpointResult = lambdaRecorder { _: String, _: String? -> }
|
||||||
|
val storePushGatewayResult = lambdaRecorder { _: String, _: String? -> }
|
||||||
val useCase = createDefaultUnregisterUnifiedPushUseCase(
|
val useCase = createDefaultUnregisterUnifiedPushUseCase(
|
||||||
unifiedPushStore = FakeUnifiedPushStore(
|
unifiedPushStore = FakeUnifiedPushStore(
|
||||||
getEndpointResult = { "aEndpoint" },
|
getEndpointResult = { "aEndpoint" },
|
||||||
getPushGatewayResult = { null },
|
getPushGatewayResult = { null },
|
||||||
|
storeUpEndpointResult = storeUpEndpointResult,
|
||||||
|
storePushGatewayResult = storePushGatewayResult,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
val result = useCase.execute(matrixClient, A_SECRET)
|
val result = useCase.execute(matrixClient, A_SECRET)
|
||||||
assertThat(result.isFailure).isTrue()
|
assertThat(result.isSuccess).isTrue()
|
||||||
|
storeUpEndpointResult.assertions()
|
||||||
|
.isCalledOnce()
|
||||||
|
.with(value(A_SECRET), value(null))
|
||||||
|
storePushGatewayResult.assertions()
|
||||||
|
.isCalledOnce()
|
||||||
|
.with(value(A_SECRET), value(null))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue