Update Room decoration algo
This commit is contained in:
parent
256f8b77aa
commit
fc4f5faffd
|
@ -46,7 +46,7 @@ class RxRoom(private val room: Room, private val session: Session) {
|
||||||
it.getOrNull()?.let { roomSummary ->
|
it.getOrNull()?.let { roomSummary ->
|
||||||
if (roomSummary.isEncrypted) {
|
if (roomSummary.isEncrypted) {
|
||||||
// Return the list of other users
|
// Return the list of other users
|
||||||
roomSummary.otherMemberIds
|
roomSummary.otherMemberIds + listOf(session.myUserId)
|
||||||
} else {
|
} else {
|
||||||
// Return an empty list, the room is not encrypted
|
// Return an empty list, the room is not encrypted
|
||||||
emptyList()
|
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
|
// Observe the device info of the users in the room
|
||||||
val cryptoDeviceInfoObservable = memberIdsChangeObservable
|
val cryptoDeviceInfoObservable = memberIdsChangeObservable
|
||||||
.switchMap { otherUserIds ->
|
.switchMap { membersIds ->
|
||||||
session.getLiveCryptoDeviceInfo(otherUserIds)
|
session.getLiveCryptoDeviceInfo(membersIds)
|
||||||
.asObservable()
|
.asObservable()
|
||||||
.map {
|
.map {
|
||||||
// If any key change, emit the userIds list
|
// If any key change, emit the userIds list
|
||||||
otherUserIds
|
membersIds
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val roomEncryptionTrustLevelObservable = cryptoDeviceInfoObservable
|
val roomEncryptionTrustLevelObservable = cryptoDeviceInfoObservable
|
||||||
.map { otherUserIds ->
|
.map { userIds ->
|
||||||
if (otherUserIds.isEmpty()) {
|
if (userIds.isEmpty()) {
|
||||||
Optional<RoomEncryptionTrustLevel>(null)
|
Optional<RoomEncryptionTrustLevel>(null)
|
||||||
} else {
|
} else {
|
||||||
session.getCrossSigningService().getTrustLevelForUsers(otherUserIds).toOptional()
|
session.getCrossSigningService().getTrustLevelForUsers(userIds).toOptional()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ class RxSession(private val session: Session) {
|
||||||
summaries.map {
|
summaries.map {
|
||||||
if (it.isEncrypted) {
|
if (it.isEncrypted) {
|
||||||
it.copy(
|
it.copy(
|
||||||
roomEncryptionTrustLevel = session.getCrossSigningService().getTrustLevelForUsers(it.otherMemberIds)
|
roomEncryptionTrustLevel = session.getCrossSigningService().getTrustLevelForUsers(it.otherMemberIds + listOf(session.myUserId))
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
it
|
it
|
||||||
|
|
|
@ -659,16 +659,19 @@ internal class DefaultCrossSigningService @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getTrustLevelForUsers(userIds: List<String>): RoomEncryptionTrustLevel {
|
override fun getTrustLevelForUsers(userIds: List<String>): RoomEncryptionTrustLevel {
|
||||||
val atLeastOneTrusted = userIds
|
val allTrusted = userIds
|
||||||
.filter { it != userId }
|
.filter { getUserCrossSigningKeys(it)?.isTrusted() == true }
|
||||||
.map { getUserCrossSigningKeys(it) }
|
|
||||||
.any { it?.isTrusted() == true }
|
|
||||||
|
|
||||||
return if (!atLeastOneTrusted) {
|
val allUsersAreVerified = userIds.size == allTrusted.size
|
||||||
|
|
||||||
|
return if (allTrusted.isEmpty()) {
|
||||||
RoomEncryptionTrustLevel.Default
|
RoomEncryptionTrustLevel.Default
|
||||||
} else {
|
} 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)
|
cryptoStore.getUserDeviceList(it)
|
||||||
}.flatten()
|
}.flatten()
|
||||||
if (getMyCrossSigningKeys() != null) {
|
if (getMyCrossSigningKeys() != null) {
|
||||||
|
@ -676,14 +679,14 @@ internal class DefaultCrossSigningService @Inject constructor(
|
||||||
if (hasWarning) {
|
if (hasWarning) {
|
||||||
RoomEncryptionTrustLevel.Warning
|
RoomEncryptionTrustLevel.Warning
|
||||||
} else {
|
} else {
|
||||||
RoomEncryptionTrustLevel.Trusted
|
if (allUsersAreVerified) RoomEncryptionTrustLevel.Trusted else RoomEncryptionTrustLevel.Default
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val hasWarningLegacy = allDevices.any { !it.isVerified }
|
val hasWarningLegacy = allDevices.any { !it.isVerified }
|
||||||
if (hasWarningLegacy) {
|
if (hasWarningLegacy) {
|
||||||
RoomEncryptionTrustLevel.Warning
|
RoomEncryptionTrustLevel.Warning
|
||||||
} else {
|
} else {
|
||||||
RoomEncryptionTrustLevel.Trusted
|
if (allUsersAreVerified) RoomEncryptionTrustLevel.Trusted else RoomEncryptionTrustLevel.Default
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue