From 2c25efc36ade1cc2fd272e94ff62f00051f34960 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Tue, 21 Sep 2021 12:06:26 +0100 Subject: [PATCH] making the removePusher more generic as it can handle email and http pushers - Updates the doc to reflect that to remove emails an appId of m.email is required --- .../android/sdk/api/session/pushers/PushersService.kt | 10 +++------- .../internal/session/pushers/DefaultPushersService.kt | 7 +------ .../java/im/vector/app/core/pushers/PushersManager.kt | 4 ++-- .../features/settings/push/PushGatewaysViewModel.kt | 2 +- 4 files changed, 7 insertions(+), 16 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/pushers/PushersService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/pushers/PushersService.kt index f2f74cb24b..ee9828fa63 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/pushers/PushersService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/pushers/PushersService.kt @@ -99,14 +99,10 @@ interface PushersService { eventId: String) /** - * Remove the http pusher + * Remove the pusher + * When the appId is m.email then an email address is expected in the pushkey */ - suspend fun removeHttpPusher(pushkey: String, appId: String) - - /** - * Remove the email pusher for a given email - */ - suspend fun removeEmailPusher(email: String) + suspend fun removePusher(pushkey: String, appId: String) /** * Get the current pushers, as a LiveData diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/DefaultPushersService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/DefaultPushersService.kt index be39eb7aba..a6336ff571 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/DefaultPushersService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/DefaultPushersService.kt @@ -114,16 +114,11 @@ internal class DefaultPushersService @Inject constructor( this.data?.url?.let { url -> if ("/_matrix/push/v1/notify" !in url) throw InvalidParameterException("url should contain '/_matrix/push/v1/notify'") } } - override suspend fun removeHttpPusher(pushkey: String, appId: String) { + override suspend fun removePusher(pushkey: String, appId: String) { val params = RemovePusherTask.Params(pushkey, appId) removePusherTask.execute(params) } - override suspend fun removeEmailPusher(email: String) { - val params = RemovePusherTask.Params(email, "m.email") - removePusherTask.execute(params) - } - override fun getPushersLive(): LiveData> { return monarchy.findAllMappedWithChanges( { realm -> PusherEntity.where(realm) }, diff --git a/vector/src/main/java/im/vector/app/core/pushers/PushersManager.kt b/vector/src/main/java/im/vector/app/core/pushers/PushersManager.kt index 248e03161b..3f77e6a422 100644 --- a/vector/src/main/java/im/vector/app/core/pushers/PushersManager.kt +++ b/vector/src/main/java/im/vector/app/core/pushers/PushersManager.kt @@ -75,12 +75,12 @@ class PushersManager @Inject constructor( suspend fun unregisterEmailPusher(email: String) { val currentSession = activeSessionHolder.getSafeActiveSession() ?: return - currentSession.removeEmailPusher(email) + currentSession.removePusher(email, appId = "m.email") } suspend fun unregisterPusher(pushKey: String) { val currentSession = activeSessionHolder.getSafeActiveSession() ?: return - currentSession.removeHttpPusher(pushKey, stringProvider.getString(R.string.pusher_app_id)) + currentSession.removePusher(pushKey, stringProvider.getString(R.string.pusher_app_id)) } companion object { diff --git a/vector/src/main/java/im/vector/app/features/settings/push/PushGatewaysViewModel.kt b/vector/src/main/java/im/vector/app/features/settings/push/PushGatewaysViewModel.kt index 9910526878..c3f799730c 100644 --- a/vector/src/main/java/im/vector/app/features/settings/push/PushGatewaysViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/settings/push/PushGatewaysViewModel.kt @@ -79,7 +79,7 @@ class PushGatewaysViewModel @AssistedInject constructor(@Assisted initialState: private fun removePusher(pusher: Pusher) { viewModelScope.launch { - session.removeHttpPusher(pusher.pushKey, pusher.appId) + session.removePusher(pusher.pushKey, pusher.appId) } }