mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-03-18 04:08:44 +03:00
Update Room decoration algo
This commit is contained in:
parent
256f8b77aa
commit
fc4f5faffd
3 changed files with 20 additions and 17 deletions
|
@ -46,7 +46,7 @@ class RxRoom(private val room: Room, private val session: Session) {
|
|||
it.getOrNull()?.let { roomSummary ->
|
||||
if (roomSummary.isEncrypted) {
|
||||
// Return the list of other users
|
||||
roomSummary.otherMemberIds
|
||||
roomSummary.otherMemberIds + listOf(session.myUserId)
|
||||
} else {
|
||||
// Return an empty list, the room is not encrypted
|
||||
emptyList()
|
||||
|
@ -56,21 +56,21 @@ class RxRoom(private val room: Room, private val session: Session) {
|
|||
|
||||
// Observe the device info of the users in the room
|
||||
val cryptoDeviceInfoObservable = memberIdsChangeObservable
|
||||
.switchMap { otherUserIds ->
|
||||
session.getLiveCryptoDeviceInfo(otherUserIds)
|
||||
.switchMap { membersIds ->
|
||||
session.getLiveCryptoDeviceInfo(membersIds)
|
||||
.asObservable()
|
||||
.map {
|
||||
// If any key change, emit the userIds list
|
||||
otherUserIds
|
||||
membersIds
|
||||
}
|
||||
}
|
||||
|
||||
val roomEncryptionTrustLevelObservable = cryptoDeviceInfoObservable
|
||||
.map { otherUserIds ->
|
||||
if (otherUserIds.isEmpty()) {
|
||||
.map { userIds ->
|
||||
if (userIds.isEmpty()) {
|
||||
Optional<RoomEncryptionTrustLevel>(null)
|
||||
} else {
|
||||
session.getCrossSigningService().getTrustLevelForUsers(otherUserIds).toOptional()
|
||||
session.getCrossSigningService().getTrustLevelForUsers(userIds).toOptional()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ class RxSession(private val session: Session) {
|
|||
summaries.map {
|
||||
if (it.isEncrypted) {
|
||||
it.copy(
|
||||
roomEncryptionTrustLevel = session.getCrossSigningService().getTrustLevelForUsers(it.otherMemberIds)
|
||||
roomEncryptionTrustLevel = session.getCrossSigningService().getTrustLevelForUsers(it.otherMemberIds + listOf(session.myUserId))
|
||||
)
|
||||
} else {
|
||||
it
|
||||
|
|
|
@ -659,16 +659,19 @@ internal class DefaultCrossSigningService @Inject constructor(
|
|||
}
|
||||
|
||||
override fun getTrustLevelForUsers(userIds: List<String>): RoomEncryptionTrustLevel {
|
||||
val atLeastOneTrusted = userIds
|
||||
.filter { it != userId }
|
||||
.map { getUserCrossSigningKeys(it) }
|
||||
.any { it?.isTrusted() == true }
|
||||
val allTrusted = userIds
|
||||
.filter { getUserCrossSigningKeys(it)?.isTrusted() == true }
|
||||
|
||||
return if (!atLeastOneTrusted) {
|
||||
val allUsersAreVerified = userIds.size == allTrusted.size
|
||||
|
||||
return if (allTrusted.isEmpty()) {
|
||||
RoomEncryptionTrustLevel.Default
|
||||
} else {
|
||||
// I have verified at least one other user
|
||||
val allDevices = userIds.mapNotNull {
|
||||
|
||||
// If one of the verified user as an untrusted device -> warning
|
||||
// Green if all devices of all verified users are trusted -> green
|
||||
// else black
|
||||
val allDevices = allTrusted.mapNotNull {
|
||||
cryptoStore.getUserDeviceList(it)
|
||||
}.flatten()
|
||||
if (getMyCrossSigningKeys() != null) {
|
||||
|
@ -676,14 +679,14 @@ internal class DefaultCrossSigningService @Inject constructor(
|
|||
if (hasWarning) {
|
||||
RoomEncryptionTrustLevel.Warning
|
||||
} else {
|
||||
RoomEncryptionTrustLevel.Trusted
|
||||
if (allUsersAreVerified) RoomEncryptionTrustLevel.Trusted else RoomEncryptionTrustLevel.Default
|
||||
}
|
||||
} else {
|
||||
val hasWarningLegacy = allDevices.any { !it.isVerified }
|
||||
if (hasWarningLegacy) {
|
||||
RoomEncryptionTrustLevel.Warning
|
||||
} else {
|
||||
RoomEncryptionTrustLevel.Trusted
|
||||
if (allUsersAreVerified) RoomEncryptionTrustLevel.Trusted else RoomEncryptionTrustLevel.Default
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue