From 5b210df7c514e39027f7237a3d7dfa085a1767ec Mon Sep 17 00:00:00 2001 From: Valere Date: Tue, 31 Dec 2019 10:35:50 +0100 Subject: [PATCH] Manage done states + cleaning --- .../crypto/sas/SasVerificationService.kt | 15 +++- .../message/MessageVerificationDoneContent.kt | 10 ++- .../model/rest/KeyVerificationRequest.kt | 2 +- .../tasks/RoomVerificationUpdateTask.kt | 22 ++--- .../DefaultSasVerificationService.kt | 83 +++++++++++++------ .../PendingVerificationRequest.kt | 1 + .../crypto/verification/VerificationInfo.kt | 1 + .../verification/VerificationInfoAccept.kt | 2 +- .../verification/VerificationInfoCancel.kt | 2 +- .../verification/VerificationInfoKey.kt | 2 +- .../verification/VerificationInfoMac.kt | 2 +- .../verification/VerificationInfoReady.kt | 2 +- .../verification/VerificationInfoStart.kt | 2 +- .../verification/SASVerificationActivity.kt | 1 + .../SASVerificationIncomingFragment.kt | 1 + .../SASVerificationShortCodeFragment.kt | 1 + .../SASVerificationStartFragment.kt | 1 + .../SASVerificationVerifiedFragment.kt | 1 + .../verification/SasVerificationViewModel.kt | 1 + .../timeline/factory/EncryptionItemFactory.kt | 1 + .../helper/MessageInformationDataFactory.kt | 1 + .../timeline/item/MessageInformationData.kt | 1 + .../timeline/item/VerificationRequestItem.kt | 14 ++-- 23 files changed, 115 insertions(+), 54 deletions(-) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/crypto/sas/SasVerificationService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/crypto/sas/SasVerificationService.kt index 418b7ac508..83c130571d 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/crypto/sas/SasVerificationService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/crypto/sas/SasVerificationService.kt @@ -55,7 +55,7 @@ interface SasVerificationService { */ fun beginKeyVerification(method: String, userId: String, deviceID: String): String? - fun requestKeyVerificationInDMs(userId: String, roomId: String, callback: MatrixCallback?) : PendingVerificationRequest + fun requestKeyVerificationInDMs(userId: String, roomId: String, callback: MatrixCallback?): PendingVerificationRequest fun beginKeyVerificationInDMs(method: String, transactionId: String, @@ -76,4 +76,17 @@ interface SasVerificationService { fun verificationRequestCreated(pr: PendingVerificationRequest) {} fun verificationRequestUpdated(pr: PendingVerificationRequest) {} } + + companion object { + + fun isValidRequest(age: Long?): Boolean { + if (age == null) return false + val now = System.currentTimeMillis() + val tooInThePast = now - (10 * 60 * 1000) + val fiveMinInMs = 5 * 60 * 1000 + val tooInTheFuture = System.currentTimeMillis() + fiveMinInMs + + return !(age < tooInThePast || age > tooInTheFuture) + } + } } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageVerificationDoneContent.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageVerificationDoneContent.kt index 965fcb79bb..3f4bf1c59f 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageVerificationDoneContent.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageVerificationDoneContent.kt @@ -17,6 +17,8 @@ package im.vector.matrix.android.api.session.room.model.message import com.squareup.moshi.Json import com.squareup.moshi.JsonClass +import im.vector.matrix.android.api.session.events.model.Content +import im.vector.matrix.android.api.session.events.model.toContent import im.vector.matrix.android.api.session.room.model.relation.RelationDefaultContent import im.vector.matrix.android.internal.crypto.verification.VerificationInfo @@ -24,5 +26,11 @@ import im.vector.matrix.android.internal.crypto.verification.VerificationInfo internal data class MessageVerificationDoneContent( @Json(name = "m.relates_to") val relatesTo: RelationDefaultContent? ) : VerificationInfo { - override fun isValid() = true + + override val transactionID: String? + get() = relatesTo?.eventId + + override fun isValid() = transactionID?.isNotEmpty() == true + + override fun toEventContent(): Content? = this.toContent() } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/model/rest/KeyVerificationRequest.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/model/rest/KeyVerificationRequest.kt index 51eed84412..4511db324a 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/model/rest/KeyVerificationRequest.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/model/rest/KeyVerificationRequest.kt @@ -37,7 +37,7 @@ internal data class KeyVerificationRequest( val timestamp: Int, @Json(name = "transaction_id") - var transactionID: String? = null + override var transactionID: String? = null ) : SendToDeviceObject, VerificationInfo { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/tasks/RoomVerificationUpdateTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/tasks/RoomVerificationUpdateTask.kt index 61eff8cf61..ec25c0dd04 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/tasks/RoomVerificationUpdateTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/tasks/RoomVerificationUpdateTask.kt @@ -18,6 +18,7 @@ package im.vector.matrix.android.internal.crypto.tasks import im.vector.matrix.android.api.session.crypto.CryptoService import im.vector.matrix.android.api.session.crypto.MXCryptoError +import im.vector.matrix.android.api.session.crypto.sas.SasVerificationService import im.vector.matrix.android.api.session.events.model.Event import im.vector.matrix.android.api.session.events.model.EventType import im.vector.matrix.android.api.session.events.model.toModel @@ -52,27 +53,16 @@ internal class DefaultRoomVerificationUpdateTask @Inject constructor( override suspend fun execute(params: RoomVerificationUpdateTask.Params) { // TODO ignore initial sync or back pagination? - val now = System.currentTimeMillis() - val tooInThePast = now - (10 * 60 * 1000) - val fiveMinInMs = 5 * 60 * 1000 - val tooInTheFuture = System.currentTimeMillis() + fiveMinInMs - params.events.forEach { event -> Timber.d("## SAS Verification live observer: received msgId: ${event.eventId} msgtype: ${event.type} from ${event.senderId}") Timber.v("## SAS Verification live observer: received msgId: $event") // If the request is in the future by more than 5 minutes or more than 10 minutes in the past, // the message should be ignored by the receiver. - val ageLocalTs = event.ageLocalTs - if (ageLocalTs != null && (now - ageLocalTs) > fiveMinInMs) { - Timber.d("## SAS Verification live observer: msgId: ${event.eventId} is too old (age: ${(now - ageLocalTs)})") - return@forEach - } else { - val eventOrigin = event.originServerTs ?: -1 - if (eventOrigin < tooInThePast || eventOrigin > tooInTheFuture) { - Timber.d("## SAS Verification live observer: msgId: ${event.eventId} is too old (ts: $eventOrigin") - return@forEach - } + + if (!SasVerificationService.isValidRequest(event.ageLocalTs + ?: event.originServerTs)) return@forEach Unit.also { + Timber.d("## SAS Verification live observer: msgId: ${event.eventId} is outdated") } // decrypt if needed? @@ -149,7 +139,7 @@ internal class DefaultRoomVerificationUpdateTask @Inject constructor( EventType.KEY_VERIFICATION_DONE -> { params.sasVerificationService.onRoomEvent(event) } - EventType.MESSAGE -> { + EventType.MESSAGE -> { if (MessageType.MSGTYPE_VERIFICATION_REQUEST == event.getClearContent().toModel()?.type) { params.sasVerificationService.onRoomRequestReceived(event) } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/DefaultSasVerificationService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/DefaultSasVerificationService.kt index a5ac169729..7691427d11 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/DefaultSasVerificationService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/DefaultSasVerificationService.kt @@ -77,6 +77,7 @@ internal class DefaultSasVerificationService @Inject constructor( /** * Map [sender: [PendingVerificationRequest]] + * For now we keep all requests (even terminated ones) during the lifetime of the app. */ private val pendingRequests = HashMap>() @@ -84,7 +85,7 @@ internal class DefaultSasVerificationService @Inject constructor( fun onToDeviceEvent(event: Event) { GlobalScope.launch(coroutineDispatchers.crypto) { when (event.getClearType()) { - EventType.KEY_VERIFICATION_START -> { + EventType.KEY_VERIFICATION_START -> { onStartRequestReceived(event) } EventType.KEY_VERIFICATION_CANCEL -> { @@ -93,13 +94,13 @@ internal class DefaultSasVerificationService @Inject constructor( EventType.KEY_VERIFICATION_ACCEPT -> { onAcceptReceived(event) } - EventType.KEY_VERIFICATION_KEY -> { + EventType.KEY_VERIFICATION_KEY -> { onKeyReceived(event) } - EventType.KEY_VERIFICATION_MAC -> { + EventType.KEY_VERIFICATION_MAC -> { onMacReceived(event) } - else -> { + else -> { // ignore } } @@ -109,7 +110,7 @@ internal class DefaultSasVerificationService @Inject constructor( fun onRoomEvent(event: Event) { GlobalScope.launch(coroutineDispatchers.crypto) { when (event.getClearType()) { - EventType.KEY_VERIFICATION_START -> { + EventType.KEY_VERIFICATION_START -> { onRoomStartRequestReceived(event) } EventType.KEY_VERIFICATION_CANCEL -> { @@ -119,24 +120,24 @@ internal class DefaultSasVerificationService @Inject constructor( EventType.KEY_VERIFICATION_ACCEPT -> { onRoomAcceptReceived(event) } - EventType.KEY_VERIFICATION_KEY -> { + EventType.KEY_VERIFICATION_KEY -> { onRoomKeyRequestReceived(event) } - EventType.KEY_VERIFICATION_MAC -> { + EventType.KEY_VERIFICATION_MAC -> { onRoomMacReceived(event) } - EventType.KEY_VERIFICATION_READY -> { + EventType.KEY_VERIFICATION_READY -> { onRoomReadyReceived(event) } - EventType.KEY_VERIFICATION_DONE -> { - // TODO? + EventType.KEY_VERIFICATION_DONE -> { + onRoomDoneReceived(event) } - EventType.MESSAGE -> { + EventType.MESSAGE -> { if (MessageType.MSGTYPE_VERIFICATION_REQUEST == event.getClearContent().toModel()?.type) { onRoomRequestReceived(event) } } - else -> { + else -> { // ignore } } @@ -247,6 +248,7 @@ internal class DefaultSasVerificationService @Inject constructor( } val pendingVerificationRequest = PendingVerificationRequest( + ageLocalTs = event.ageLocalTs ?: System.currentTimeMillis(), isIncoming = true, otherUserId = senderId, // requestInfo.toUserId, transactionId = event.eventId, @@ -411,7 +413,7 @@ internal class DefaultSasVerificationService @Inject constructor( return } getExistingVerificationRequest(event.senderId ?: "", cancelReq.transactionID)?.let { - updateOutgoingPendingRequest(it.copy(cancelConclusion = safeValueOf(cancelReq.code))) + updatePendingRequest(it.copy(cancelConclusion = safeValueOf(cancelReq.code))) // Should we remove it from the list? } handleOnCancel(event.senderId!!, cancelReq) @@ -433,14 +435,20 @@ internal class DefaultSasVerificationService @Inject constructor( private fun handleOnCancel(otherUserId: String, cancelReq: VerificationInfoCancel) { Timber.v("## SAS onCancelReceived otherUser:$otherUserId reason:${cancelReq.reason}") - val existing = getExistingTransaction(otherUserId, cancelReq.transactionID!!) - if (existing == null) { - Timber.e("## Received invalid cancel request") - return + + val existingTransaction = getExistingTransaction(otherUserId, cancelReq.transactionID!!) + val existingRequest = getExistingVerificationRequest(otherUserId, cancelReq.transactionID!!) + + if (existingRequest != null) { + // Mark this request as cancelled + updatePendingRequest(existingRequest.copy( + cancelConclusion = safeValueOf(cancelReq.code) + )) } - if (existing is SASVerificationTransaction) { - existing.cancelledReason = safeValueOf(cancelReq.code) - existing.state = SasVerificationTxState.OnCancelled + + if (existingTransaction is SASVerificationTransaction) { + existingTransaction.cancelledReason = safeValueOf(cancelReq.code) + existingTransaction.state = SasVerificationTxState.OnCancelled } } @@ -558,6 +566,23 @@ internal class DefaultSasVerificationService @Inject constructor( handleReadyReceived(event.senderId, readyReq) } + private fun onRoomDoneReceived(event: Event) { + val doneReq = event.getClearContent().toModel() + ?.copy( + // relates_to is in clear in encrypted payload + relatesTo = event.content.toModel()?.relatesTo + ) + + if (doneReq == null || doneReq.isValid().not() || event.senderId == null) { + // ignore + Timber.e("## SAS Received invalid Done request") + // TODO should we cancel? + return + } + + handleDoneReceived(event.senderId, doneReq) + } + private fun onMacReceived(event: Event) { val macReq = event.getClearContent().toModel()!! @@ -589,7 +614,16 @@ internal class DefaultSasVerificationService @Inject constructor( Timber.e("## SAS Received Ready for unknown request txId:${readyReq.transactionID} fromDevice ${readyReq.fromDevice}") return } - updateOutgoingPendingRequest(existingRequest.copy(readyInfo = readyReq)) + updatePendingRequest(existingRequest.copy(readyInfo = readyReq)) + } + + private fun handleDoneReceived(senderId: String, doneInfo: VerificationInfo) { + val existingRequest = getExistingVerificationRequest(senderId)?.find { it.transactionId == doneInfo.transactionID } + if (existingRequest == null) { + Timber.e("## SAS Received Done for unknown request txId:${doneInfo.transactionID}") + return + } + updatePendingRequest(existingRequest.copy(isSuccessful = true)) } override fun getExistingTransaction(otherUser: String, tid: String): VerificationTransaction? { @@ -675,6 +709,7 @@ internal class DefaultSasVerificationService @Inject constructor( cryptoService = cryptoService ) val verificationRequest = PendingVerificationRequest( + ageLocalTs = System.currentTimeMillis(), isIncoming = false, localID = params.event.eventId ?: "", otherUserId = userId @@ -694,7 +729,7 @@ internal class DefaultSasVerificationService @Inject constructor( this.callback = object : MatrixCallback { override fun onSuccess(data: SendResponse) { params.event.getClearContent().toModel()?.let { - updateOutgoingPendingRequest(verificationRequest.copy( + updatePendingRequest(verificationRequest.copy( transactionId = data.eventId, requestInfo = it )) @@ -713,7 +748,7 @@ internal class DefaultSasVerificationService @Inject constructor( return verificationRequest } - private fun updateOutgoingPendingRequest(updated: PendingVerificationRequest) { + private fun updatePendingRequest(updated: PendingVerificationRequest) { val requestsForUser = pendingRequests[updated.otherUserId] ?: ArrayList().also { pendingRequests[updated.otherUserId] = it @@ -768,7 +803,7 @@ internal class DefaultSasVerificationService @Inject constructor( CancelCode.User, null // TODO handle error? ) - updateOutgoingPendingRequest(it.copy(readyInfo = readyMsg)) + updatePendingRequest(it.copy(readyInfo = readyMsg)) } } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/PendingVerificationRequest.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/PendingVerificationRequest.kt index 6447b8668b..74b8c95a80 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/PendingVerificationRequest.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/PendingVerificationRequest.kt @@ -23,6 +23,7 @@ import java.util.* * Stores current pending verification requests */ data class PendingVerificationRequest( + val ageLocalTs : Long, val isIncoming: Boolean = false, val localID: String = UUID.randomUUID().toString(), val otherUserId: String, diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/VerificationInfo.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/VerificationInfo.kt index 5fe5c62edd..5a4838831c 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/VerificationInfo.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/VerificationInfo.kt @@ -22,4 +22,5 @@ interface VerificationInfo { fun toEventContent(): Content? = null fun toSendToDeviceObject(): SendToDeviceObject? = null fun isValid() : Boolean + val transactionID: String? } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/VerificationInfoAccept.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/VerificationInfoAccept.kt index 7f639c3bc7..2774a44d49 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/VerificationInfoAccept.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/VerificationInfoAccept.kt @@ -17,7 +17,7 @@ package im.vector.matrix.android.internal.crypto.verification internal interface VerificationInfoAccept : VerificationInfo { - val transactionID: String? + override val transactionID: String? /** * The key agreement protocol that Bob’s device has selected to use, out of the list proposed by Alice’s device diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/VerificationInfoCancel.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/VerificationInfoCancel.kt index 2970358a15..b9bd2cebee 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/VerificationInfoCancel.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/VerificationInfoCancel.kt @@ -17,7 +17,7 @@ package im.vector.matrix.android.internal.crypto.verification internal interface VerificationInfoCancel : VerificationInfo { - val transactionID: String? + override val transactionID: String? /** * machine-readable reason for cancelling, see [CancelCode] */ diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/VerificationInfoKey.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/VerificationInfoKey.kt index e5deb63b56..99edb53e79 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/VerificationInfoKey.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/VerificationInfoKey.kt @@ -20,7 +20,7 @@ package im.vector.matrix.android.internal.crypto.verification */ internal interface VerificationInfoKey : VerificationInfo { - val transactionID: String? + override val transactionID: String? /** * The device’s ephemeral public key, as an unpadded base64 string */ diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/VerificationInfoMac.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/VerificationInfoMac.kt index 01fc865250..ace1210986 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/VerificationInfoMac.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/VerificationInfoMac.kt @@ -17,7 +17,7 @@ package im.vector.matrix.android.internal.crypto.verification internal interface VerificationInfoMac : VerificationInfo { - val transactionID: String? + override val transactionID: String? /** * A map of key ID to the MAC of the key, as an unpadded base64 string, calculated using the MAC key diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/VerificationInfoReady.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/VerificationInfoReady.kt index 87436f5686..0c5312987e 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/VerificationInfoReady.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/VerificationInfoReady.kt @@ -24,7 +24,7 @@ package im.vector.matrix.android.internal.crypto.verification */ interface VerificationInfoReady : VerificationInfo { - val transactionID: String? + override val transactionID: String? /** * The ID of the device that sent the m.key.verification.ready message diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/VerificationInfoStart.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/VerificationInfoStart.kt index 2248a239fb..d0cfe06815 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/VerificationInfoStart.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/VerificationInfoStart.kt @@ -28,7 +28,7 @@ internal interface VerificationInfoStart : VerificationInfo { * This string must be unique for the pair of users performing verification for the duration that the transaction is valid. * Alice’s device should record this ID and use it in future messages in this transaction. */ - val transactionID: String? + override val transactionID: String? /** * An array of key agreement protocols that Alice’s client understands. diff --git a/vector/src/main/java/im/vector/riotx/features/crypto/verification/SASVerificationActivity.kt b/vector/src/main/java/im/vector/riotx/features/crypto/verification/SASVerificationActivity.kt index cf80bf98fc..222891eb3d 100644 --- a/vector/src/main/java/im/vector/riotx/features/crypto/verification/SASVerificationActivity.kt +++ b/vector/src/main/java/im/vector/riotx/features/crypto/verification/SASVerificationActivity.kt @@ -31,6 +31,7 @@ import im.vector.riotx.core.extensions.observeEvent import im.vector.riotx.core.platform.SimpleFragmentActivity import im.vector.riotx.core.platform.WaitingViewData +// TODO Deprecated("replaced by bottomsheet UX") class SASVerificationActivity : SimpleFragmentActivity() { companion object { diff --git a/vector/src/main/java/im/vector/riotx/features/crypto/verification/SASVerificationIncomingFragment.kt b/vector/src/main/java/im/vector/riotx/features/crypto/verification/SASVerificationIncomingFragment.kt index 61f5c5f9fe..cb96900ba7 100644 --- a/vector/src/main/java/im/vector/riotx/features/crypto/verification/SASVerificationIncomingFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/crypto/verification/SASVerificationIncomingFragment.kt @@ -29,6 +29,7 @@ import im.vector.riotx.core.platform.VectorBaseFragment import im.vector.riotx.features.home.AvatarRenderer import javax.inject.Inject +// TODO Deprecated("replaced by bottomsheet UX") class SASVerificationIncomingFragment @Inject constructor( private var avatarRenderer: AvatarRenderer ) : VectorBaseFragment() { diff --git a/vector/src/main/java/im/vector/riotx/features/crypto/verification/SASVerificationShortCodeFragment.kt b/vector/src/main/java/im/vector/riotx/features/crypto/verification/SASVerificationShortCodeFragment.kt index ec9a943449..64c1c4b1f0 100644 --- a/vector/src/main/java/im/vector/riotx/features/crypto/verification/SASVerificationShortCodeFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/crypto/verification/SASVerificationShortCodeFragment.kt @@ -29,6 +29,7 @@ import im.vector.riotx.R import im.vector.riotx.core.platform.VectorBaseFragment import javax.inject.Inject +// TODO Deprecated("replaced by bottomsheet UX") class SASVerificationShortCodeFragment @Inject constructor(): VectorBaseFragment() { private lateinit var viewModel: SasVerificationViewModel diff --git a/vector/src/main/java/im/vector/riotx/features/crypto/verification/SASVerificationStartFragment.kt b/vector/src/main/java/im/vector/riotx/features/crypto/verification/SASVerificationStartFragment.kt index d33167518f..4e9699e853 100644 --- a/vector/src/main/java/im/vector/riotx/features/crypto/verification/SASVerificationStartFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/crypto/verification/SASVerificationStartFragment.kt @@ -32,6 +32,7 @@ import im.vector.riotx.core.platform.VectorBaseActivity import im.vector.riotx.core.platform.VectorBaseFragment import javax.inject.Inject +// TODO Deprecated("replaced by bottomsheet UX") class SASVerificationStartFragment @Inject constructor(): VectorBaseFragment() { override fun getLayoutResId() = R.layout.fragment_sas_verification_start diff --git a/vector/src/main/java/im/vector/riotx/features/crypto/verification/SASVerificationVerifiedFragment.kt b/vector/src/main/java/im/vector/riotx/features/crypto/verification/SASVerificationVerifiedFragment.kt index 17beb21aff..fe7f9861b0 100644 --- a/vector/src/main/java/im/vector/riotx/features/crypto/verification/SASVerificationVerifiedFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/crypto/verification/SASVerificationVerifiedFragment.kt @@ -21,6 +21,7 @@ import im.vector.riotx.R import im.vector.riotx.core.platform.VectorBaseFragment import javax.inject.Inject +// TODO Deprecated("replaced by bottomsheet UX") class SASVerificationVerifiedFragment @Inject constructor() : VectorBaseFragment() { override fun getLayoutResId() = R.layout.fragment_sas_verification_verified diff --git a/vector/src/main/java/im/vector/riotx/features/crypto/verification/SasVerificationViewModel.kt b/vector/src/main/java/im/vector/riotx/features/crypto/verification/SasVerificationViewModel.kt index f14a85c516..ca283e449d 100644 --- a/vector/src/main/java/im/vector/riotx/features/crypto/verification/SasVerificationViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/crypto/verification/SasVerificationViewModel.kt @@ -27,6 +27,7 @@ import im.vector.matrix.android.api.session.user.model.User import im.vector.riotx.core.utils.LiveEvent import javax.inject.Inject +// TODO Deprecated("replaced by bottomsheet UX") class SasVerificationViewModel @Inject constructor() : ViewModel(), SasVerificationService.SasVerificationListener { diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/factory/EncryptionItemFactory.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/factory/EncryptionItemFactory.kt index 29b01120d1..696cc7d904 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/factory/EncryptionItemFactory.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/factory/EncryptionItemFactory.kt @@ -46,6 +46,7 @@ class EncryptionItemFactory @Inject constructor(private val stringProvider: Stri eventId = event.root.eventId ?: "?", senderId = event.root.senderId ?: "", sendState = event.root.sendState, + ageLocalTS = event.root.ageLocalTs, avatarUrl = event.senderAvatar, memberName = event.getDisambiguatedDisplayName(), showInformation = false, diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/helper/MessageInformationDataFactory.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/helper/MessageInformationDataFactory.kt index 049998f093..96a90f82c4 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/helper/MessageInformationDataFactory.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/helper/MessageInformationDataFactory.kt @@ -73,6 +73,7 @@ class MessageInformationDataFactory @Inject constructor(private val session: Ses senderId = event.root.senderId ?: "", sendState = event.root.sendState, time = time, + ageLocalTS = event.root.ageLocalTs, avatarUrl = avatarUrl, memberName = formattedMemberName, showInformation = showInformation, diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MessageInformationData.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MessageInformationData.kt index 835a789107..fe5d0d03ca 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MessageInformationData.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MessageInformationData.kt @@ -28,6 +28,7 @@ data class MessageInformationData( val senderId: String, val sendState: SendState, val time: CharSequence? = null, + val ageLocalTS : Long?, val avatarUrl: String?, val memberName: CharSequence? = null, val showInformation: Boolean = true, diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/VerificationRequestItem.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/VerificationRequestItem.kt index db7c4008c0..d00e90760a 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/VerificationRequestItem.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/VerificationRequestItem.kt @@ -28,6 +28,7 @@ import androidx.core.view.isVisible import androidx.core.view.updateLayoutParams import com.airbnb.epoxy.EpoxyAttribute import com.airbnb.epoxy.EpoxyModelClass +import im.vector.matrix.android.api.session.crypto.sas.SasVerificationService import im.vector.matrix.android.internal.session.room.VerificationState import im.vector.riotx.R import im.vector.riotx.core.resources.ColorProvider @@ -72,7 +73,7 @@ abstract class VerificationRequestItem : AbsBaseMessageItem { + null -> { holder.buttonBar.isVisible = !attributes.informationData.sentByMe holder.statusTextView.text = null holder.statusTextView.isVisible = false @@ -82,17 +83,17 @@ abstract class VerificationRequestItem : AbsBaseMessageItem { + VerificationState.CANCELED_BY_ME -> { holder.buttonBar.isVisible = false holder.statusTextView.text = holder.view.context.getString(R.string.verification_request_you_cancelled) holder.statusTextView.isVisible = true } - VerificationState.WAITING -> { + VerificationState.WAITING -> { holder.buttonBar.isVisible = false holder.statusTextView.text = holder.view.context.getString(R.string.verification_request_waiting) holder.statusTextView.isVisible = true } - VerificationState.DONE -> { + VerificationState.DONE -> { holder.buttonBar.isVisible = false holder.statusTextView.text = if (attributes.informationData.sentByMe) { holder.view.context.getString(R.string.verification_request_other_accepted, attributes.otherUserName) @@ -101,13 +102,16 @@ abstract class VerificationRequestItem : AbsBaseMessageItem { + else -> { holder.buttonBar.isVisible = false holder.statusTextView.text = null holder.statusTextView.isVisible = false } } + // Always hide buttons if request is too old + holder.buttonBar.isVisible = holder.buttonBar.isVisible && SasVerificationService.isValidRequest(attributes.informationData.ageLocalTS) + holder.callback = callback holder.attributes = attributes