mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-03-17 11:48:51 +03:00
using dedicated pusher removal methods for the different types of pushers
- also adds a separate removePusher which supports removing any type of pusher
This commit is contained in:
parent
7fd794bd7a
commit
4482cbdaa6
4 changed files with 32 additions and 8 deletions
|
@ -102,10 +102,22 @@ interface PushersService {
|
|||
eventId: String)
|
||||
|
||||
/**
|
||||
* Remove the pusher
|
||||
* When the appId is m.email then an email address is expected in the pushkey
|
||||
* Remove a registered pusher
|
||||
* @param pusher the pusher to remove, can be http or email
|
||||
*/
|
||||
suspend fun removePusher(pushkey: String, appId: String)
|
||||
suspend fun removePusher(pusher: Pusher)
|
||||
|
||||
/**
|
||||
* Remove a Http pusher by its pushkey and appId
|
||||
* @see addHttpPusher
|
||||
*/
|
||||
suspend fun removeHttpPusher(pushkey: String, appId: String)
|
||||
|
||||
/**
|
||||
* Remove an Email pusher
|
||||
* @see addEmailPusher
|
||||
*/
|
||||
suspend fun removeEmailPusher(email: String)
|
||||
|
||||
/**
|
||||
* Get the current pushers, as a LiveData
|
||||
|
|
|
@ -120,8 +120,20 @@ internal class DefaultPushersService @Inject constructor(
|
|||
data?.url?.let { url -> if ("/_matrix/push/v1/notify" !in url) throw InvalidParameterException("url should contain '/_matrix/push/v1/notify'") }
|
||||
}
|
||||
|
||||
override suspend fun removePusher(pushkey: String, appId: String) {
|
||||
val params = RemovePusherTask.Params(pushkey, appId)
|
||||
override suspend fun removePusher(pusher: Pusher) {
|
||||
removePusher(pusher.pushKey, pusher.appId)
|
||||
}
|
||||
|
||||
override suspend fun removeHttpPusher(pushkey: String, appId: String) {
|
||||
removePusher(pushkey, appId)
|
||||
}
|
||||
|
||||
override suspend fun removeEmailPusher(email: String) {
|
||||
removePusher(pushKey = email, Pusher.APP_ID_EMAIL)
|
||||
}
|
||||
|
||||
private suspend fun removePusher(pushKey: String, pushAppId: String) {
|
||||
val params = RemovePusherTask.Params(pushKey, pushAppId)
|
||||
removePusherTask.execute(params)
|
||||
}
|
||||
|
||||
|
|
|
@ -75,12 +75,12 @@ class PushersManager @Inject constructor(
|
|||
|
||||
suspend fun unregisterEmailPusher(email: String) {
|
||||
val currentSession = activeSessionHolder.getSafeActiveSession() ?: return
|
||||
currentSession.removePusher(email, appId = "m.email")
|
||||
currentSession.removeEmailPusher(email)
|
||||
}
|
||||
|
||||
suspend fun unregisterPusher(pushKey: String) {
|
||||
val currentSession = activeSessionHolder.getSafeActiveSession() ?: return
|
||||
currentSession.removePusher(pushKey, stringProvider.getString(R.string.pusher_app_id))
|
||||
currentSession.removeHttpPusher(pushKey, stringProvider.getString(R.string.pusher_app_id))
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
|
|
@ -79,7 +79,7 @@ class PushGatewaysViewModel @AssistedInject constructor(@Assisted initialState:
|
|||
private fun removePusher(pusher: Pusher) {
|
||||
viewModelScope.launch {
|
||||
kotlin.runCatching {
|
||||
session.removePusher(pusher.pushKey, pusher.appId)
|
||||
session.removePusher(pusher)
|
||||
}.onFailure {
|
||||
_viewEvents.post(PushGatewayViewEvents.RemovePusherFailed(it))
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue