Replacing unregister method by usecase
This commit is contained in:
parent
4dbca7858c
commit
2890f41f30
@ -19,7 +19,7 @@ package im.vector.app.core.di
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import im.vector.app.ActiveSessionDataSource
|
import im.vector.app.ActiveSessionDataSource
|
||||||
import im.vector.app.core.extensions.startSyncing
|
import im.vector.app.core.extensions.startSyncing
|
||||||
import im.vector.app.core.pushers.UnifiedPushHelper
|
import im.vector.app.core.pushers.UnregisterUnifiedPushUseCase
|
||||||
import im.vector.app.core.services.GuardServiceStarter
|
import im.vector.app.core.services.GuardServiceStarter
|
||||||
import im.vector.app.core.session.ConfigureAndStartSessionUseCase
|
import im.vector.app.core.session.ConfigureAndStartSessionUseCase
|
||||||
import im.vector.app.features.call.webrtc.WebRtcCallManager
|
import im.vector.app.features.call.webrtc.WebRtcCallManager
|
||||||
@ -46,12 +46,12 @@ class ActiveSessionHolder @Inject constructor(
|
|||||||
private val pushRuleTriggerListener: PushRuleTriggerListener,
|
private val pushRuleTriggerListener: PushRuleTriggerListener,
|
||||||
private val sessionListener: SessionListener,
|
private val sessionListener: SessionListener,
|
||||||
private val imageManager: ImageManager,
|
private val imageManager: ImageManager,
|
||||||
private val unifiedPushHelper: UnifiedPushHelper,
|
|
||||||
private val guardServiceStarter: GuardServiceStarter,
|
private val guardServiceStarter: GuardServiceStarter,
|
||||||
private val sessionInitializer: SessionInitializer,
|
private val sessionInitializer: SessionInitializer,
|
||||||
private val applicationContext: Context,
|
private val applicationContext: Context,
|
||||||
private val authenticationService: AuthenticationService,
|
private val authenticationService: AuthenticationService,
|
||||||
private val configureAndStartSessionUseCase: ConfigureAndStartSessionUseCase,
|
private val configureAndStartSessionUseCase: ConfigureAndStartSessionUseCase,
|
||||||
|
private val unregisterUnifiedPushUseCase: UnregisterUnifiedPushUseCase,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
private var activeSessionReference: AtomicReference<Session?> = AtomicReference()
|
private var activeSessionReference: AtomicReference<Session?> = AtomicReference()
|
||||||
@ -85,7 +85,7 @@ class ActiveSessionHolder @Inject constructor(
|
|||||||
incomingVerificationRequestHandler.stop()
|
incomingVerificationRequestHandler.stop()
|
||||||
pushRuleTriggerListener.stop()
|
pushRuleTriggerListener.stop()
|
||||||
// No need to unregister the pusher, the sign out will (should?) do it server side.
|
// No need to unregister the pusher, the sign out will (should?) do it server side.
|
||||||
unifiedPushHelper.unregister(pushersManager = null)
|
unregisterUnifiedPushUseCase.execute(pushersManager = null)
|
||||||
guardServiceStarter.stop()
|
guardServiceStarter.stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,7 +213,7 @@ class UnifiedPushHelper @Inject constructor(
|
|||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO remove and replace by use case
|
// TODO remove
|
||||||
suspend fun unregister(pushersManager: PushersManager? = null) {
|
suspend fun unregister(pushersManager: PushersManager? = null) {
|
||||||
val mode = BackgroundSyncMode.FDROID_BACKGROUND_SYNC_MODE_FOR_REALTIME
|
val mode = BackgroundSyncMode.FDROID_BACKGROUND_SYNC_MODE_FOR_REALTIME
|
||||||
vectorPreferences.setFdroidSyncBackgroundMode(mode)
|
vectorPreferences.setFdroidSyncBackgroundMode(mode)
|
||||||
|
@ -26,20 +26,19 @@ import javax.inject.Inject
|
|||||||
|
|
||||||
class UnregisterUnifiedPushUseCase @Inject constructor(
|
class UnregisterUnifiedPushUseCase @Inject constructor(
|
||||||
@ApplicationContext private val context: Context,
|
@ApplicationContext private val context: Context,
|
||||||
private val pushersManager: PushersManager,
|
|
||||||
private val vectorPreferences: VectorPreferences,
|
private val vectorPreferences: VectorPreferences,
|
||||||
private val unifiedPushStore: UnifiedPushStore,
|
private val unifiedPushStore: UnifiedPushStore,
|
||||||
private val unifiedPushHelper: UnifiedPushHelper,
|
private val unifiedPushHelper: UnifiedPushHelper,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
// TODO add unit tests
|
// TODO add unit tests
|
||||||
suspend fun execute() {
|
suspend fun execute(pushersManager: PushersManager?) {
|
||||||
val mode = BackgroundSyncMode.FDROID_BACKGROUND_SYNC_MODE_FOR_REALTIME
|
val mode = BackgroundSyncMode.FDROID_BACKGROUND_SYNC_MODE_FOR_REALTIME
|
||||||
vectorPreferences.setFdroidSyncBackgroundMode(mode)
|
vectorPreferences.setFdroidSyncBackgroundMode(mode)
|
||||||
try {
|
try {
|
||||||
unifiedPushHelper.getEndpointOrToken()?.let {
|
unifiedPushHelper.getEndpointOrToken()?.let {
|
||||||
Timber.d("Removing $it")
|
Timber.d("Removing $it")
|
||||||
pushersManager.unregisterPusher(it)
|
pushersManager?.unregisterPusher(it)
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Timber.d(e, "Probably unregistering a non existing pusher")
|
Timber.d(e, "Probably unregistering a non existing pusher")
|
||||||
|
@ -18,26 +18,27 @@ package im.vector.app.features.settings.notifications
|
|||||||
|
|
||||||
import im.vector.app.core.di.ActiveSessionHolder
|
import im.vector.app.core.di.ActiveSessionHolder
|
||||||
import im.vector.app.core.pushers.PushersManager
|
import im.vector.app.core.pushers.PushersManager
|
||||||
import im.vector.app.core.pushers.UnifiedPushHelper
|
import im.vector.app.core.pushers.UnregisterUnifiedPushUseCase
|
||||||
import im.vector.app.features.settings.devices.v2.notification.CheckIfCanTogglePushNotificationsViaPusherUseCase
|
import im.vector.app.features.settings.devices.v2.notification.CheckIfCanTogglePushNotificationsViaPusherUseCase
|
||||||
import im.vector.app.features.settings.devices.v2.notification.TogglePushNotificationUseCase
|
import im.vector.app.features.settings.devices.v2.notification.TogglePushNotificationUseCase
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class DisableNotificationsForCurrentSessionUseCase @Inject constructor(
|
class DisableNotificationsForCurrentSessionUseCase @Inject constructor(
|
||||||
private val activeSessionHolder: ActiveSessionHolder,
|
private val activeSessionHolder: ActiveSessionHolder,
|
||||||
private val unifiedPushHelper: UnifiedPushHelper,
|
|
||||||
private val pushersManager: PushersManager,
|
private val pushersManager: PushersManager,
|
||||||
private val checkIfCanTogglePushNotificationsViaPusherUseCase: CheckIfCanTogglePushNotificationsViaPusherUseCase,
|
private val checkIfCanTogglePushNotificationsViaPusherUseCase: CheckIfCanTogglePushNotificationsViaPusherUseCase,
|
||||||
private val togglePushNotificationUseCase: TogglePushNotificationUseCase,
|
private val togglePushNotificationUseCase: TogglePushNotificationUseCase,
|
||||||
|
private val unregisterUnifiedPushUseCase: UnregisterUnifiedPushUseCase,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
// TODO update unit tests
|
||||||
suspend fun execute() {
|
suspend fun execute() {
|
||||||
val session = activeSessionHolder.getSafeActiveSession() ?: return
|
val session = activeSessionHolder.getSafeActiveSession() ?: return
|
||||||
val deviceId = session.sessionParams.deviceId ?: return
|
val deviceId = session.sessionParams.deviceId ?: return
|
||||||
if (checkIfCanTogglePushNotificationsViaPusherUseCase.execute(session)) {
|
if (checkIfCanTogglePushNotificationsViaPusherUseCase.execute(session)) {
|
||||||
togglePushNotificationUseCase.execute(deviceId, enabled = false)
|
togglePushNotificationUseCase.execute(deviceId, enabled = false)
|
||||||
} else {
|
} else {
|
||||||
unifiedPushHelper.unregister(pushersManager)
|
unregisterUnifiedPushUseCase.execute(pushersManager)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user