fix(Watchtower): Do not include hidden accounts in the Global alerts counter
This commit is contained in:
parent
1c973be83f
commit
390c999f65
|
@ -5,10 +5,13 @@ import kotlinx.datetime.Instant
|
||||||
data class DWatchtowerAlert(
|
data class DWatchtowerAlert(
|
||||||
val alertId: String,
|
val alertId: String,
|
||||||
val cipherId: CipherId,
|
val cipherId: CipherId,
|
||||||
|
val accountId: AccountId,
|
||||||
val type: DWatchtowerAlertType,
|
val type: DWatchtowerAlertType,
|
||||||
val reportedAt: Instant,
|
val reportedAt: Instant,
|
||||||
val read: Boolean,
|
val read: Boolean,
|
||||||
val version: String,
|
val version: String,
|
||||||
) : HasCipherId {
|
) : HasCipherId, HasAccountId {
|
||||||
override fun cipherId(): String = cipherId.id
|
override fun cipherId(): String = cipherId.id
|
||||||
|
|
||||||
|
override fun accountId(): String = accountId.id
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.artemchep.keyguard.provider.bitwarden.usecase
|
||||||
import app.cash.sqldelight.coroutines.asFlow
|
import app.cash.sqldelight.coroutines.asFlow
|
||||||
import app.cash.sqldelight.coroutines.mapToList
|
import app.cash.sqldelight.coroutines.mapToList
|
||||||
import com.artemchep.keyguard.common.io.effectMap
|
import com.artemchep.keyguard.common.io.effectMap
|
||||||
|
import com.artemchep.keyguard.common.model.AccountId
|
||||||
import com.artemchep.keyguard.common.model.CipherId
|
import com.artemchep.keyguard.common.model.CipherId
|
||||||
import com.artemchep.keyguard.common.model.DWatchtowerAlert
|
import com.artemchep.keyguard.common.model.DWatchtowerAlert
|
||||||
import com.artemchep.keyguard.common.model.DWatchtowerAlertType
|
import com.artemchep.keyguard.common.model.DWatchtowerAlertType
|
||||||
|
@ -40,10 +41,12 @@ class GetWatchtowerAlertsImpl(
|
||||||
.mapNotNull { item ->
|
.mapNotNull { item ->
|
||||||
val type = DWatchtowerAlertType.of(item.type)
|
val type = DWatchtowerAlertType.of(item.type)
|
||||||
?: return@mapNotNull null
|
?: return@mapNotNull null
|
||||||
|
val accountId = AccountId(item.accountId!!)
|
||||||
val cipherId = CipherId(item.cipherId)
|
val cipherId = CipherId(item.cipherId)
|
||||||
DWatchtowerAlert(
|
DWatchtowerAlert(
|
||||||
alertId = item.cipherId + "|" + item.type,
|
alertId = item.cipherId + "|" + item.type,
|
||||||
cipherId = cipherId,
|
cipherId = cipherId,
|
||||||
|
accountId = accountId,
|
||||||
type = type,
|
type = type,
|
||||||
reportedAt = item.reportedAt,
|
reportedAt = item.reportedAt,
|
||||||
read = item.read,
|
read = item.read,
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package com.artemchep.keyguard.provider.bitwarden.usecase
|
package com.artemchep.keyguard.provider.bitwarden.usecase
|
||||||
|
|
||||||
|
import com.artemchep.keyguard.common.usecase.GetProfiles
|
||||||
import com.artemchep.keyguard.common.usecase.GetWatchtowerUnreadAlerts
|
import com.artemchep.keyguard.common.usecase.GetWatchtowerUnreadAlerts
|
||||||
import com.artemchep.keyguard.common.usecase.GetWatchtowerUnreadCount
|
import com.artemchep.keyguard.common.usecase.GetWatchtowerUnreadCount
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.combine
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
import org.kodein.di.DirectDI
|
import org.kodein.di.DirectDI
|
||||||
import org.kodein.di.instance
|
import org.kodein.di.instance
|
||||||
|
@ -12,15 +14,27 @@ import org.kodein.di.instance
|
||||||
*/
|
*/
|
||||||
class GetWatchtowerUnreadCountImpl(
|
class GetWatchtowerUnreadCountImpl(
|
||||||
private val getWatchtowerUnreadAlerts: GetWatchtowerUnreadAlerts,
|
private val getWatchtowerUnreadAlerts: GetWatchtowerUnreadAlerts,
|
||||||
|
private val getProfiles: GetProfiles,
|
||||||
) : GetWatchtowerUnreadCount {
|
) : GetWatchtowerUnreadCount {
|
||||||
constructor(directDI: DirectDI) : this(
|
constructor(directDI: DirectDI) : this(
|
||||||
getWatchtowerUnreadAlerts = directDI.instance(),
|
getWatchtowerUnreadAlerts = directDI.instance(),
|
||||||
|
getProfiles = directDI.instance(),
|
||||||
)
|
)
|
||||||
|
|
||||||
private val sharedFlow = getWatchtowerUnreadAlerts()
|
private val sharedFlow = combine(
|
||||||
.map { list ->
|
getProfiles()
|
||||||
list.size
|
.map { profiles ->
|
||||||
}
|
profiles
|
||||||
|
.associateBy { it.accountId }
|
||||||
|
},
|
||||||
|
getWatchtowerUnreadAlerts(),
|
||||||
|
) { profiles, unreadAlerts ->
|
||||||
|
unreadAlerts
|
||||||
|
.count { alert ->
|
||||||
|
val profile = profiles[alert.accountId.id]
|
||||||
|
profile?.hidden == false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun invoke(): Flow<Int> = sharedFlow
|
override fun invoke(): Flow<Int> = sharedFlow
|
||||||
|
|
||||||
|
|
|
@ -59,11 +59,12 @@ markAsRead {
|
||||||
}
|
}
|
||||||
|
|
||||||
getThreats:
|
getThreats:
|
||||||
SELECT *
|
SELECT watchtowerThreat.*, cipher.accountId AS accountId
|
||||||
FROM watchtowerThreat
|
FROM watchtowerThreat
|
||||||
|
LEFT JOIN cipher ON cipher.cipherId = watchtowerThreat.cipherId
|
||||||
WHERE
|
WHERE
|
||||||
threat > 0
|
watchtowerThreat.threat > 0
|
||||||
ORDER BY reportedAt DESC;
|
ORDER BY watchtowerThreat.reportedAt DESC;
|
||||||
|
|
||||||
getPendingCipherIds:
|
getPendingCipherIds:
|
||||||
SELECT DISTINCT
|
SELECT DISTINCT
|
||||||
|
|
Loading…
Reference in New Issue