Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,80 +39,76 @@ class FirstTimeActionManagerImpl @Inject constructor(

private val unconfinedScope = CoroutineScope(dispatcherManager.unconfined)

override val allSettingsBadgeCountFlow: StateFlow<Int>
get() = combine(
listOf(
allSecuritySettingsBadgeCountFlow,
allAutofillSettingsBadgeCountFlow,
allVaultSettingsBadgeCountFlow,
),
) {
it.sum()
@OptIn(ExperimentalCoroutinesApi::class)
override val allSecuritySettingsBadgeCountFlow: StateFlow<Int> = authDiskSource
.activeUserIdChangesFlow
.filterNotNull()
.flatMapLatest {
// can be expanded to support multiple security settings
settingsDiskSource.getShowUnlockSettingBadgeFlow(userId = it)
.map { showUnlockBadge ->
listOfNotNull(showUnlockBadge)
}
.map { list ->
list.count { badgeOnValue -> badgeOnValue }
}
}
.stateIn(
scope = unconfinedScope,
started = SharingStarted.Lazily,
initialValue = 0,
)
.stateIn(
scope = unconfinedScope,
started = SharingStarted.Eagerly,
initialValue = 0,
)

@OptIn(ExperimentalCoroutinesApi::class)
override val allSecuritySettingsBadgeCountFlow: StateFlow<Int>
get() = authDiskSource
.activeUserIdChangesFlow
.filterNotNull()
.flatMapLatest {
// can be expanded to support multiple security settings
settingsDiskSource.getShowUnlockSettingBadgeFlow(userId = it)
.map { showUnlockBadge ->
listOfNotNull(showUnlockBadge)
}
.map { list ->
list.count { badgeOnValue -> badgeOnValue }
}
override val allAutofillSettingsBadgeCountFlow: StateFlow<Int> = authDiskSource
.activeUserIdChangesFlow
.filterNotNull()
.flatMapLatest {
combine(
getShowAutofillSettingBadgeFlowInternal(userId = it),
getShowBrowserAutofillSettingBadgeFlowInternal(userId = it),
) { showAutofillBadge, showBrowserAutofillBadge ->
listOf(showAutofillBadge, showBrowserAutofillBadge)
}
.stateIn(
scope = unconfinedScope,
started = SharingStarted.Lazily,
initialValue = 0,
)

@OptIn(ExperimentalCoroutinesApi::class)
override val allAutofillSettingsBadgeCountFlow: StateFlow<Int>
get() = authDiskSource
.activeUserIdChangesFlow
.filterNotNull()
.flatMapLatest {
combine(
getShowAutofillSettingBadgeFlowInternal(userId = it),
getShowBrowserAutofillSettingBadgeFlowInternal(userId = it),
) { showAutofillBadge, showBrowserAutofillBadge ->
listOf(showAutofillBadge, showBrowserAutofillBadge)
.map { list ->
list.count { showBadge -> showBadge }
}
.map { list ->
list.count { showBadge -> showBadge }
}
}
.stateIn(
scope = unconfinedScope,
started = SharingStarted.Lazily,
initialValue = 0,
)
}
.stateIn(
scope = unconfinedScope,
started = SharingStarted.Eagerly,
initialValue = 0,
)

@OptIn(ExperimentalCoroutinesApi::class)
override val allVaultSettingsBadgeCountFlow: StateFlow<Int>
get() = authDiskSource
.activeUserIdChangesFlow
.filterNotNull()
.flatMapLatest {
getShowImportLoginsSettingBadgeFlowInternal(userId = it)
.map { showImportLogins -> listOf(showImportLogins) }
.map { list -> list.count { showImportLogins -> showImportLogins } }
}
.stateIn(
scope = unconfinedScope,
started = SharingStarted.Lazily,
initialValue = 0,
)
override val allVaultSettingsBadgeCountFlow: StateFlow<Int> = authDiskSource
.activeUserIdChangesFlow
.filterNotNull()
.flatMapLatest {
getShowImportLoginsSettingBadgeFlowInternal(userId = it)
.map { showImportLogins -> listOf(showImportLogins) }
.map { list -> list.count { showImportLogins -> showImportLogins } }
}
.stateIn(
scope = unconfinedScope,
started = SharingStarted.Eagerly,
initialValue = 0,
)

override val allSettingsBadgeCountFlow: StateFlow<Int> = combine(
listOf(
allSecuritySettingsBadgeCountFlow,
allAutofillSettingsBadgeCountFlow,
allVaultSettingsBadgeCountFlow,
),
) {
it.sum()
}
.stateIn(
scope = unconfinedScope,
started = SharingStarted.Eagerly,
initialValue = 0,
)

/**
* Returns a [Flow] that emits every time the active user's first time state is changed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,28 +48,27 @@ internal class UserNotificationPolicyManagerImpl(
}

@OptIn(ExperimentalCoroutinesApi::class)
override val displayDataFlow: StateFlow<UserNotificationPolicyData?>
get() = authDiskSource
.activeUserIdChangesFlow
.flatMapLatest { userId ->
userId ?: return@flatMapLatest flowOf(null)
combine(
settingsDiskSource.getVaultPolicyBannerDismissedDateFlow(userId = userId),
policyManager
.getActivePoliciesFlow(type = PolicyType.ORGANIZATION_USER_NOTIFICATION)
.map { it.firstOrNull() },
) { revisionDate, policy ->
(policy?.userNotificationPolicyData)?.takeIf {
policy.revisionDate?.toEpochMilli() != revisionDate?.toEpochMilli() ||
revisionDate == null
}
override val displayDataFlow: StateFlow<UserNotificationPolicyData?> = authDiskSource
.activeUserIdChangesFlow
.flatMapLatest { userId ->
userId ?: return@flatMapLatest flowOf(null)
combine(
settingsDiskSource.getVaultPolicyBannerDismissedDateFlow(userId = userId),
policyManager
.getActivePoliciesFlow(type = PolicyType.ORGANIZATION_USER_NOTIFICATION)
.map { it.firstOrNull() },
) { revisionDate, policy ->
(policy?.userNotificationPolicyData)?.takeIf {
policy.revisionDate?.toEpochMilli() != revisionDate?.toEpochMilli() ||
revisionDate == null
}
}
.stateIn(
scope = unconfinedScope,
started = SharingStarted.Lazily,
initialValue = displayData,
)
}
.stateIn(
scope = unconfinedScope,
started = SharingStarted.Eagerly,
initialValue = displayData,
)

override fun dismissBanner() {
policyManager
Expand Down
Loading
Loading