Skip to content

Commit

Permalink
Update room member shields behavior (#8195)
Browse files Browse the repository at this point in the history
  • Loading branch information
yostyle authored Mar 3, 2023
1 parent a434041 commit 446ed24
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 19 deletions.
1 change: 1 addition & 0 deletions changelog.d/8195.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update room member shields behavior
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ data class CryptoDeviceInfo(
val isVerified: Boolean
get() = trustLevel?.isVerified() == true

val isCrossSigningVerified: Boolean
get() = trustLevel?.isCrossSigningVerified() == true

val isUnknown: Boolean
get() = trustLevel == null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,10 @@ class RoomMemberProfileController @Inject constructor(
// Cross signing is enabled for this user
if (state.userMXCrossSigningInfo.isTrusted()) {
// User is trusted
val icon = if (state.allDevicesAreTrusted) {
R.drawable.ic_shield_trusted
val (icon, titleRes) = if (state.allDevicesAreCrossSignedTrusted) {
Pair(R.drawable.ic_shield_trusted, R.string.verification_profile_verified)
} else {
R.drawable.ic_shield_warning
}

val titleRes = if (state.allDevicesAreTrusted) {
R.string.verification_profile_verified
} else {
R.string.verification_profile_warning
Pair(R.drawable.ic_shield_warning, R.string.verification_profile_warning)
}

buildProfileAction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ data class DeviceListViewState(
val allowDeviceAction: Boolean,
val userItem: MatrixItem? = null,
val memberCrossSigningKey: MXCrossSigningInfo? = null,
val myDeviceId: String = "",
val cryptoDevices: Async<List<CryptoDeviceInfo>> = Loading(),
val selectedDevice: CryptoDeviceInfo? = null
) : MavericksState
Expand All @@ -70,6 +71,7 @@ class DeviceListBottomSheetViewModel @AssistedInject constructor(
userId = userId,
allowDeviceAction = args.allowDeviceAction,
userItem = session.getUserOrDefault(userId).toMatrixItem(),
myDeviceId = session.sessionParams.deviceId ?: "",
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ import im.vector.app.core.ui.list.genericItem
import im.vector.app.core.ui.list.genericWithValueItem
import im.vector.app.core.utils.DimensionConverter
import im.vector.app.features.settings.VectorPreferences
import im.vector.app.features.settings.devices.TrustUtils
import im.vector.lib.core.utils.epoxy.charsequence.toEpoxyCharSequence
import me.gujun.android.span.span
import org.matrix.android.sdk.api.extensions.orFalse
import org.matrix.android.sdk.api.session.crypto.model.CryptoDeviceInfo
import org.matrix.android.sdk.api.session.crypto.model.RoomEncryptionTrustLevel
import javax.inject.Inject

class DeviceListEpoxyController @Inject constructor(
Expand Down Expand Up @@ -68,10 +71,20 @@ class DeviceListEpoxyController @Inject constructor(
it.isVerified
}

val trustMSK = data.memberCrossSigningKey?.isTrusted().orFalse()
val legacyMode = data.memberCrossSigningKey == null

// Build top header
val allGreen = deviceList.fold(true, { prev, device ->
prev && device.isVerified
})
val allGreen = deviceList.fold(true) { prev, device ->
val trustLevel = TrustUtils.shieldForTrust(
data.myDeviceId == device.deviceId,
trustMSK,
legacyMode,
device.trustLevel
)

prev && trustLevel == RoomEncryptionTrustLevel.Trusted
}

genericItem {
id("title")
Expand Down Expand Up @@ -105,8 +118,21 @@ class DeviceListEpoxyController @Inject constructor(
// Build list of device with status
deviceList.forEach { device ->
genericWithValueItem {
val trustLevel = TrustUtils.shieldForTrust(
data.myDeviceId == device.deviceId,
trustMSK,
legacyMode,
device.trustLevel
)
val shield = when (trustLevel) {
RoomEncryptionTrustLevel.Default -> R.drawable.ic_shield_unknown
RoomEncryptionTrustLevel.Warning -> R.drawable.ic_shield_warning
RoomEncryptionTrustLevel.Trusted -> R.drawable.ic_shield_trusted
RoomEncryptionTrustLevel.E2EWithUnsupportedAlgorithm -> R.drawable.ic_warning_badge
}

id(device.deviceId)
titleIconResourceId(if (device.isVerified) R.drawable.ic_shield_trusted else R.drawable.ic_shield_warning)
titleIconResourceId(shield)
apply {
val title = if (host.vectorPreferences.developerMode()) {
val seq = span {
Expand All @@ -126,12 +152,12 @@ class DeviceListEpoxyController @Inject constructor(
}
value(
host.stringProvider.getString(
if (device.isVerified) R.string.trusted else R.string.not_trusted
if (trustLevel == RoomEncryptionTrustLevel.Trusted) R.string.trusted else R.string.not_trusted
)
)
valueColorInt(
host.colorProvider.getColorFromAttribute(
if (device.isVerified) R.attr.colorPrimary else R.attr.colorError
if (trustLevel == RoomEncryptionTrustLevel.Trusted) R.attr.colorPrimary else R.attr.colorError
)
)
itemClickAction {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ import im.vector.app.core.ui.list.genericWithValueItem
import im.vector.app.core.utils.DimensionConverter
import im.vector.app.features.crypto.verification.epoxy.bottomSheetVerificationActionItem
import im.vector.app.features.settings.VectorPreferences
import im.vector.app.features.settings.devices.TrustUtils
import im.vector.lib.core.utils.epoxy.charsequence.toEpoxyCharSequence
import me.gujun.android.span.span
import org.matrix.android.sdk.api.extensions.orFalse
import org.matrix.android.sdk.api.session.crypto.model.CryptoDeviceInfo
import org.matrix.android.sdk.api.session.crypto.model.RoomEncryptionTrustLevel
import javax.inject.Inject

class DeviceTrustInfoEpoxyController @Inject constructor(
Expand All @@ -49,11 +52,26 @@ class DeviceTrustInfoEpoxyController @Inject constructor(
override fun buildModels(data: DeviceListViewState?) {
val host = this
data?.selectedDevice?.let { cryptoDeviceInfo ->
val isVerified = cryptoDeviceInfo.trustLevel?.isVerified() == true
val trustMSK = data.memberCrossSigningKey?.isTrusted().orFalse()
val legacyMode = data.memberCrossSigningKey == null
val isMyDevice = data.myDeviceId == cryptoDeviceInfo.deviceId
val trustLevel = TrustUtils.shieldForTrust(
isMyDevice,
trustMSK,
legacyMode,
cryptoDeviceInfo.trustLevel
)
val isVerified = trustLevel == RoomEncryptionTrustLevel.Trusted
val shield = when (trustLevel) {
RoomEncryptionTrustLevel.Default -> R.drawable.ic_shield_unknown
RoomEncryptionTrustLevel.Warning -> R.drawable.ic_shield_warning
RoomEncryptionTrustLevel.Trusted -> R.drawable.ic_shield_trusted
RoomEncryptionTrustLevel.E2EWithUnsupportedAlgorithm -> R.drawable.ic_warning_badge
}
genericItem {
id("title")
style(ItemStyle.BIG_TEXT)
titleIconResourceId(if (isVerified) R.drawable.ic_shield_trusted else R.drawable.ic_shield_warning)
titleIconResourceId(shield)
title(
host.stringProvider
.getString(if (isVerified) R.string.verification_profile_verified else R.string.verification_profile_warning)
Expand Down Expand Up @@ -90,7 +108,7 @@ class DeviceTrustInfoEpoxyController @Inject constructor(

genericWithValueItem {
id(cryptoDeviceInfo.deviceId)
titleIconResourceId(if (isVerified) R.drawable.ic_shield_trusted else R.drawable.ic_shield_warning)
titleIconResourceId(shield)
title(
span {
+(cryptoDeviceInfo.displayName() ?: "")
Expand All @@ -103,7 +121,7 @@ class DeviceTrustInfoEpoxyController @Inject constructor(
)
}

if (!isVerified) {
if (!isVerified && !isMyDevice) {
genericFooterItem {
id("warn")
centered(false)
Expand Down

0 comments on commit 446ed24

Please sign in to comment.