Properly unregister from the ntfy app when the user logs out.
This commit is contained in:
parent
022cd93653
commit
7a7b5d2dd0
15 changed files with 110 additions and 77 deletions
|
|
@ -10,6 +10,7 @@ package io.element.android.libraries.pushproviders.unifiedpush
|
|||
import com.squareup.anvil.annotations.ContributesMultibinding
|
||||
import io.element.android.libraries.di.AppScope
|
||||
import io.element.android.libraries.matrix.api.MatrixClient
|
||||
import io.element.android.libraries.matrix.api.core.SessionId
|
||||
import io.element.android.libraries.pushproviders.api.CurrentUserPushConfig
|
||||
import io.element.android.libraries.pushproviders.api.Distributor
|
||||
import io.element.android.libraries.pushproviders.api.PushProvider
|
||||
|
|
@ -47,7 +48,12 @@ class UnifiedPushProvider @Inject constructor(
|
|||
|
||||
override suspend fun unregister(matrixClient: MatrixClient): Result<Unit> {
|
||||
val clientSecret = pushClientSecret.getSecretForUser(matrixClient.sessionId)
|
||||
return unRegisterUnifiedPushUseCase.execute(matrixClient, clientSecret)
|
||||
return unRegisterUnifiedPushUseCase.unregister(matrixClient, clientSecret)
|
||||
}
|
||||
|
||||
override suspend fun onSessionDeleted(sessionId: SessionId) {
|
||||
val clientSecret = pushClientSecret.getSecretForUser(sessionId)
|
||||
unRegisterUnifiedPushUseCase.cleanup(clientSecret)
|
||||
}
|
||||
|
||||
override suspend fun getCurrentUserPushConfig(): CurrentUserPushConfig? {
|
||||
|
|
|
|||
|
|
@ -18,7 +18,15 @@ import timber.log.Timber
|
|||
import javax.inject.Inject
|
||||
|
||||
interface UnregisterUnifiedPushUseCase {
|
||||
suspend fun execute(matrixClient: MatrixClient, clientSecret: String): Result<Unit>
|
||||
/**
|
||||
* Unregister the app from the homeserver, then from UnifiedPush.
|
||||
*/
|
||||
suspend fun unregister(matrixClient: MatrixClient, clientSecret: String): Result<Unit>
|
||||
|
||||
/**
|
||||
* Cleanup any remaining data for the given client secret and unregister the app from UnifiedPush.
|
||||
*/
|
||||
fun cleanup(clientSecret: String)
|
||||
}
|
||||
|
||||
@ContributesBinding(AppScope::class)
|
||||
|
|
@ -27,7 +35,7 @@ class DefaultUnregisterUnifiedPushUseCase @Inject constructor(
|
|||
private val unifiedPushStore: UnifiedPushStore,
|
||||
private val pusherSubscriber: PusherSubscriber,
|
||||
) : UnregisterUnifiedPushUseCase {
|
||||
override suspend fun execute(matrixClient: MatrixClient, clientSecret: String): Result<Unit> {
|
||||
override suspend fun unregister(matrixClient: MatrixClient, clientSecret: String): Result<Unit> {
|
||||
val endpoint = unifiedPushStore.getEndpoint(clientSecret)
|
||||
val gateway = unifiedPushStore.getPushGateway(clientSecret)
|
||||
if (endpoint == null || gateway == null) {
|
||||
|
|
@ -42,7 +50,7 @@ class DefaultUnregisterUnifiedPushUseCase @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private fun cleanup(clientSecret: String) {
|
||||
override fun cleanup(clientSecret: String) {
|
||||
unifiedPushStore.storeUpEndpoint(clientSecret, null)
|
||||
unifiedPushStore.storePushGateway(clientSecret, null)
|
||||
UnifiedPush.unregisterApp(context, clientSecret)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue