mirror of
https://github.com/bitwarden/android.git
synced 2026-06-07 14:57:41 -05:00
Check isAuthenticated status within PushManager (#600)
This commit is contained in:
committed by
Álison Fernandes
parent
3d75867a15
commit
8efd9d2c8a
@@ -94,6 +94,11 @@ class PushManagerImpl @Inject constructor(
|
||||
override val syncSendUpsertFlow: SharedFlow<SyncSendUpsertData>
|
||||
get() = mutableSyncSendUpsertSharedFlow.asSharedFlow()
|
||||
|
||||
private val activeUserId: String?
|
||||
get() = authDiskSource.userState?.activeUserId
|
||||
private val isLoggedIn: Boolean
|
||||
get() = authDiskSource.userState?.activeAccount?.isLoggedIn == true
|
||||
|
||||
init {
|
||||
authDiskSource
|
||||
.userStateFlow
|
||||
@@ -113,7 +118,7 @@ class PushManagerImpl @Inject constructor(
|
||||
|
||||
if (authDiskSource.uniqueAppId == notification.contextId) return
|
||||
|
||||
val userId = authDiskSource.userState?.activeUserId
|
||||
val userId = activeUserId
|
||||
|
||||
when (val type = notification.notificationType) {
|
||||
NotificationType.AUTH_REQUEST,
|
||||
@@ -130,7 +135,7 @@ class PushManagerImpl @Inject constructor(
|
||||
}
|
||||
|
||||
NotificationType.LOG_OUT -> {
|
||||
if (userId == null) return
|
||||
if (!isLoggedIn) return
|
||||
mutableLogoutSharedFlow.tryEmit(Unit)
|
||||
}
|
||||
|
||||
@@ -139,7 +144,7 @@ class PushManagerImpl @Inject constructor(
|
||||
-> {
|
||||
val payload: NotificationPayload.SyncCipherNotification =
|
||||
json.decodeFromJsonElement(notification.payload)
|
||||
if (!payload.userMatchesNotification(userId)) return
|
||||
if (!isLoggedIn || !payload.userMatchesNotification(userId)) return
|
||||
mutableSyncCipherUpsertSharedFlow.tryEmit(
|
||||
SyncCipherUpsertData(
|
||||
cipherId = payload.id,
|
||||
@@ -154,7 +159,7 @@ class PushManagerImpl @Inject constructor(
|
||||
-> {
|
||||
val payload: NotificationPayload.SyncCipherNotification =
|
||||
json.decodeFromJsonElement(notification.payload)
|
||||
if (!payload.userMatchesNotification(userId)) return
|
||||
if (!isLoggedIn || !payload.userMatchesNotification(userId)) return
|
||||
mutableSyncCipherDeleteSharedFlow.tryEmit(
|
||||
SyncCipherDeleteData(payload.id),
|
||||
)
|
||||
@@ -173,7 +178,7 @@ class PushManagerImpl @Inject constructor(
|
||||
-> {
|
||||
val payload: NotificationPayload.SyncFolderNotification =
|
||||
json.decodeFromJsonElement(notification.payload)
|
||||
if (!payload.userMatchesNotification(userId)) return
|
||||
if (!isLoggedIn || !payload.userMatchesNotification(userId)) return
|
||||
mutableSyncFolderUpsertSharedFlow.tryEmit(
|
||||
SyncFolderUpsertData(
|
||||
folderId = payload.id,
|
||||
@@ -186,7 +191,7 @@ class PushManagerImpl @Inject constructor(
|
||||
NotificationType.SYNC_FOLDER_DELETE -> {
|
||||
val payload: NotificationPayload.SyncFolderNotification =
|
||||
json.decodeFromJsonElement(notification.payload)
|
||||
if (!payload.userMatchesNotification(userId)) return
|
||||
if (!isLoggedIn || !payload.userMatchesNotification(userId)) return
|
||||
|
||||
mutableSyncFolderDeleteSharedFlow.tryEmit(
|
||||
SyncFolderDeleteData(payload.id),
|
||||
@@ -194,7 +199,7 @@ class PushManagerImpl @Inject constructor(
|
||||
}
|
||||
|
||||
NotificationType.SYNC_ORG_KEYS -> {
|
||||
if (userId == null) return
|
||||
if (!isLoggedIn) return
|
||||
mutableSyncOrgKeysSharedFlow.tryEmit(Unit)
|
||||
}
|
||||
|
||||
@@ -203,7 +208,7 @@ class PushManagerImpl @Inject constructor(
|
||||
-> {
|
||||
val payload: NotificationPayload.SyncSendNotification =
|
||||
json.decodeFromJsonElement(notification.payload)
|
||||
if (!payload.userMatchesNotification(userId)) return
|
||||
if (!isLoggedIn || !payload.userMatchesNotification(userId)) return
|
||||
mutableSyncSendUpsertSharedFlow.tryEmit(
|
||||
SyncSendUpsertData(
|
||||
sendId = payload.id,
|
||||
@@ -216,7 +221,7 @@ class PushManagerImpl @Inject constructor(
|
||||
NotificationType.SYNC_SEND_DELETE -> {
|
||||
val payload: NotificationPayload.SyncSendNotification =
|
||||
json.decodeFromJsonElement(notification.payload)
|
||||
if (!payload.userMatchesNotification(userId)) return
|
||||
if (!isLoggedIn || !payload.userMatchesNotification(userId)) return
|
||||
mutableSyncSendDeleteSharedFlow.tryEmit(
|
||||
SyncSendDeleteData(payload.id),
|
||||
)
|
||||
@@ -226,7 +231,9 @@ class PushManagerImpl @Inject constructor(
|
||||
|
||||
override fun registerPushTokenIfNecessary(token: String) {
|
||||
pushDiskSource.registeredPushToken = token
|
||||
val userId = authDiskSource.userState?.activeUserId ?: return
|
||||
|
||||
if (!isLoggedIn) return
|
||||
val userId = activeUserId ?: return
|
||||
ioScope.launch {
|
||||
registerPushTokenIfNecessaryInternal(
|
||||
userId = userId,
|
||||
@@ -235,8 +242,10 @@ class PushManagerImpl @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("ReturnCount")
|
||||
override fun registerStoredPushTokenIfNecessary() {
|
||||
val userId = authDiskSource.userState?.activeUserId ?: return
|
||||
if (!isLoggedIn) return
|
||||
val userId = activeUserId ?: return
|
||||
|
||||
// If the last registered token is from less than a day before, skip this for now
|
||||
val lastRegistration = pushDiskSource.getLastPushTokenRegistrationDate(userId)?.toInstant()
|
||||
|
||||
@@ -1,14 +1,19 @@
|
||||
package com.x8bit.bitwarden.data.platform.manager.di
|
||||
|
||||
import android.content.Context
|
||||
import com.x8bit.bitwarden.data.auth.datasource.disk.AuthDiskSource
|
||||
import com.x8bit.bitwarden.data.auth.repository.AuthRepository
|
||||
import com.x8bit.bitwarden.data.platform.datasource.disk.PushDiskSource
|
||||
import com.x8bit.bitwarden.data.platform.datasource.network.authenticator.RefreshAuthenticator
|
||||
import com.x8bit.bitwarden.data.platform.datasource.network.interceptor.AuthTokenInterceptor
|
||||
import com.x8bit.bitwarden.data.platform.datasource.network.interceptor.BaseUrlInterceptors
|
||||
import com.x8bit.bitwarden.data.platform.datasource.network.service.PushService
|
||||
import com.x8bit.bitwarden.data.platform.manager.AppForegroundManager
|
||||
import com.x8bit.bitwarden.data.platform.manager.AppForegroundManagerImpl
|
||||
import com.x8bit.bitwarden.data.platform.manager.NetworkConfigManager
|
||||
import com.x8bit.bitwarden.data.platform.manager.NetworkConfigManagerImpl
|
||||
import com.x8bit.bitwarden.data.platform.manager.PushManager
|
||||
import com.x8bit.bitwarden.data.platform.manager.PushManagerImpl
|
||||
import com.x8bit.bitwarden.data.platform.manager.SdkClientManager
|
||||
import com.x8bit.bitwarden.data.platform.manager.SdkClientManagerImpl
|
||||
import com.x8bit.bitwarden.data.platform.manager.clipboard.BitwardenClipboardManager
|
||||
@@ -21,6 +26,7 @@ import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import kotlinx.serialization.json.Json
|
||||
import java.time.Clock
|
||||
import javax.inject.Singleton
|
||||
|
||||
@@ -72,4 +78,22 @@ object PlatformManagerModule {
|
||||
refreshAuthenticator = refreshAuthenticator,
|
||||
dispatcherManager = dispatcherManager,
|
||||
)
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun providePushManager(
|
||||
authDiskSource: AuthDiskSource,
|
||||
pushDiskSource: PushDiskSource,
|
||||
pushService: PushService,
|
||||
dispatcherManager: DispatcherManager,
|
||||
clock: Clock,
|
||||
json: Json,
|
||||
): PushManager = PushManagerImpl(
|
||||
authDiskSource = authDiskSource,
|
||||
pushDiskSource = pushDiskSource,
|
||||
pushService = pushService,
|
||||
dispatcherManager = dispatcherManager,
|
||||
clock = clock,
|
||||
json = json,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
package com.x8bit.bitwarden.data.platform.manager.di
|
||||
|
||||
import com.x8bit.bitwarden.data.auth.datasource.disk.AuthDiskSource
|
||||
import com.x8bit.bitwarden.data.platform.datasource.disk.PushDiskSource
|
||||
import com.x8bit.bitwarden.data.platform.datasource.network.service.PushService
|
||||
import com.x8bit.bitwarden.data.platform.manager.PushManager
|
||||
import com.x8bit.bitwarden.data.platform.manager.PushManagerImpl
|
||||
import com.x8bit.bitwarden.data.platform.manager.dispatcher.DispatcherManager
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import kotlinx.serialization.json.Json
|
||||
import java.time.Clock
|
||||
import javax.inject.Singleton
|
||||
|
||||
/**
|
||||
* Provides repositories in the push package.
|
||||
*/
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
object PushManagerModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun providePushManager(
|
||||
authDiskSource: AuthDiskSource,
|
||||
pushDiskSource: PushDiskSource,
|
||||
pushService: PushService,
|
||||
dispatcherManager: DispatcherManager,
|
||||
clock: Clock,
|
||||
json: Json,
|
||||
): PushManager = PushManagerImpl(
|
||||
authDiskSource = authDiskSource,
|
||||
pushDiskSource = pushDiskSource,
|
||||
pushService = pushService,
|
||||
dispatcherManager = dispatcherManager,
|
||||
clock = clock,
|
||||
json = json,
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user