mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-03-19 04:38:44 +03:00
Update room member shields behavior (#8195)
This commit is contained in:
parent
a4340412e8
commit
446ed24bea
6 changed files with 63 additions and 19 deletions
1
changelog.d/8195.bugfix
Normal file
1
changelog.d/8195.bugfix
Normal file
|
@ -0,0 +1 @@
|
|||
Update room member shields behavior
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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
|
||||
|
@ -70,6 +71,7 @@ class DeviceListBottomSheetViewModel @AssistedInject constructor(
|
|||
userId = userId,
|
||||
allowDeviceAction = args.allowDeviceAction,
|
||||
userItem = session.getUserOrDefault(userId).toMatrixItem(),
|
||||
myDeviceId = session.sessionParams.deviceId ?: "",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(
|
||||
|
@ -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")
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
|
|
@ -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(
|
||||
|
@ -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)
|
||||
|
@ -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() ?: "")
|
||||
|
@ -103,7 +121,7 @@ class DeviceTrustInfoEpoxyController @Inject constructor(
|
|||
)
|
||||
}
|
||||
|
||||
if (!isVerified) {
|
||||
if (!isVerified && !isMyDevice) {
|
||||
genericFooterItem {
|
||||
id("warn")
|
||||
centered(false)
|
||||
|
|
Loading…
Add table
Reference in a new issue