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 im.vector.app.ActiveSessionDataSource
 | 
			
		||||
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.session.ConfigureAndStartSessionUseCase
 | 
			
		||||
import im.vector.app.features.call.webrtc.WebRtcCallManager
 | 
			
		||||
@ -46,12 +46,12 @@ class ActiveSessionHolder @Inject constructor(
 | 
			
		||||
        private val pushRuleTriggerListener: PushRuleTriggerListener,
 | 
			
		||||
        private val sessionListener: SessionListener,
 | 
			
		||||
        private val imageManager: ImageManager,
 | 
			
		||||
        private val unifiedPushHelper: UnifiedPushHelper,
 | 
			
		||||
        private val guardServiceStarter: GuardServiceStarter,
 | 
			
		||||
        private val sessionInitializer: SessionInitializer,
 | 
			
		||||
        private val applicationContext: Context,
 | 
			
		||||
        private val authenticationService: AuthenticationService,
 | 
			
		||||
        private val configureAndStartSessionUseCase: ConfigureAndStartSessionUseCase,
 | 
			
		||||
        private val unregisterUnifiedPushUseCase: UnregisterUnifiedPushUseCase,
 | 
			
		||||
) {
 | 
			
		||||
 | 
			
		||||
    private var activeSessionReference: AtomicReference<Session?> = AtomicReference()
 | 
			
		||||
@ -85,7 +85,7 @@ class ActiveSessionHolder @Inject constructor(
 | 
			
		||||
        incomingVerificationRequestHandler.stop()
 | 
			
		||||
        pushRuleTriggerListener.stop()
 | 
			
		||||
        // 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()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -213,7 +213,7 @@ class UnifiedPushHelper @Inject constructor(
 | 
			
		||||
                .show()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // TODO remove and replace by use case
 | 
			
		||||
    // TODO remove
 | 
			
		||||
    suspend fun unregister(pushersManager: PushersManager? = null) {
 | 
			
		||||
        val mode = BackgroundSyncMode.FDROID_BACKGROUND_SYNC_MODE_FOR_REALTIME
 | 
			
		||||
        vectorPreferences.setFdroidSyncBackgroundMode(mode)
 | 
			
		||||
 | 
			
		||||
@ -26,20 +26,19 @@ import javax.inject.Inject
 | 
			
		||||
 | 
			
		||||
class UnregisterUnifiedPushUseCase @Inject constructor(
 | 
			
		||||
        @ApplicationContext private val context: Context,
 | 
			
		||||
        private val pushersManager: PushersManager,
 | 
			
		||||
        private val vectorPreferences: VectorPreferences,
 | 
			
		||||
        private val unifiedPushStore: UnifiedPushStore,
 | 
			
		||||
        private val unifiedPushHelper: UnifiedPushHelper,
 | 
			
		||||
) {
 | 
			
		||||
 | 
			
		||||
    // TODO add unit tests
 | 
			
		||||
    suspend fun execute() {
 | 
			
		||||
    suspend fun execute(pushersManager: PushersManager?) {
 | 
			
		||||
        val mode = BackgroundSyncMode.FDROID_BACKGROUND_SYNC_MODE_FOR_REALTIME
 | 
			
		||||
        vectorPreferences.setFdroidSyncBackgroundMode(mode)
 | 
			
		||||
        try {
 | 
			
		||||
            unifiedPushHelper.getEndpointOrToken()?.let {
 | 
			
		||||
                Timber.d("Removing $it")
 | 
			
		||||
                pushersManager.unregisterPusher(it)
 | 
			
		||||
                pushersManager?.unregisterPusher(it)
 | 
			
		||||
            }
 | 
			
		||||
        } catch (e: Exception) {
 | 
			
		||||
            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.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.TogglePushNotificationUseCase
 | 
			
		||||
import javax.inject.Inject
 | 
			
		||||
 | 
			
		||||
class DisableNotificationsForCurrentSessionUseCase @Inject constructor(
 | 
			
		||||
        private val activeSessionHolder: ActiveSessionHolder,
 | 
			
		||||
        private val unifiedPushHelper: UnifiedPushHelper,
 | 
			
		||||
        private val pushersManager: PushersManager,
 | 
			
		||||
        private val checkIfCanTogglePushNotificationsViaPusherUseCase: CheckIfCanTogglePushNotificationsViaPusherUseCase,
 | 
			
		||||
        private val togglePushNotificationUseCase: TogglePushNotificationUseCase,
 | 
			
		||||
        private val unregisterUnifiedPushUseCase: UnregisterUnifiedPushUseCase,
 | 
			
		||||
) {
 | 
			
		||||
 | 
			
		||||
    // TODO update unit tests
 | 
			
		||||
    suspend fun execute() {
 | 
			
		||||
        val session = activeSessionHolder.getSafeActiveSession() ?: return
 | 
			
		||||
        val deviceId = session.sessionParams.deviceId ?: return
 | 
			
		||||
        if (checkIfCanTogglePushNotificationsViaPusherUseCase.execute(session)) {
 | 
			
		||||
            togglePushNotificationUseCase.execute(deviceId, enabled = false)
 | 
			
		||||
        } else {
 | 
			
		||||
            unifiedPushHelper.unregister(pushersManager)
 | 
			
		||||
            unregisterUnifiedPushUseCase.execute(pushersManager)
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user