diff --git a/app/src/main/kotlin/com/x8bit/bitwarden/data/platform/manager/PushManagerImpl.kt b/app/src/main/kotlin/com/x8bit/bitwarden/data/platform/manager/PushManagerImpl.kt index feadfb2b97..9966586619 100644 --- a/app/src/main/kotlin/com/x8bit/bitwarden/data/platform/manager/PushManagerImpl.kt +++ b/app/src/main/kotlin/com/x8bit/bitwarden/data/platform/manager/PushManagerImpl.kt @@ -48,7 +48,7 @@ private val PUSH_TOKEN_UPDATE_DELAY: Duration = 7.days * Primary implementation of [PushManager]. */ @Suppress("LongParameterList") -class PushManagerImpl @Inject constructor( +internal class PushManagerImpl @Inject constructor( private val authDiskSource: AuthDiskSource, private val pushDiskSource: PushDiskSource, private val pushService: PushService, @@ -162,33 +162,7 @@ class PushManagerImpl @Inject constructor( } NotificationType.LOG_OUT -> { - json - .decodeFromString( - string = notification.payload, - ) - .takeUnless { it.userId == null } - ?.takeUnless { - featureFlagManager.getFeatureFlag(FlagKey.NoLogoutOnKdfChange) && - it.logOutReason == PushNotificationLogOutReason.KDF_CHANGE - } - ?.let { - val userId = requireNotNull(it.userId) - when (it.logOutReason) { - PushNotificationLogOutReason.KEY_ROTATION -> { - // We do not want to logout, we need to sync to help - // facilitate the key rotation. - mutableFullSyncSharedFlow.tryEmit(userId) - } - - PushNotificationLogOutReason.KDF_CHANGE, - null, - -> { - mutableLogoutSharedFlow.tryEmit( - NotificationLogoutData(userId = userId), - ) - } - } - } + handleLogoutPayload(payload = json.decodeFromString(string = notification.payload)) } NotificationType.SYNC_CIPHER_CREATE, @@ -353,6 +327,31 @@ class PushManagerImpl @Inject constructor( } } + private fun handleLogoutPayload(payload: NotificationPayload.UserNotification) { + payload + .takeUnless { it.userId == null } + ?.let { + val userId = requireNotNull(it.userId) + when (it.logOutReason) { + PushNotificationLogOutReason.KEY_ROTATION -> { + // We do not want to log out, we need to sync to help + // facilitate the key rotation. + mutableFullSyncSharedFlow.tryEmit(userId) + } + + PushNotificationLogOutReason.KDF_CHANGE -> { + if (!featureFlagManager.getFeatureFlag(key = FlagKey.NoLogoutOnKdfChange)) { + mutableLogoutSharedFlow.tryEmit(NotificationLogoutData(userId = userId)) + } + } + + null -> { + mutableLogoutSharedFlow.tryEmit(NotificationLogoutData(userId = userId)) + } + } + } + } + override fun registerPushTokenIfNecessary(token: String) { pushDiskSource.registeredPushToken = token