diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/crypto/RoomEncryptionTrustLevel.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/crypto/RoomEncryptionTrustLevel.kt new file mode 100644 index 0000000000..ee431ae23a --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/crypto/RoomEncryptionTrustLevel.kt @@ -0,0 +1,31 @@ +/* + * Copyright 2020 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.matrix.android.api.crypto + +/** + * RoomEncryptionTrustLevel represents the trust level in an encrypted room. + */ +enum class RoomEncryptionTrustLevel { + // No one in the room has been verified -> Black shield + Default, + + // There are one or more device un-verified -> the app should display a red shield + Warning, + + // All devices in the room are verified -> the app should display a green shield + Trusted +} diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/RoomSummary.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/RoomSummary.kt index 7ec6254613..28c56125f1 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/RoomSummary.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/RoomSummary.kt @@ -16,6 +16,7 @@ package im.vector.matrix.android.api.session.room.model +import im.vector.matrix.android.api.crypto.RoomEncryptionTrustLevel import im.vector.matrix.android.api.session.room.model.tag.RoomTag import im.vector.matrix.android.api.session.room.send.UserDraft import im.vector.matrix.android.api.session.room.timeline.TimelineEvent @@ -24,7 +25,7 @@ import im.vector.matrix.android.api.session.room.timeline.TimelineEvent * This class holds some data of a room. * It can be retrieved by [im.vector.matrix.android.api.session.room.Room] and [im.vector.matrix.android.api.session.room.RoomService] */ -data class RoomSummary( +data class RoomSummary constructor( val roomId: String, val displayName: String = "", val topic: String = "", @@ -46,7 +47,9 @@ data class RoomSummary( val userDrafts: List = emptyList(), var isEncrypted: Boolean, val typingRoomMemberIds: List = emptyList(), - val breadcrumbsIndex: Int = NOT_IN_BREADCRUMBS + val breadcrumbsIndex: Int = NOT_IN_BREADCRUMBS, + // TODO Plug it + val roomEncryptionTrustLevel: RoomEncryptionTrustLevel? = null ) { val isVersioned: Boolean diff --git a/vector/src/main/java/im/vector/riotx/features/crypto/util/Extensions.kt b/vector/src/main/java/im/vector/riotx/features/crypto/util/Extensions.kt new file mode 100644 index 0000000000..f4885498c3 --- /dev/null +++ b/vector/src/main/java/im/vector/riotx/features/crypto/util/Extensions.kt @@ -0,0 +1,32 @@ +/* + * Copyright 2020 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.riotx.features.crypto.util + +import androidx.annotation.DrawableRes +import im.vector.matrix.android.api.crypto.RoomEncryptionTrustLevel +import im.vector.riotx.R +import im.vector.riotx.core.extensions.exhaustive + +@DrawableRes +fun RoomEncryptionTrustLevel?.toImageRes(): Int { + return when (this) { + null -> 0 + RoomEncryptionTrustLevel.Default -> R.drawable.ic_shield_black + RoomEncryptionTrustLevel.Warning -> R.drawable.ic_shield_warning + RoomEncryptionTrustLevel.Trusted -> R.drawable.ic_shield_trusted + }.exhaustive +} diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt index e51c25b0e9..6bc423ba7b 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt @@ -116,6 +116,7 @@ import im.vector.riotx.features.attachments.AttachmentTypeSelectorView import im.vector.riotx.features.attachments.AttachmentsHelper import im.vector.riotx.features.attachments.ContactAttachment import im.vector.riotx.features.command.Command +import im.vector.riotx.features.crypto.util.toImageRes import im.vector.riotx.features.crypto.verification.VerificationBottomSheet import im.vector.riotx.features.home.AvatarRenderer import im.vector.riotx.features.home.room.detail.composer.TextComposerView @@ -682,18 +683,23 @@ class RoomDetailFragment @Inject constructor( } private fun renderRoomSummary(state: RoomDetailViewState) { - state.asyncRoomSummary()?.let { - if (it.membership.isLeft()) { + state.asyncRoomSummary()?.let { roomSummary -> + if (roomSummary.membership.isLeft()) { Timber.w("The room has been left") activity?.finish() } else { - roomToolbarTitleView.text = it.displayName - avatarRenderer.render(it.toMatrixItem(), roomToolbarAvatarImageView) + roomToolbarTitleView.text = roomSummary.displayName + avatarRenderer.render(roomSummary.toMatrixItem(), roomToolbarAvatarImageView) - renderSubTitle(state.typingMessage, it.topic) + renderSubTitle(state.typingMessage, roomSummary.topic) + } + jumpToBottomView.count = roomSummary.notificationCount + jumpToBottomView.drawBadge = roomSummary.hasUnreadMessages + + roomToolbarDecorationImageView.let { + it.setImageResource(roomSummary.roomEncryptionTrustLevel.toImageRes()) + it.isVisible = roomSummary.roomEncryptionTrustLevel != null } - jumpToBottomView.count = it.notificationCount - jumpToBottomView.drawBadge = it.hasUnreadMessages } } diff --git a/vector/src/main/res/layout/fragment_room_detail.xml b/vector/src/main/res/layout/fragment_room_detail.xml index 90455f0572..fc360a451f 100644 --- a/vector/src/main/res/layout/fragment_room_detail.xml +++ b/vector/src/main/res/layout/fragment_room_detail.xml @@ -33,6 +33,16 @@ app:layout_constraintTop_toTopOf="parent" tools:src="@tools:sample/avatars" /> + +