This commit is contained in:
Valere 2019-12-30 18:42:32 +01:00
parent 6bf3a703df
commit 3eed9b5083
16 changed files with 19 additions and 59 deletions

View File

@ -25,10 +25,8 @@ import im.vector.matrix.android.api.session.room.model.message.*
import im.vector.matrix.android.internal.crypto.algorithms.olm.OlmDecryptionResult
import im.vector.matrix.android.internal.crypto.verification.DefaultSasVerificationService
import im.vector.matrix.android.internal.di.DeviceId
import im.vector.matrix.android.internal.di.SessionDatabase
import im.vector.matrix.android.internal.di.UserId
import im.vector.matrix.android.internal.task.Task
import io.realm.RealmConfiguration
import timber.log.Timber
import java.util.*
import javax.inject.Inject
@ -51,8 +49,7 @@ internal class DefaultRoomVerificationUpdateTask @Inject constructor(
private val transactionsHandledByOtherDevice = ArrayList<String>()
}
override suspend fun execute(params: RoomVerificationUpdateTask.Params): Unit {
override suspend fun execute(params: RoomVerificationUpdateTask.Params) {
// TODO ignore initial sync or back pagination?
val now = System.currentTimeMillis()
@ -160,5 +157,4 @@ internal class DefaultRoomVerificationUpdateTask @Inject constructor(
}
}
}
}

View File

