Fix / Decline request was not implemented

This commit is contained in:
Valere 2020-01-02 16:12:20 +01:00
parent 52c25b803f
commit bf28f14b8b
7 changed files with 38 additions and 14 deletions

View File

@ -57,6 +57,8 @@ interface SasVerificationService {
fun requestKeyVerificationInDMs(userId: String, roomId: String): PendingVerificationRequest
fun declineVerificationRequestInDMs(otherUserId: String, otherDeviceId: String, transactionId: String, roomId: String)
fun beginKeyVerificationInDMs(method: String,
transactionId: String,
roomId: String,

View File

@ -704,6 +704,16 @@ internal class DefaultSasVerificationService @Inject constructor(
val transport = sasTransportRoomMessageFactory.createTransport(context, credentials.userId, credentials.deviceId
?: "", roomId, null)
// Cancel existing pending requests?
requestsForUser.forEach { existingRequest ->
existingRequest.transactionId?.let { tid ->
if (!existingRequest.isFinished) {
Timber.d("## SAS, cancelling pending requests to start a new one")
transport.cancelTransaction(tid, existingRequest.otherUserId, "", CancelCode.User)
}
}
}
val localID = LocalEcho.createLocalEchoId()
val verificationRequest = PendingVerificationRequest(
@ -727,6 +737,17 @@ internal class DefaultSasVerificationService @Inject constructor(
return verificationRequest
}
override fun declineVerificationRequestInDMs(otherUserId: String, otherDeviceId: String, transactionId: String, roomId: String) {
sasTransportRoomMessageFactory.createTransport(context, credentials.userId, credentials.deviceId
?: "", roomId, null).cancelTransaction(transactionId, otherUserId, otherDeviceId, CancelCode.User)
getExistingVerificationRequest(otherUserId, transactionId)?.let {
updatePendingRequest(it.copy(
cancelConclusion = CancelCode.User
))
}
}
private fun updatePendingRequest(updated: PendingVerificationRequest) {
val requestsForUser = pendingRequests[updated.otherUserId]
?: ArrayList<PendingVerificationRequest>().also {

View File

@ -37,4 +37,6 @@ data class PendingVerificationRequest(
val isReady: Boolean = readyInfo != null
val isSent: Boolean = transactionId != null
val isFinished: Boolean = isSuccessful || cancelConclusion != null
}

View File

@ -146,7 +146,11 @@ class VerificationBottomSheet : VectorBaseBottomSheetDialogFragment() {
}
// Transaction has not yet started
if (it.pendingRequest == null || !it.pendingRequest.isReady) {
if (it.pendingRequest?.cancelConclusion != null) {
// The request has been declined, we should dismiss
dismiss()
} else if (it.pendingRequest == null || !it.pendingRequest.isReady) {
// We are waiting for other party to reply with ready
showFragment(VerificationRequestFragment::class, Bundle().apply {
putParcelable(MvRx.KEY_ARG, VerificationArgs(it.otherUserMxItem?.id ?: ""))
})

View File

@ -65,7 +65,7 @@ sealed class RoomDetailAction : VectorViewModelAction {
object ResendAll : RoomDetailAction()
data class AcceptVerificationRequest(val transactionId: String, val otherUserId: String, val otherdDeviceId: String) : RoomDetailAction()
data class DeclineVerificationRequest(val transactionId: String) : RoomDetailAction()
data class DeclineVerificationRequest(val transactionId: String, val otherUserId: String, val otherdDeviceId: String) : RoomDetailAction()
data class RequestVerification(val userId: String) : RoomDetailAction()
}

View File

@ -27,7 +27,6 @@ import com.squareup.inject.assisted.Assisted
import com.squareup.inject.assisted.AssistedInject
import im.vector.matrix.android.api.MatrixCallback
import im.vector.matrix.android.api.MatrixPatterns
import im.vector.matrix.android.api.failure.Failure
import im.vector.matrix.android.api.session.Session
import im.vector.matrix.android.api.session.events.model.EventType
import im.vector.matrix.android.api.session.events.model.isImageMessage
@ -185,7 +184,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
is RoomDetailAction.ExitTrackingUnreadMessagesState -> stopTrackingUnreadMessages()
is RoomDetailAction.AcceptVerificationRequest -> handleAcceptVerification(action)
is RoomDetailAction.DeclineVerificationRequest -> handleDeclineVerification(action)
is RoomDetailAction.RequestVerification -> handleRequestVerification(action)
is RoomDetailAction.RequestVerification -> handleRequestVerification(action)
}
}
@ -799,18 +798,14 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
session.getSasVerificationService().readyPendingVerificationInDMs(action.otherUserId, room.roomId,
action.transactionId)
_requestLiveData.postValue(LiveEvent(Success(action)))
// session.getSasVerificationService().beginKeyVerificationInDMs(
// KeyVerificationStart.VERIF_METHOD_SAS,
// action.transactionId,
// room.roomId,
// action.otherUserMxItem,
// action.otherdDeviceId,
// null
// )
}
private fun handleDeclineVerification(action: RoomDetailAction.DeclineVerificationRequest) {
Timber.e("TODO implement $action")
session.getSasVerificationService().declineVerificationRequestInDMs(
action.otherUserId,
action.otherdDeviceId,
action.transactionId,
room.roomId)
}
private fun handleRequestVerification(action: RoomDetailAction.RequestVerification) {

View File

@ -137,7 +137,7 @@ abstract class VerificationRequestItem : AbsBaseMessageItem<VerificationRequestI
att.otherUserId,
att.fromDevide))
} else if (it == declineButton) {
callback?.onTimelineItemAction(RoomDetailAction.DeclineVerificationRequest(att.referenceId))
callback?.onTimelineItemAction(RoomDetailAction.DeclineVerificationRequest(att.referenceId, att.otherUserId, att.fromDevide))
}
})