@ -196,13 +196,13 @@ internal class DefaultSasVerificationService @Inject constructor(
val senderId = event.senderId ?: return
if (requestInfo.toUserId != credentials.userId) {
//I should ignore this, it's not for me
// I should ignore this, it's not for me
Timber.w("## SAS Verification ignoring request from ${event.senderId}, not sent to me")
return
}
if(checkKeysAreDownloaded(senderId, requestInfo.fromDevice) == null) {
//I should ignore this, it's not for me
if (checkKeysAreDownloaded(senderId, requestInfo.fromDevice) == null) {
// I should ignore this, it's not for me
Timber.e("## SAS Verification device ${requestInfo.fromDevice} is not knwon")
// TODO cancel?
return
@ -216,7 +216,7 @@ internal class DefaultSasVerificationService @Inject constructor(
val pendingVerificationRequest = PendingVerificationRequest(
isIncoming = true,
otherUserId = senderId,//requestInfo.toUserId,
otherUserId = senderId, // requestInfo.toUserId,
transactionId = event.eventId,
requestInfo = requestInfo
)
@ -512,13 +512,12 @@ internal class DefaultSasVerificationService @Inject constructor(
// TODO should we cancel?
return
}
if(checkKeysAreDownloaded(event.senderId, readyReq.fromDevice ?: "") == null) {
if (checkKeysAreDownloaded(event.senderId, readyReq.fromDevice ?: "") == null) {
Timber.e("## SAS Verification device ${readyReq.fromDevice} is not knwown")
// TODO cancel?
return
}
handleReadyReceived(event.senderId, readyReq)
}
@ -616,8 +615,7 @@ internal class DefaultSasVerificationService @Inject constructor(
override fun requestKeyVerificationInDMs(userId: String, roomId: String, callback: MatrixCallback<String>?)
: PendingVerificationRequest {
Timber.i("## SAS Requesting verification to user: $userId in room ${roomId}")
Timber.i("## SAS Requesting verification to user: $userId in room $roomId")
val requestsForUser = pendingRequests[userId]
?: ArrayList<PendingVerificationRequest>().also {
pendingRequests[userId] = it

View File

@ -68,6 +68,5 @@ internal class VerificationMessageLiveObserver @Inject constructor(
roomVerificationUpdateTask.configureWith(
RoomVerificationUpdateTask.Params(events, sasVerificationService, cryptoService)
).executeBy(taskExecutor)
}
}

View File

@ -273,7 +273,6 @@ interface FragmentModule {
@FragmentKey(SoftLogoutFragment::class)
fun bindSoftLogoutFragment(fragment: SoftLogoutFragment): Fragment
@Binds
@IntoMap
@FragmentKey(VerificationRequestFragment::class)
@ -284,13 +283,11 @@ interface FragmentModule {
@FragmentKey(VerificationChooseMethodFragment::class)
fun bindVerificationMethodChooserFragment(fragment: VerificationChooseMethodFragment): Fragment
@Binds
@IntoMap
@FragmentKey(SASVerificationCodeFragment::class)
fun bindVerificationSasCodeFragment(fragment: SASVerificationCodeFragment): Fragment
@Binds
@IntoMap
@FragmentKey(VerificationConclusionFragment::class)

View File

@ -37,7 +37,6 @@ class SASVerificationCodeFragment @Inject constructor(
@BindView(R.id.sas_emoji_grid)
lateinit var emojiGrid: ViewGroup
@BindView(R.id.sas_decimal_code)
lateinit var decimalTextView: TextView
@ -56,7 +55,6 @@ class SASVerificationCodeFragment @Inject constructor(
@BindView(R.id.emoji6)
lateinit var emoji6View: ViewGroup
private val viewModel by fragmentViewModel(SASVerificationCodeViewModel::class)
private val sharedViewModel by parentFragmentViewModel(VerificationBottomSheetViewModel::class)
@ -65,7 +63,7 @@ class SASVerificationCodeFragment @Inject constructor(
if (state.supportsEmoji) {
decimalTextView.isVisible = false
when(val emojiDescription = state.emojiDescription) {
when (val emojiDescription = state.emojiDescription) {
is Success -> {
sasLoadingProgress.isVisible = false
emojiGrid.isVisible = true
@ -104,20 +102,19 @@ class SASVerificationCodeFragment @Inject constructor(
}
if (state.isWaitingFromOther) {
//hide buttons
// hide buttons
ButtonsVisibilityGroup.isInvisible = true
sasCodeWaitingPartnerText.isVisible = true
} else {
ButtonsVisibilityGroup.isVisible = true
sasCodeWaitingPartnerText.isVisible = false
}
}
is Fail -> {
sasLoadingProgress.isVisible = false
emojiGrid.isInvisible = true
ButtonsVisibilityGroup.isInvisible = true
//TODO?
// TODO?
}
else -> {
sasLoadingProgress.isVisible = true
@ -126,15 +123,15 @@ class SASVerificationCodeFragment @Inject constructor(
}
}
} else {
//Decimal
// Decimal
emojiGrid.isInvisible = true
decimalTextView.isVisible = true
val decimalCode = state.decimalDescription.invoke()
decimalTextView.text = decimalCode
//TODO
// TODO
if (state.isWaitingFromOther) {
//hide buttons
// hide buttons
ButtonsVisibilityGroup.isInvisible = true
sasCodeWaitingPartnerText.isVisible = true
} else {
@ -144,10 +141,9 @@ class SASVerificationCodeFragment @Inject constructor(
}
}
@OnClick(R.id.sas_request_continue_button)
fun onMatchButtonTapped() = withState(viewModel) { state ->
//UX echo
// UX echo
ButtonsVisibilityGroup.isInvisible = true
sasCodeWaitingPartnerText.isVisible = true
sharedViewModel.handle(VerificationAction.SASMatchAction(state.otherUserId, state.transactionId))
@ -155,10 +151,9 @@ class SASVerificationCodeFragment @Inject constructor(
@OnClick(R.id.sas_request_cancel_button)
fun onDoNotMatchButtonTapped() = withState(viewModel) { state ->
//UX echo
// UX echo
ButtonsVisibilityGroup.isInvisible = true
sasCodeWaitingPartnerText.isVisible = true
sharedViewModel.handle(VerificationAction.SASDoNotMatchAction(state.otherUserId, state.transactionId))
}
}

View File

@ -41,8 +41,7 @@ data class SASVerificationCodeViewState(
class SASVerificationCodeViewModel @AssistedInject constructor(
@Assisted initialState: SASVerificationCodeViewState,
private val session: Session
) : VectorViewModel<SASVerificationCodeViewState, EmptyAction>(initialState)
, SasVerificationService.SasVerificationListener {
) : VectorViewModel<SASVerificationCodeViewState, EmptyAction>(initialState), SasVerificationService.SasVerificationListener {
init {
withState { state ->
@ -165,6 +164,5 @@ class SASVerificationCodeViewModel @AssistedInject constructor(
}
override fun handle(action: EmptyAction) {
}
}

View File

@ -24,7 +24,6 @@ import im.vector.matrix.android.api.session.crypto.sas.SasVerificationService
import im.vector.matrix.android.api.session.crypto.sas.SasVerificationTransaction
import im.vector.matrix.android.api.session.crypto.sas.SasVerificationTxState
import im.vector.matrix.android.api.session.user.model.User
import im.vector.matrix.android.internal.crypto.verification.PendingVerificationRequest
import im.vector.riotx.core.utils.LiveEvent
import javax.inject.Inject

View File

@ -56,7 +56,6 @@ class VerificationBottomSheet : VectorBaseBottomSheetDialogFragment() {
val roomId: String? = null
) : Parcelable
@Inject
lateinit var verificationRequestViewModelFactory: VerificationRequestViewModel.Factory
@Inject
@ -99,7 +98,6 @@ class VerificationBottomSheet : VectorBaseBottomSheetDialogFragment() {
}
override fun invalidate() = withState(viewModel) {
it.otherUserMxItem?.let { matrixItem ->
val displayName = matrixItem.displayName ?: ""
otherUserNameText.text = getString(R.string.verification_request_alert_title, displayName)
@ -111,7 +109,6 @@ class VerificationBottomSheet : VectorBaseBottomSheetDialogFragment() {
// Did the request result in a SAS transaction?
if (it.sasTransactionState != null) {
when (it.sasTransactionState) {
SasVerificationTxState.None,
SasVerificationTxState.SendingStart,
@ -148,7 +145,6 @@ class VerificationBottomSheet : VectorBaseBottomSheetDialogFragment() {
return@withState
}
// Transaction has not yet started
if (it.pendingRequest == null || !it.pendingRequest.isReady) {
showFragment(VerificationRequestFragment::class, Bundle().apply {
@ -159,7 +155,6 @@ class VerificationBottomSheet : VectorBaseBottomSheetDialogFragment() {
putParcelable(MvRx.KEY_ARG, VerificationArgs(it.otherUserMxItem?.id
?: "", it.pendingRequest.transactionId))
})
}
super.invalidate()
@ -173,7 +168,6 @@ class VerificationBottomSheet : VectorBaseBottomSheetDialogFragment() {
}
// Commit now, to ensure changes occurs before next rendering frame (or bottomsheet want animate)
childFragmentManager.commitTransactionNow {
replace(R.id.bottomSheetFragmentContainer,
fragmentClass.java,
bundle,
@ -184,7 +178,6 @@ class VerificationBottomSheet : VectorBaseBottomSheetDialogFragment() {
}
}
fun View.getParentCoordinatorLayout(): CoordinatorLayout? {
var current = this as? View
while (current != null) {

View File

@ -34,7 +34,6 @@ import im.vector.riotx.core.platform.VectorViewModel
import im.vector.riotx.core.platform.VectorViewModelAction
import im.vector.riotx.core.utils.LiveEvent
data class VerificationBottomSheetViewState(
val otherUserMxItem: MatrixItem? = null,
val roomId: String? = null,
@ -43,7 +42,6 @@ data class VerificationBottomSheetViewState(
val cancelCode: CancelCode? = null
) : MvRxState
sealed class VerificationAction : VectorViewModelAction {
data class RequestVerificationByDM(val userID: String, val roomId: String?) : VerificationAction()
data class StartSASVerification(val userID: String, val pendingRequestTransactionId: String) : VerificationAction()
@ -57,7 +55,6 @@ class VerificationBottomSheetViewModel @AssistedInject constructor(@Assisted ini
: VectorViewModel<VerificationBottomSheetViewState, VerificationAction>(initialState),
SasVerificationService.SasVerificationListener {
// Can be used for several actions, for a one shot result
private val _requestLiveData = MutableLiveData<LiveEvent<Async<VerificationAction>>>()
val requestLiveData: LiveData<LiveEvent<Async<VerificationAction>>>
@ -146,7 +143,6 @@ class VerificationBottomSheetViewModel @AssistedInject constructor(@Assisted ini
}
}
override fun transactionCreated(tx: SasVerificationTransaction) {
transactionUpdated(tx)
}

View File

@ -43,7 +43,6 @@ class VerificationChooseMethodFragment @Inject constructor(
if (state.QRModeAvailable) {
val cSpan = object : ClickableSpan() {
override fun onClick(widget: View) {
}
}
val openLink = getString(R.string.verify_open_camera_link)
@ -65,5 +64,4 @@ class VerificationChooseMethodFragment @Inject constructor(
sharedViewModel.handle(VerificationAction.StartSASVerification(it.otherUserMxItem?.id ?: "", it.pendingRequest?.transactionId
?: ""))
}
}

View File

@ -33,13 +33,11 @@ data class VerificationChooseMethodViewState(
val SASMOdeAvailable: Boolean = false
) : MvRxState
class VerificationChooseMethodViewModel @AssistedInject constructor(
@Assisted initialState: VerificationChooseMethodViewState,
private val session: Session
) : VectorViewModel<VerificationChooseMethodViewState, EmptyAction>(initialState) {
init {
withState { state ->
val pvr = session.getSasVerificationService().getExistingVerificationRequest(state.otherUserId)?.first {
@ -70,8 +68,5 @@ class VerificationChooseMethodViewModel @AssistedInject constructor(
}
}
override fun handle(action: EmptyAction) {}
}

View File

@ -50,7 +50,6 @@ class VerificationConclusionFragment @Inject constructor() : VectorBaseFragment(
verifyConclusionDescription.setTextOrHide(getString(R.string.sas_verified_successful_description))
verifyConclusionBottomDescription.text = getString(R.string.verification_green_shield)
verifyConclusionImageView.setImageDrawable(ContextCompat.getDrawable(requireContext(), R.drawable.ic_shield_trusted))
}
ConclusionState.WARNING -> {
verificationConclusionTitle.text = getString(R.string.verification_conclusion_not_secure)

View File

@ -55,7 +55,7 @@ class VerificationRequestFragment @Inject constructor(
when (state.started) {
is Loading -> {
//Hide the start button, show waiting
// Hide the start button, show waiting
verificationStartButton.isInvisible = true
verificationWaitingText.isVisible = true
val otherUser = state.matrixItem.displayName ?: state.matrixItem.id
@ -79,5 +79,4 @@ class VerificationRequestFragment @Inject constructor(
verificationStartButton.isEnabled = false
sharedViewModel.handle(VerificationAction.RequestVerificationByDM(state.matrixItem.id, state.roomId))
}
}

View File

@ -27,14 +27,12 @@ import im.vector.matrix.android.internal.crypto.verification.PendingVerification
import im.vector.riotx.core.di.HasScreenInjector
import im.vector.riotx.core.platform.VectorViewModel
data class VerificationRequestViewState(
val roomId: String? = null,
val matrixItem: MatrixItem,
val started: Async<Boolean> = Success(false)
) : MvRxState
class VerificationRequestViewModel @AssistedInject constructor(
@Assisted initialState: VerificationRequestViewState,
private val session: Session

View File

@ -1130,7 +1130,7 @@ class RoomDetailFragment @Inject constructor(
}
override fun onAvatarClicked(informationData: MessageInformationData) {
//vectorBaseActivity.notImplemented("Click on user avatar")
// vectorBaseActivity.notImplemented("Click on user avatar")
roomDetailViewModel.handle(RoomDetailAction.RequestVerification(informationData.senderId))
}

View File

@ -796,7 +796,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
}
private fun handleAcceptVerification(action: RoomDetailAction.AcceptVerificationRequest) {
session.getSasVerificationService().readyPendingVerificationInDMs(action.otherUserId,room.roomId,
session.getSasVerificationService().readyPendingVerificationInDMs(action.otherUserId, room.roomId,
action.transactionId)
_requestLiveData.postValue(LiveEvent(Success(action)))
// session.getSasVerificationService().beginKeyVerificationInDMs(