fix cancel user verification

remove dead code
This commit is contained in:
valere 2023-01-15 17:13:00 +01:00
parent c0397875f0
commit 607f375bcd
30 changed files with 72 additions and 3436 deletions

View file

@ -2510,6 +2510,8 @@
<string name="verify_new_session_was_not_me">This wasnt me</string>
<string name="verify_new_session_compromized">Your account may be compromised</string>
<string name="_resume">Resume</string>
<string name="verify_cancel_self_verification_from_untrusted">If you cancel, you wont be able to read encrypted messages on this device, and other users wont trust it</string>
<string name="verify_cancel_self_verification_from_trusted">If you cancel, you wont be able to read encrypted messages on your new device, and other users wont trust it</string>
<string name="verify_cancel_other">You wont verify %1$s (%2$s) if you cancel now. Start again in their user profile.</string>

View file

@ -18,7 +18,6 @@ package im.vector.app.features.crypto.verification
import im.vector.app.core.platform.VectorViewModelAction
// TODO Remove otherUserId and transactionId when it's not necessary. Should be known by the ViewModel, no?
sealed class VerificationAction : VectorViewModelAction {
object RequestVerificationByDM : VerificationAction()
object RequestSelfVerification : VerificationAction()

View file

@ -1,439 +0,0 @@
// /*
// * Copyright 2019 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.app.features.crypto.verification
//
// import android.app.Activity
// import android.app.Dialog
// import android.os.Bundle
// import android.os.Parcelable
// import android.view.KeyEvent
// import android.view.LayoutInflater
// import android.view.View
// import android.view.ViewGroup
// import androidx.fragment.app.Fragment
// import com.airbnb.mvrx.fragmentViewModel
// import com.airbnb.mvrx.withState
// import com.google.android.material.dialog.MaterialAlertDialogBuilder
// import dagger.hilt.android.AndroidEntryPoint
// import im.vector.app.R
// import im.vector.app.core.extensions.commitTransaction
// import im.vector.app.core.extensions.registerStartForActivityResult
// import im.vector.app.core.extensions.toMvRxBundle
// import im.vector.app.core.platform.VectorBaseActivity
// import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment
// import im.vector.app.databinding.BottomSheetVerificationBinding
// import im.vector.app.features.crypto.quads.SharedSecureStorageActivity
// import im.vector.app.features.crypto.verification.cancel.VerificationCancelFragment
// import im.vector.app.features.crypto.verification.cancel.VerificationNotMeFragment
// import im.vector.app.features.crypto.verification.choose.VerificationChooseMethodFragment
// import im.vector.app.features.crypto.verification.conclusion.VerificationConclusionFragment
// import im.vector.app.features.crypto.verification.emoji.VerificationEmojiCodeFragment
// import im.vector.app.features.crypto.verification.qrconfirmation.VerificationQRWaitingFragment
// import im.vector.app.features.crypto.verification.qrconfirmation.VerificationQrScannedByOtherFragment
// import im.vector.app.features.crypto.verification.request.VerificationRequestFragment
// import im.vector.app.features.displayname.getBestName
// import im.vector.app.features.home.AvatarRenderer
// import im.vector.app.features.settings.VectorSettingsActivity
// import kotlinx.parcelize.Parcelize
// import org.matrix.android.sdk.api.session.crypto.crosssigning.KEYBACKUP_SECRET_SSSS_NAME
// import org.matrix.android.sdk.api.session.crypto.crosssigning.MASTER_KEY_SSSS_NAME
// import org.matrix.android.sdk.api.session.crypto.crosssigning.SELF_SIGNING_KEY_SSSS_NAME
// import org.matrix.android.sdk.api.session.crypto.crosssigning.USER_SIGNING_KEY_SSSS_NAME
// import org.matrix.android.sdk.api.session.crypto.model.RoomEncryptionTrustLevel
// import org.matrix.android.sdk.api.session.crypto.verification.CancelCode
// import org.matrix.android.sdk.api.session.crypto.verification.EVerificationState
// import org.matrix.android.sdk.api.session.crypto.verification.VerificationTxState
// import timber.log.Timber
// import javax.inject.Inject
// import kotlin.reflect.KClass
//
// @AndroidEntryPoint
// class VerificationBottomSheet : VectorBaseBottomSheetDialogFragment<BottomSheetVerificationBinding>() {
//
// @Parcelize
// data class VerificationArgs(
// val otherUserId: String,
// // might be null for self verification if there is no device to request to
// // in this case you could use 4S (or reset all)
// val verificationId: String?,
// // val verificationLocalId: String? = null,
// val roomId: String? = null,
// // Special mode where UX should show loading wheel until other session sends a request/tx
// val selfVerificationMode: Boolean = false
// ) : Parcelable
//
// override val showExpanded = true
//
// @Inject
// lateinit var avatarRenderer: AvatarRenderer
//
// private val viewModel by fragmentViewModel(VerificationBottomSheetViewModel::class)
//
// override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): BottomSheetVerificationBinding {
// return BottomSheetVerificationBinding.inflate(inflater, container, false)
// }
//
// init {
// isCancelable = false
// }
//
// override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
// super.onViewCreated(view, savedInstanceState)
//
// viewModel.observeViewEvents {
// when (it) {
// is VerificationBottomSheetViewEvents.Dismiss -> dismiss()
// is VerificationBottomSheetViewEvents.AccessSecretStore -> {
// secretStartForActivityResult.launch(
// SharedSecureStorageActivity.newReadIntent(
// requireContext(),
// null, // use default key
// listOf(MASTER_KEY_SSSS_NAME, USER_SIGNING_KEY_SSSS_NAME, SELF_SIGNING_KEY_SSSS_NAME, KEYBACKUP_SECRET_SSSS_NAME),
// SharedSecureStorageActivity.DEFAULT_RESULT_KEYSTORE_ALIAS
// )
// )
// }
// is VerificationBottomSheetViewEvents.ModalError -> {
// MaterialAlertDialogBuilder(requireContext())
// .setTitle(getString(R.string.dialog_title_error))
// .setMessage(it.errorMessage)
// .setCancelable(false)
// .setPositiveButton(R.string.ok, null)
// .show()
// Unit
// }
// VerificationBottomSheetViewEvents.GoToSettings -> {
// dismiss()
// (activity as? VectorBaseActivity<*>)?.let { activity ->
// activity.navigator.openSettings(activity, VectorSettingsActivity.EXTRA_DIRECT_ACCESS_SECURITY_PRIVACY)
// }
// }
// }
// }
// }
//
// override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
// return super.onCreateDialog(savedInstanceState).apply {
// setOnKeyListener { _, keyCode, keyEvent ->
// if (keyCode == KeyEvent.KEYCODE_BACK && keyEvent.action == KeyEvent.ACTION_UP) {
// viewModel.queryCancel()
// true
// } else {
// false
// }
// }
// }
// }
//
// private val secretStartForActivityResult = registerStartForActivityResult { activityResult ->
// if (activityResult.resultCode == Activity.RESULT_OK) {
// val result = activityResult.data?.getStringExtra(SharedSecureStorageActivity.EXTRA_DATA_RESULT)
// val reset = activityResult.data?.getBooleanExtra(SharedSecureStorageActivity.EXTRA_DATA_RESET, false) ?: false
// if (result != null) {
// viewModel.handle(VerificationAction.GotResultFromSsss(result, SharedSecureStorageActivity.DEFAULT_RESULT_KEYSTORE_ALIAS))
// } else if (reset) {
// // all have been reset, so we are verified?
// viewModel.handle(VerificationAction.SecuredStorageHasBeenReset)
// }
// } else {
// viewModel.handle(VerificationAction.CancelledFromSsss)
// }
// }
//
// override fun invalidate() = withState(viewModel) { state ->
// avatarRenderer.render(state.otherUserMxItem, views.otherUserAvatarImageView)
// if (state.isMe) {
// if (state.sasTransactionState == VerificationTxState.Verified ||
// state.qrTransactionState == VerificationTxState.Verified ||
// state.verifiedFromPrivateKeys) {
// views.otherUserShield.render(RoomEncryptionTrustLevel.Trusted)
// } else {
// views.otherUserShield.render(RoomEncryptionTrustLevel.Warning)
// }
// views.otherUserNameText.text = getString(
// if (state.selfVerificationMode) R.string.crosssigning_verify_this_session else R.string.crosssigning_verify_session
// )
// } else {
// if (state.sasTransactionState == VerificationTxState.Verified || state.qrTransactionState == VerificationTxState.Verified) {
// views.otherUserNameText.text = getString(R.string.verification_verified_user, state.otherUserMxItem.getBestName())
// views.otherUserShield.render(RoomEncryptionTrustLevel.Trusted)
// } else {
// views.otherUserNameText.text = getString(R.string.verification_verify_user, state.otherUserMxItem.getBestName())
// views.otherUserShield.render(null)
// }
// }
//
// if (state.quadSHasBeenReset) {
// showFragment(
// VerificationConclusionFragment::class,
// VerificationConclusionFragment.Args(
// isSuccessFull = true,
// isMe = true,
// cancelReason = null
// )
// )
// return@withState
// }
//
// if (state.userThinkItsNotHim) {
// views.otherUserNameText.text = getString(R.string.dialog_title_warning)
// showFragment(VerificationNotMeFragment::class)
// return@withState
// }
//
// if (state.userWantsToCancel) {
// views.otherUserNameText.text = getString(R.string.are_you_sure)
// showFragment(VerificationCancelFragment::class)
// return@withState
// }
//
// if (state.selfVerificationMode && state.verifyingFrom4S) {
// showFragment(QuadSLoadingFragment::class)
// return@withState
// }
// if (state.selfVerificationMode && state.verifiedFromPrivateKeys) {
// showFragment(
// VerificationConclusionFragment::class,
// VerificationConclusionFragment.Args(true, null, state.isMe)
// )
// return@withState
// }
//
// // Did the request result in a SAS transaction?
// if (state.sasTransactionState != null) {
// when (state.sasTransactionState) {
//
// VerificationTxState.None,
// VerificationTxState.SasStarted,
// VerificationTxState.SasKeySent,
// VerificationTxState.SasShortCodeReady,
// VerificationTxState.SasMacSent,
// is VerificationTxState.SasMacReceived,
// VerificationTxState.SasAccepted -> {
// showFragment(
// VerificationEmojiCodeFragment::class,
// VerificationArgs(
// state.otherUserId,
// // If it was outgoing it.transaction id would be null, but the pending request
// // would be updated (from localId to txId)
// state.pendingRequest.invoke()?.transactionId ?: state.transactionId
// )
// )
// }
// is VerificationTxState.Verified -> {
// showFragment(
// VerificationConclusionFragment::class,
// VerificationConclusionFragment.Args(true, null, state.isMe)
// )
// }
// is VerificationTxState.Cancelled -> {
// showFragment(
// VerificationConclusionFragment::class,
// VerificationConclusionFragment.Args(false, state.sasTransactionState.cancelCode.value, state.isMe)
// )
// }
// else -> Unit
// // is VerificationTxState.None,
// // is VerificationTxState.SendingStart,
// // is VerificationTxState.Started,
// // is VerificationTxState.OnStarted,
// // is VerificationTxState.SendingAccept,
// // is VerificationTxState.Accepted,
// // is VerificationTxState.OnAccepted,
// // is VerificationTxState.SendingKey,
// // is VerificationTxState.KeySent,
// // is VerificationTxState.OnKeyReceived,
// // is VerificationTxState.ShortCodeReady,
// // is VerificationTxState.ShortCodeAccepted,
// // is VerificationTxState.SendingMac,
// // is VerificationTxState.MacSent,
// // is VerificationTxState.Verifying -> {
// // showFragment(
// // VerificationEmojiCodeFragment::class,
// // VerificationArgs(
// // state.otherUserId,
// // // If it was outgoing it.transaction id would be null, but the pending request
// // // would be updated (from localId to txId)
// // state.pendingRequest.invoke()?.transactionId ?: state.transactionId
// // )
// // )
// // }
// // is VerificationTxState.Verified -> {
// // showFragment(
// // VerificationConclusionFragment::class,
// // VerificationConclusionFragment.Args(true, null, state.isMe)
// // )
// // }
// // is VerificationTxState.Cancelled -> {
// // showFragment(
// // VerificationConclusionFragment::class,
// // VerificationConclusionFragment.Args(false, state.sasTransactionState.cancelCode.value, state.isMe)
// // )
// // }
// // else -> Unit
// }
//
// return@withState
// }
//
// when (state.qrTransactionState) {
// is VerificationTxState.QrScannedByOther -> {
// showFragment(VerificationQrScannedByOtherFragment::class)
// return@withState
// }
// //TODO
// // is VerificationTxState.Started,
// is VerificationTxState.WaitingOtherReciprocateConfirm -> {
// showFragment(
// VerificationQRWaitingFragment::class,
// VerificationQRWaitingFragment.Args(
// isMe = state.isMe,
// otherUserName = state.otherUserMxItem.getBestName()
// )
// )
// return@withState
// }
// is VerificationTxState.Verified -> {
// showFragment(
// VerificationConclusionFragment::class,
// VerificationConclusionFragment.Args(true, null, state.isMe)
// )
// return@withState
// }
// is VerificationTxState.Cancelled -> {
// showFragment(
// VerificationConclusionFragment::class,
// VerificationConclusionFragment.Args(false, state.qrTransactionState.cancelCode.value, state.isMe)
// )
// return@withState
// }
// else -> Unit
// }
//
// // At this point there is no SAS transaction for this request
//
// // Transaction has not yet started
// if (state.pendingRequest.invoke()?.cancelConclusion != null) {
// // The request has been declined, we should dismiss
// views.otherUserNameText.text = getString(R.string.verification_cancelled)
// showFragment(
// VerificationConclusionFragment::class,
// VerificationConclusionFragment.Args(
// isSuccessFull = false,
// cancelReason = state.pendingRequest.invoke()?.cancelConclusion?.value ?: CancelCode.User.value,
// isMe = state.isMe
// )
// )
// return@withState
// }
//
// // If it's an outgoing
// if (state.pendingRequest.invoke() == null || state.pendingRequest.invoke()?.isIncoming == false || state.selfVerificationMode) {
// Timber.v("## SAS show bottom sheet for outgoing request")
// if (state.pendingRequest.invoke()?.state == EVerificationState.Ready) {
// Timber.v("## SAS show bottom sheet for outgoing and ready request")
// // Show choose method fragment with waiting
// showFragment(
// VerificationChooseMethodFragment::class,
// VerificationArgs(
// otherUserId = state.otherUserId,
// verificationId = state.pendingRequest.invoke()?.transactionId
// )
// )
// } else {
// // Stay on the start fragment
// showFragment(
// VerificationRequestFragment::class,
// VerificationArgs(
// otherUserId = state.otherUserId,
// verificationId = state.pendingRequest.invoke()?.transactionId,
// )
// )
// }
// } else if (state.pendingRequest.invoke()?.isIncoming == true) {
// Timber.v("## SAS show bottom sheet for Incoming request")
// // For incoming we can switch to choose method because ready is being sent or already sent
// showFragment(
// VerificationChooseMethodFragment::class,
// VerificationArgs(
// otherUserId = state.otherUserId,
// verificationId = state.pendingRequest.invoke()?.transactionId
// )
// )
// }
// super.invalidate()
// }
//
// private fun showFragment(fragmentClass: KClass<out Fragment>, argsParcelable: Parcelable? = null) {
// if (childFragmentManager.findFragmentByTag(fragmentClass.simpleName) == null) {
// childFragmentManager.commitTransaction {
// replace(
// R.id.bottomSheetFragmentContainer,
// fragmentClass.java,
// argsParcelable?.toMvRxBundle(),
// fragmentClass.simpleName
// )
// }
// }
// }
//
// companion object {
// fun withArgs(otherUserId: String, transactionId: String): VerificationBottomSheet {
// return VerificationBottomSheet().apply {
// setArguments(
// VerificationArgs(
// otherUserId = otherUserId,
// verificationId = transactionId,
// )
// )
// }
// }
//
// // fun forSelfVerification(session: Session): VerificationBottomSheet {
// // return VerificationBottomSheet().apply {
// // setArguments(
// // VerificationArgs(
// // otherUserId = session.myUserId,
// // selfVerificationMode = true
// // )
// // )
// // }
// // }
//
// // fun forSelfVerification(session: Session, outgoingRequest: String): VerificationBottomSheet {
// // return VerificationBottomSheet().apply {
// // setArguments(
// // VerificationArgs(
// // otherUserId = session.myUserId,
// // selfVerificationMode = true,
// // verificationId = outgoingRequest
// // )
// // )
// // }
// // }
//
// // const val WAITING_SELF_VERIF_TAG: String = "WAITING_SELF_VERIF_TAG"
// }
// }
//
// // fun View.getParentCoordinatorLayout(): CoordinatorLayout? {
// // var current = this as? View
// // while (current != null) {
// // if (current is CoordinatorLayout) return current
// // current = current.parent as? View
// // }
// // return null
// // }

View file

@ -27,6 +27,7 @@ sealed class VerificationBottomSheetViewEvents : VectorViewEvents {
object AccessSecretStore : VerificationBottomSheetViewEvents()
object ResetAll : VerificationBottomSheetViewEvents()
object GoToSettings : VerificationBottomSheetViewEvents()
data class ConfirmCancel(val otherUserId: String, val deviceId: String?) : VerificationBottomSheetViewEvents()
data class ModalError(val errorMessage: CharSequence) : VerificationBottomSheetViewEvents()
data class RequestNotFound(val transactionId: String) : VerificationBottomSheetViewEvents()
}

View file

@ -1,665 +0,0 @@
// /*
// * Copyright 2019 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.app.features.crypto.verification
//
// import com.airbnb.mvrx.Async
// import com.airbnb.mvrx.Fail
// import com.airbnb.mvrx.Loading
// import com.airbnb.mvrx.MavericksState
// import com.airbnb.mvrx.MavericksViewModelFactory
// import com.airbnb.mvrx.Success
// import com.airbnb.mvrx.Uninitialized
// import dagger.assisted.Assisted
// import dagger.assisted.AssistedFactory
// import dagger.assisted.AssistedInject
// import im.vector.app.R
// import im.vector.app.core.di.MavericksAssistedViewModelFactory
// import im.vector.app.core.di.hiltMavericksViewModelFactory
// import im.vector.app.core.platform.VectorViewModel
// import im.vector.app.core.resources.StringProvider
// import im.vector.app.features.raw.wellknown.getElementWellknown
// import im.vector.app.features.raw.wellknown.isSecureBackupRequired
// import im.vector.app.features.session.coroutineScope
// import kotlinx.coroutines.Dispatchers
// import kotlinx.coroutines.flow.collect
// import kotlinx.coroutines.flow.filter
// import kotlinx.coroutines.flow.launchIn
// import kotlinx.coroutines.flow.onEach
// import kotlinx.coroutines.launch
// import org.matrix.android.sdk.api.Matrix
// import org.matrix.android.sdk.api.extensions.orFalse
// import org.matrix.android.sdk.api.extensions.tryOrNull
// import org.matrix.android.sdk.api.raw.RawService
// import org.matrix.android.sdk.api.session.Session
// import org.matrix.android.sdk.api.session.crypto.crosssigning.KEYBACKUP_SECRET_SSSS_NAME
// import org.matrix.android.sdk.api.session.crypto.crosssigning.MASTER_KEY_SSSS_NAME
// import org.matrix.android.sdk.api.session.crypto.crosssigning.SELF_SIGNING_KEY_SSSS_NAME
// import org.matrix.android.sdk.api.session.crypto.crosssigning.USER_SIGNING_KEY_SSSS_NAME
// import org.matrix.android.sdk.api.session.crypto.crosssigning.isVerified
// import org.matrix.android.sdk.api.session.crypto.keysbackup.BackupUtils
// import org.matrix.android.sdk.api.session.crypto.keysbackup.computeRecoveryKey
// import org.matrix.android.sdk.api.session.crypto.keysbackup.toKeysVersionResult
// import org.matrix.android.sdk.api.session.crypto.verification.CancelCode
// import org.matrix.android.sdk.api.session.crypto.verification.IVerificationRequest
// import org.matrix.android.sdk.api.session.crypto.verification.PendingVerificationRequest
// import org.matrix.android.sdk.api.session.crypto.verification.QrCodeVerificationTransaction
// import org.matrix.android.sdk.api.session.crypto.verification.SasVerificationTransaction
// import org.matrix.android.sdk.api.session.crypto.verification.VerificationEvent
// import org.matrix.android.sdk.api.session.crypto.verification.VerificationMethod
// import org.matrix.android.sdk.api.session.crypto.verification.VerificationService
// import org.matrix.android.sdk.api.session.crypto.verification.VerificationTransaction
// import org.matrix.android.sdk.api.session.crypto.verification.VerificationTxState
// import org.matrix.android.sdk.api.session.events.model.LocalEcho
// import org.matrix.android.sdk.api.session.getUser
// import org.matrix.android.sdk.api.util.MatrixItem
// import org.matrix.android.sdk.api.util.fromBase64
// import org.matrix.android.sdk.api.util.toMatrixItem
// import timber.log.Timber
//
// data class VerificationBottomSheetViewState(
// val otherUserId: String,
// val verificationId: String?,
// val roomId: String?,
// // true when we display the loading and we wait for the other (incoming request)
// val selfVerificationMode: Boolean,
// val otherUserMxItem: MatrixItem,
// val pendingRequest: Async<PendingVerificationRequest> = Uninitialized,
// val pendingLocalId: String? = null,
// val sasTransactionState: VerificationTxState? = null,
// val qrTransactionState: VerificationTxState? = null,
// val transactionId: String? = null,
// val verifiedFromPrivateKeys: Boolean = false,
// val verifyingFrom4S: Boolean = false,
// val isMe: Boolean = false,
// val currentDeviceCanCrossSign: Boolean = false,
// val userWantsToCancel: Boolean = false,
// val userThinkItsNotHim: Boolean = false,
// val quadSContainsSecrets: Boolean = true,
// val isVerificationRequired: Boolean = false,
// val quadSHasBeenReset: Boolean = false,
// val hasAnyOtherSession: Boolean = false
// ) : MavericksState {
//
// constructor(args: VerificationBottomSheet.VerificationArgs) : this(
// otherUserId = args.otherUserId,
// verificationId = args.verificationId,
// selfVerificationMode = args.selfVerificationMode,
// roomId = args.roomId,
// otherUserMxItem = MatrixItem.UserItem(args.otherUserId),
// )
// }
//
// class VerificationBottomSheetViewModel @AssistedInject constructor(
// @Assisted initialState: VerificationBottomSheetViewState,
// private val rawService: RawService,
// private val session: Session,
// private val supportedVerificationMethodsProvider: SupportedVerificationMethodsProvider,
// private val stringProvider: StringProvider,
// private val matrix: Matrix,
// ) :
// VectorViewModel<VerificationBottomSheetViewState, VerificationAction, VerificationBottomSheetViewEvents>(initialState),
// VerificationService.Listener {
//
// @AssistedFactory
// interface Factory : MavericksAssistedViewModelFactory<VerificationBottomSheetViewModel, VerificationBottomSheetViewState> {
// override fun create(initialState: VerificationBottomSheetViewState): VerificationBottomSheetViewModel
// }
//
// companion object : MavericksViewModelFactory<VerificationBottomSheetViewModel, VerificationBottomSheetViewState> by hiltMavericksViewModelFactory()
//
// init {
// // session.cryptoService().verificationService().addListener(this)
//
// // This is async, but at this point should be in cache
// // so it's ok to not wait until result
// viewModelScope.launch(Dispatchers.IO) {
// val wellKnown = rawService.getElementWellknown(session.sessionParams)
// setState {
// copy(isVerificationRequired = wellKnown?.isSecureBackupRequired().orFalse())
// }
// }
//
//
// // viewModelScope.launch {
// //
// // var autoReady = false
// // val pr = if (initialState.selfVerificationMode) {
// // // See if active tx for this user and take it
// //
// // session.cryptoService().verificationService().getExistingVerificationRequests(initialState.otherUserId)
// // .lastOrNull { !it.isFinished }
// // ?.also { verificationRequest ->
// // if (verificationRequest.isIncoming && !verificationRequest.isReady) {
// // // auto ready in this case, as we are waiting
// // autoReady = true
// // }
// // }
// // } else {
// // session.cryptoService().verificationService().getExistingVerificationRequest(initialState.otherUserId, initialState.transactionId)
// // }
// //
// // val sasTx = (pr?.transactionId ?: initialState.transactionId)?.let {
// // session.cryptoService().verificationService().getExistingTransaction(initialState.otherUserId, it) as? SasVerificationTransaction
// // }
// //
// // val qrTx = (pr?.transactionId ?: initialState.transactionId)?.let {
// // session.cryptoService().verificationService().getExistingTransaction(initialState.otherUserId, it) as? QrCodeVerificationTransaction
// // }
// //
// // setState {
// // copy(
// // sasTransactionState = sasTx?.state,
// // qrTransactionState = qrTx?.state,
// // transactionId = pr?.transactionId ?: initialState.transactionId,
// // pendingRequest = if (pr != null) Success(pr) else Uninitialized,
// // isMe = initialState.otherUserId == session.myUserId,
// // currentDeviceCanCrossSign = session.cryptoService().crossSigningService().canCrossSign(),
// // quadSContainsSecrets = session.sharedSecretStorageService().isRecoverySetup(),
// // hasAnyOtherSession = hasAnyOtherSession
// // )
// // }
// //
// // if (autoReady) {
// // // TODO, can I be here in DM mode? in this case should test if roomID is null?
// // session.cryptoService().verificationService()
// // .readyPendingVerification(
// // supportedVerificationMethodsProvider.provide(),
// // pr!!.otherUserId,
// // pr.transactionId ?: ""
// // )
// // }
// // }
// }
//
// private fun fetchOtherUserProfile(otherUserId: String) {
// session.getUser(otherUserId)?.toMatrixItem()?.let {
// setState {
// copy(
// otherUserMxItem = it
// )
// }
// }
// // Always fetch the latest User data
// viewModelScope.launch {
// tryOrNull { session.userService().resolveUser(otherUserId) }
// ?.toMatrixItem()
// ?.let {
// setState {
// copy(
// otherUserMxItem = it
// )
// }
// }
// }
// }
//
// // override fun onCleared() {
// // super.onCleared()
// // }
//
// fun queryCancel() = withState { state ->
// if (state.userThinkItsNotHim) {
// setState {
// copy(userThinkItsNotHim = false)
// }
// } else {
// // if the verification is already done you can't cancel anymore
// if (state.pendingRequest.invoke()?.cancelConclusion != null ||
// // state.sasTransactionState is VerificationTxState.TerminalTxState ||
// state.verifyingFrom4S) {
// // you cannot cancel anymore
// } else {
// if (!state.isVerificationRequired) {
// setState {
// copy(userWantsToCancel = true)
// }
// }
// }
// }
// }
//
// fun confirmCancel() = withState { state ->
// cancelAllPendingVerifications(state)
// _viewEvents.post(VerificationBottomSheetViewEvents.Dismiss)
// }
//
// private fun cancelAllPendingVerifications(state: VerificationBottomSheetViewState) {
// viewModelScope.launch {
// session.cryptoService()
// .verificationService().getExistingVerificationRequest(state.otherUserId, state.transactionId)?.let {
// session.cryptoService().verificationService().cancelVerificationRequest(it)
// }
// session.cryptoService()
// .verificationService()
// .getExistingTransaction(state.otherUserId, state.transactionId ?: "")
// ?.cancel(CancelCode.User)
// }
// }
//
// fun continueFromCancel() {
// setState {
// copy(userWantsToCancel = false)
// }
// }
//
// fun continueFromWasNotMe() {
// setState {
// copy(userThinkItsNotHim = false)
// }
// }
//
// fun itWasNotMe() {
// setState {
// copy(userThinkItsNotHim = true)
// }
// }
//
// fun goToSettings() = withState { state ->
// cancelAllPendingVerifications(state)
// _viewEvents.post(VerificationBottomSheetViewEvents.GoToSettings)
// }
//
// override fun handle(action: VerificationAction) = withState { state ->
// val otherUserId = state.otherUserId
// val roomId = state.roomId
// ?: session.roomService().getExistingDirectRoomWithUser(otherUserId)
//
// when (action) {
// is VerificationAction.RequestVerificationByDM -> {
// setState {
// copy(
// pendingRequest = Loading()
// )
// }
//
// if (roomId == null) {
// // val localId = LocalEcho.createLocalEchoId()
// session.coroutineScope.launch {
// try {
// val roomId = session.roomService().createDirectRoom(otherUserId)
// val request = session
// .cryptoService()
// .verificationService()
// .requestKeyVerificationInDMs(
// supportedVerificationMethodsProvider.provide(),
// otherUserId,
// roomId,
// )
// setState {
// copy(
// roomId = roomId,
// pendingRequest = Success(request),
// transactionId = request.transactionId
// )
// }
// } catch (failure: Throwable) {
// setState {
// copy(pendingRequest = Fail(failure))
// }
// }
// }
// } else {
// session.coroutineScope.launch {
// val request = session
// .cryptoService()
// .verificationService()
// .requestKeyVerificationInDMs(supportedVerificationMethodsProvider.provide(), otherUserId, roomId)
// setState {
// copy(
// pendingRequest = Success(request),
// transactionId = request.transactionId
// )
// }
// }
// }
// Unit
// }
// is VerificationAction.StartSASVerification -> {
// viewModelScope.launch {
// val request = session.cryptoService().verificationService().getExistingVerificationRequest(otherUserId, state.transactionId)
// ?: return@launch
// val otherDevice = request.otherDeviceId
// if (roomId == null) {
// session.cryptoService().verificationService().requestSelfKeyVerification(
// listOf(VerificationMethod.SAS)
// )
// } else {
// session.cryptoService().verificationService().requestKeyVerificationInDMs(
// listOf(VerificationMethod.SAS),
// roomId = roomId,
// otherUserId = request.otherUserId,
// )
// }
// }
// Unit
// }
// is VerificationAction.RemoteQrCodeScanned -> {
// viewModelScope.launch {
// val existingTransaction = session.cryptoService().verificationService()
// .getExistingTransaction(action.otherUserId, action.transactionId) as? QrCodeVerificationTransaction
// existingTransaction
// ?.userHasScannedOtherQrCode(action.scannedData)
// }
// }
// is VerificationAction.OtherUserScannedSuccessfully -> {
// viewModelScope.launch {
// val transactionId = state.transactionId ?: return@launch
//
// val existingTransaction = session.cryptoService().verificationService()
// .getExistingTransaction(otherUserId, transactionId) as? QrCodeVerificationTransaction
// existingTransaction
// ?.otherUserScannedMyQrCode()
// }
// }
// is VerificationAction.OtherUserDidNotScanned -> {
// val transactionId = state.transactionId ?: return@withState
// viewModelScope.launch {
// val existingTransaction = session.cryptoService().verificationService()
// .getExistingTransaction(otherUserId, transactionId) as? QrCodeVerificationTransaction
// existingTransaction
// ?.otherUserDidNotScannedMyQrCode()
// }
// }
// is VerificationAction.SASMatchAction -> {
// val request = state.pendingRequest.invoke() ?: return@withState
// viewModelScope.launch {
// (session.cryptoService().verificationService()
// .getExistingTransaction(request.otherUserId, request.transactionId)
// as? SasVerificationTransaction)?.userHasVerifiedShortCode()
// }
// }
// is VerificationAction.SASDoNotMatchAction -> {
// val request = state.pendingRequest.invoke() ?: return@withState
// viewModelScope.launch {
// (session.cryptoService().verificationService()
// .getExistingTransaction(request.otherUserId, request.transactionId)
// as? SasVerificationTransaction)
// ?.shortCodeDoesNotMatch()
// }
// }
// is VerificationAction.ReadyPendingVerification -> {
// state.pendingRequest.invoke()?.let { request ->
// // will only be there for dm verif
// session.coroutineScope.launch {
// if (state.roomId != null) {
// session.cryptoService().verificationService()
// .readyPendingVerification(
// supportedVerificationMethodsProvider.provide(),
// state.otherUserId,
// request.transactionId
// )
// }
// }
// }
// }
// is VerificationAction.CancelPendingVerification -> {
// state.pendingRequest.invoke()?.let {
// session.coroutineScope.launch {
// session.cryptoService().verificationService()
// .cancelVerificationRequest(it)
// }
// }
// _viewEvents.post(VerificationBottomSheetViewEvents.Dismiss)
// }
// is VerificationAction.GotItConclusion -> {
// if (state.isVerificationRequired && !action.verified) {
// // we should go back to first screen
// setState {
// copy(
// pendingRequest = Uninitialized,
// // sasTransactionState = null,
// // qrTransactionState = null
// )
// }
// } else {
// _viewEvents.post(VerificationBottomSheetViewEvents.Dismiss)
// }
// }
// is VerificationAction.SkipVerification -> {
// _viewEvents.post(VerificationBottomSheetViewEvents.Dismiss)
// }
// is VerificationAction.VerifyFromPassphrase -> {
// setState { copy(verifyingFrom4S = true) }
// _viewEvents.post(VerificationBottomSheetViewEvents.AccessSecretStore)
// }
// is VerificationAction.GotResultFromSsss -> {
// handleSecretBackFromSSSS(action)
// }
// VerificationAction.SecuredStorageHasBeenReset -> {
// if (session.cryptoService().crossSigningService().allPrivateKeysKnown()) {
// setState {
// copy(quadSHasBeenReset = true, verifyingFrom4S = false)
// }
// }
// Unit
// }
// VerificationAction.CancelledFromSsss -> {
// setState {
// copy(verifyingFrom4S = false)
// }
// }
// }
// }
//
// private fun handleSecretBackFromSSSS(action: VerificationAction.GotResultFromSsss) {
// viewModelScope.launch(Dispatchers.IO) {
// try {
// action.cypherData.fromBase64().inputStream().use { ins ->
// val res = matrix.secureStorageService().loadSecureSecret<Map<String, String>>(ins, action.alias)
// val trustResult = session.cryptoService().crossSigningService().checkTrustFromPrivateKeys(
// res?.get(MASTER_KEY_SSSS_NAME),
// res?.get(USER_SIGNING_KEY_SSSS_NAME),
// res?.get(SELF_SIGNING_KEY_SSSS_NAME)
// )
// if (trustResult.isVerified()) {
// // Sign this device and upload the signature
// try {
// session.cryptoService().crossSigningService().trustDevice(session.sessionParams.deviceId)
// } catch (failure: Exception) {
// Timber.w(failure, "Failed to sign my device after recovery")
// }
//
// setState {
// copy(
// verifyingFrom4S = false,
// verifiedFromPrivateKeys = true
// )
// }
//
// // try the keybackup
// tentativeRestoreBackup(res)
// } else {
// setState {
// copy(
// verifyingFrom4S = false
// )
// }
// // POP UP something
// _viewEvents.post(VerificationBottomSheetViewEvents.ModalError(stringProvider.getString(R.string.error_failed_to_import_keys)))
// }
// }
// } catch (failure: Throwable) {
// setState {
// copy(
// verifyingFrom4S = false
// )
// }
// _viewEvents.post(
// VerificationBottomSheetViewEvents.ModalError(failure.localizedMessage ?: stringProvider.getString(R.string.unexpected_error))
// )
// }
// }
// }
//
// private fun tentativeRestoreBackup(res: Map<String, String>?) {
// // on session scope because will happen after viewmodel is cleared
// session.coroutineScope.launch {
// // It's not a good idea to download the full backup, it might take very long
// // and use a lot of resources
// // Just check that the key is valid and store it, the backup will be used megolm session per
// // megolm session when an UISI is encountered
// try {
// val secret = res?.get(KEYBACKUP_SECRET_SSSS_NAME) ?: return@launch Unit.also {
// Timber.v("## Keybackup secret not restored from SSSS")
// }
//
// val version = session.cryptoService().keysBackupService().getCurrentVersion()?.toKeysVersionResult() ?: return@launch
//
// val recoveryKey = computeRecoveryKey(secret.fromBase64())
// val backupRecoveryKey = BackupUtils.recoveryKeyFromBase58(recoveryKey)
// val isValid = backupRecoveryKey
// ?.let { session.cryptoService().keysBackupService().isValidRecoveryKeyForCurrentVersion(it) }
// ?: false
// if (isValid) {
// session.cryptoService().keysBackupService().saveBackupRecoveryKey(backupRecoveryKey, version.version)
// }
// session.cryptoService().keysBackupService().trustKeysBackupVersion(version, true)
// } catch (failure: Throwable) {
// // Just ignore for now
// Timber.e(failure, "## Failed to restore backup after SSSS recovery")
// }
// }
// }
//
// // override fun transactionCreated(tx: VerificationTransaction) {
// // transactionUpdated(tx)
// // }
// //
// // override fun transactionUpdated(tx: VerificationTransaction) = withState { state ->
// // if (state.selfVerificationMode && state.transactionId == null) {
// // // is this an incoming with that user
// // if (tx.isIncoming && tx.otherUserId == state.otherUserId) {
// // // Also auto accept incoming if needed!
// // if (tx is IncomingSasVerificationTransaction) {
// // if (tx.uxState == IncomingSasVerificationTransaction.UxState.SHOW_ACCEPT) {
// // tx.performAccept()
// // }
// // }
// // // Use this one!
// // setState {
// // copy(
// // transactionId = tx.transactionId,
// // sasTransactionState = tx.state.takeIf { tx is SasVerificationTransaction },
// // qrTransactionState = tx.state.takeIf { tx is QrCodeVerificationTransaction }
// // )
// // }
// // }
// // }
// //
// // when (tx) {
// // is SasVerificationTransaction -> {
// // if (tx.transactionId == (state.pendingRequest.invoke()?.transactionId ?: state.transactionId)) {
// // // A SAS tx has been started following this request
// // setState {
// // copy(
// // transactionId = tx.transactionId,
// // sasTransactionState = tx.state.takeIf { tx is SasVerificationTransaction },
// // qrTransactionState = tx.state.takeIf { tx is QrCodeVerificationTransaction }
// // )
// // }
// // }
// // }
// //
// // when (tx) {
// // is SasVerificationTransaction -> {
// // if (tx.transactionId == (state.pendingRequest.invoke()?.transactionId ?: state.transactionId)) {
// // // A SAS tx has been started following this request
// // setState {
// // copy(
// // sasTransactionState = tx.state
// // )
// // }
// // }
// // }
// // is QrCodeVerificationTransaction -> {
// // if (tx.transactionId == (state.pendingRequest.invoke()?.transactionId ?: state.transactionId)) {
// // // A QR tx has been started following this request
// // setState {
// // copy(
// // qrTransactionState = tx.state
// // )
// // }
// // }
// // }
// // }
// // }
// // }
//
// override fun transactionCreated(tx: VerificationTransaction) {
// transactionUpdated(tx)
// }
//
// override fun transactionUpdated(tx: VerificationTransaction) = withState { state ->
// Timber.v("transactionUpdated: $tx")
// if (tx.transactionId != state.transactionId) return@withState
// if (tx is SasVerificationTransaction) {
// // setState {
// // copy(
// // sasTransactionState = tx.state
// // )
// // }
// } else if (tx is QrCodeVerificationTransaction) {
//
// }
// // handleTransactionUpdate(state, tx)
// }
//
// override fun verificationRequestCreated(pr: PendingVerificationRequest) {
// verificationRequestUpdated(pr)
// }
//
// override fun verificationRequestUpdated(pr: PendingVerificationRequest) = withState { state ->
// Timber.v("VerificationRequestUpdated: $pr")
// if (pr.transactionId != state.pendingRequest.invoke()?.transactionId) return@withState
// setState {
// copy(pendingRequest = Success(pr))
// }
// // if (state.selfVerificationMode && state.pendingRequest.invoke() == null && state.transactionId == null) {
// // // is this an incoming with that user
// // if (pr.isIncoming && pr.otherUserId == state.otherUserId) {
// // if (!pr.isReady) {
// // // auto ready in this case, as we are waiting
// // // TODO, can I be here in DM mode? in this case should test if roomID is null?
// // viewModelScope.launch {
// // session.cryptoService().verificationService()
// // .readyPendingVerification(
// // supportedVerificationMethodsProvider.provide(),
// // pr.otherUserId,
// // pr.transactionId
// // )
// // }
// // }
// //
// // // Use this one!
// // setState {
// // copy(
// // transactionId = pr.transactionId,
// // pendingRequest = Success(pr)
// // )
// // }
// // return@withState
// // }
// // }
// //
// // if (state.transactionId == pr.transactionId) {
// // setState {
// // copy(
// // pendingRequest = Success(pr)
// // )
// // }
// // }
// }
// }

View file

@ -1,109 +0,0 @@
// /*
// * Copyright (c) 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.app.features.crypto.verification.cancel
//
// import androidx.core.text.toSpannable
// import com.airbnb.epoxy.EpoxyController
// import im.vector.app.R
// import im.vector.app.core.epoxy.bottomSheetDividerItem
// import im.vector.app.core.resources.ColorProvider
// import im.vector.app.core.resources.StringProvider
// import im.vector.app.core.utils.colorizeMatchingText
// import im.vector.app.features.crypto.verification.VerificationBottomSheetViewState
// import im.vector.app.features.crypto.verification.epoxy.bottomSheetVerificationActionItem
// import im.vector.app.features.crypto.verification.epoxy.bottomSheetVerificationNoticeItem
// import im.vector.app.features.displayname.getBestName
// import im.vector.lib.core.utils.epoxy.charsequence.EpoxyCharSequence
// import im.vector.lib.core.utils.epoxy.charsequence.toEpoxyCharSequence
// import javax.inject.Inject
//
// class VerificationCancelController @Inject constructor(
// private val stringProvider: StringProvider,
// private val colorProvider: ColorProvider
// ) : EpoxyController() {
//
// var listener: Listener? = null
//
// private var viewState: VerificationBottomSheetViewState? = null
//
// fun update(viewState: VerificationBottomSheetViewState) {
// this.viewState = viewState
// requestModelBuild()
// }
//
// override fun buildModels() {
// val state = viewState ?: return
// val host = this
// if (state.isMe) {
// if (state.currentDeviceCanCrossSign) {
// bottomSheetVerificationNoticeItem {
// id("notice")
// notice(host.stringProvider.getString(R.string.verify_cancel_self_verification_from_trusted).toEpoxyCharSequence())
// }
// } else {
// bottomSheetVerificationNoticeItem {
// id("notice")
// notice(host.stringProvider.getString(R.string.verify_cancel_self_verification_from_untrusted).toEpoxyCharSequence())
// }
// }
// } else {
// val otherUserID = state.otherUserId
// val otherDisplayName = state.otherUserMxItem.getBestName()
// bottomSheetVerificationNoticeItem {
// id("notice")
// notice(
// EpoxyCharSequence(
// host.stringProvider.getString(R.string.verify_cancel_other, otherDisplayName, otherUserID)
// .toSpannable()
// .colorizeMatchingText(otherUserID, host.colorProvider.getColorFromAttribute(R.attr.vctr_notice_text_color))
// )
// )
// }
// }
//
// bottomSheetDividerItem {
// id("sep0")
// }
//
// bottomSheetVerificationActionItem {
// id("cancel")
// title(host.stringProvider.getString(R.string.action_skip))
// titleColor(host.colorProvider.getColorFromAttribute(R.attr.colorError))
// iconRes(R.drawable.ic_arrow_right)
// iconColor(host.colorProvider.getColorFromAttribute(R.attr.colorError))
// listener { host.listener?.onTapCancel() }
// }
//
// bottomSheetDividerItem {
// id("sep1")
// }
//
// bottomSheetVerificationActionItem {
// id("continue")
// title(host.stringProvider.getString(R.string._continue))
// titleColor(host.colorProvider.getColorFromAttribute(R.attr.colorPrimary))
// iconRes(R.drawable.ic_arrow_right)
// iconColor(host.colorProvider.getColorFromAttribute(R.attr.colorPrimary))
// listener { host.listener?.onTapContinue() }
// }
// }
//
// interface Listener {
// fun onTapCancel()
// fun onTapContinue()
// }
// }

View file

@ -1,73 +0,0 @@
// /*
// * Copyright (c) 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.app.features.crypto.verification.cancel
//
// import android.os.Bundle
// import android.view.LayoutInflater
// import android.view.View
// import android.view.ViewGroup
// import com.airbnb.mvrx.parentFragmentViewModel
// import com.airbnb.mvrx.withState
// import dagger.hilt.android.AndroidEntryPoint
// import im.vector.app.core.extensions.cleanup
// import im.vector.app.core.extensions.configureWith
// import im.vector.app.core.platform.VectorBaseFragment
// import im.vector.app.databinding.BottomSheetVerificationChildFragmentBinding
// import im.vector.app.features.crypto.verification.VerificationBottomSheetViewModel
// import javax.inject.Inject
//
// @AndroidEntryPoint
// class VerificationCancelFragment :
// VectorBaseFragment<BottomSheetVerificationChildFragmentBinding>(),
// VerificationCancelController.Listener {
//
// @Inject lateinit var controller: VerificationCancelController
//
// private val viewModel by parentFragmentViewModel(VerificationBottomSheetViewModel::class)
//
// override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): BottomSheetVerificationChildFragmentBinding {
// return BottomSheetVerificationChildFragmentBinding.inflate(inflater, container, false)
// }
//
// override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
// super.onViewCreated(view, savedInstanceState)
// setupRecyclerView()
// }
//
// override fun onDestroyView() {
// views.bottomSheetVerificationRecyclerView.cleanup()
// controller.listener = null
// super.onDestroyView()
// }
//
// private fun setupRecyclerView() {
// views.bottomSheetVerificationRecyclerView.configureWith(controller, hasFixedSize = false, disableItemAnimation = true)
// controller.listener = this
// }
//
// override fun invalidate() = withState(viewModel) { state ->
// controller.update(state)
// }
//
// override fun onTapCancel() {
// viewModel.confirmCancel()
// }
//
// override fun onTapContinue() {
// viewModel.continueFromCancel()
// }
// }

View file

@ -1,84 +0,0 @@
// /*
// * Copyright (c) 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.app.features.crypto.verification.cancel
//
// import com.airbnb.epoxy.EpoxyController
// import im.vector.app.R
// import im.vector.app.core.epoxy.bottomSheetDividerItem
// import im.vector.app.core.resources.ColorProvider
// import im.vector.app.core.resources.StringProvider
// import im.vector.app.features.crypto.verification.VerificationBottomSheetViewState
// import im.vector.app.features.crypto.verification.epoxy.bottomSheetVerificationActionItem
// import im.vector.app.features.crypto.verification.epoxy.bottomSheetVerificationNoticeItem
// import im.vector.app.features.html.EventHtmlRenderer
// import im.vector.lib.core.utils.epoxy.charsequence.toEpoxyCharSequence
// import javax.inject.Inject
//
// class VerificationNotMeController @Inject constructor(
// private val stringProvider: StringProvider,
// private val colorProvider: ColorProvider,
// private val eventHtmlRenderer: EventHtmlRenderer
// ) : EpoxyController() {
//
// var listener: Listener? = null
//
// private var viewState: VerificationBottomSheetViewState? = null
//
// fun update(viewState: VerificationBottomSheetViewState) {
// this.viewState = viewState
// requestModelBuild()
// }
//
// override fun buildModels() {
// val host = this
// bottomSheetVerificationNoticeItem {
// id("notice")
// notice(host.eventHtmlRenderer.render(host.stringProvider.getString(R.string.verify_not_me_self_verification)).toEpoxyCharSequence())
// }
//
// bottomSheetDividerItem {
// id("sep0")
// }
//
// bottomSheetVerificationActionItem {
// id("skip")
// title(host.stringProvider.getString(R.string.action_skip))
// titleColor(host.colorProvider.getColorFromAttribute(R.attr.vctr_content_primary))
// iconRes(R.drawable.ic_arrow_right)
// iconColor(host.colorProvider.getColorFromAttribute(R.attr.vctr_content_primary))
// listener { host.listener?.onTapSkip() }
// }
//
// bottomSheetDividerItem {
// id("sep1")
// }
//
// bottomSheetVerificationActionItem {
// id("settings")
// title(host.stringProvider.getString(R.string.settings))
// titleColor(host.colorProvider.getColorFromAttribute(R.attr.colorPrimary))
// iconRes(R.drawable.ic_arrow_right)
// iconColor(host.colorProvider.getColorFromAttribute(R.attr.colorPrimary))
// listener { host.listener?.onTapSettings() }
// }
// }
//
// interface Listener {
// fun onTapSkip()
// fun onTapSettings()
// }
// }

View file

@ -1,73 +0,0 @@
// /*
// * Copyright (c) 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.app.features.crypto.verification.cancel
//
// import android.os.Bundle
// import android.view.LayoutInflater
// import android.view.View
// import android.view.ViewGroup
// import com.airbnb.mvrx.parentFragmentViewModel
// import com.airbnb.mvrx.withState
// import dagger.hilt.android.AndroidEntryPoint
// import im.vector.app.core.extensions.cleanup
// import im.vector.app.core.extensions.configureWith
// import im.vector.app.core.platform.VectorBaseFragment
// import im.vector.app.databinding.BottomSheetVerificationChildFragmentBinding
// import im.vector.app.features.crypto.verification.VerificationBottomSheetViewModel
// import javax.inject.Inject
//
// @AndroidEntryPoint
// class VerificationNotMeFragment :
// VectorBaseFragment<BottomSheetVerificationChildFragmentBinding>(),
// VerificationNotMeController.Listener {
//
// @Inject lateinit var controller: VerificationNotMeController
//
// private val viewModel by parentFragmentViewModel(VerificationBottomSheetViewModel::class)
//
// override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): BottomSheetVerificationChildFragmentBinding {
// return BottomSheetVerificationChildFragmentBinding.inflate(inflater, container, false)
// }
//
// override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
// super.onViewCreated(view, savedInstanceState)
// setupRecyclerView()
// }
//
// override fun onDestroyView() {
// views.bottomSheetVerificationRecyclerView.cleanup()
// controller.listener = null
// super.onDestroyView()
// }
//
// private fun setupRecyclerView() {
// views.bottomSheetVerificationRecyclerView.configureWith(controller, hasFixedSize = false, disableItemAnimation = true)
// controller.listener = this
// }
//
// override fun invalidate() = withState(viewModel) { state ->
// controller.update(state)
// }
//
// override fun onTapSkip() {
// viewModel.continueFromWasNotMe()
// }
//
// override fun onTapSettings() {
// viewModel.goToSettings()
// }
// }

View file

@ -1,147 +0,0 @@
// /*
// * 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.app.features.crypto.verification.choose
//
// import com.airbnb.epoxy.EpoxyController
// import im.vector.app.R
// import im.vector.app.core.epoxy.bottomSheetDividerItem
// import im.vector.app.core.resources.ColorProvider
// import im.vector.app.core.resources.StringProvider
// import im.vector.app.core.ui.list.buttonPositiveDestructiveButtonBarItem
// import im.vector.app.features.crypto.verification.epoxy.bottomSheetVerificationActionItem
// import im.vector.app.features.crypto.verification.epoxy.bottomSheetVerificationNoticeItem
// import im.vector.app.features.crypto.verification.epoxy.bottomSheetVerificationQrCodeItem
// import im.vector.lib.core.utils.epoxy.charsequence.toEpoxyCharSequence
// import javax.inject.Inject
//
// class VerificationChooseMethodController @Inject constructor(
// private val stringProvider: StringProvider,
// private val colorProvider: ColorProvider
// ) : EpoxyController() {
//
// var listener: Listener? = null
//
// private var viewState: VerificationChooseMethodViewState? = null
//
// fun update(viewState: VerificationChooseMethodViewState) {
// this.viewState = viewState
// requestModelBuild()
// }
//
// override fun buildModels() {
// val state = viewState ?: return
// val host = this
//
// if (state.otherCanScanQrCode || state.otherCanShowQrCode) {
// val scanCodeInstructions: String
// val scanOtherCodeTitle: String
// val compareEmojiSubtitle: String
// if (state.isMe) {
// scanCodeInstructions = stringProvider.getString(R.string.verification_scan_self_notice)
// scanOtherCodeTitle = stringProvider.getString(R.string.verification_scan_with_this_device)
// compareEmojiSubtitle = stringProvider.getString(R.string.verification_scan_self_emoji_subtitle)
// } else {
// scanCodeInstructions = stringProvider.getString(R.string.verification_scan_notice)
// scanOtherCodeTitle = stringProvider.getString(R.string.verification_scan_their_code)
// compareEmojiSubtitle = stringProvider.getString(R.string.verification_scan_emoji_subtitle)
// }
//
// bottomSheetVerificationNoticeItem {
// id("notice")
// notice(scanCodeInstructions.toEpoxyCharSequence())
// }
//
// if (state.otherCanScanQrCode && !state.qrCodeText.isNullOrBlank()) {
// bottomSheetVerificationQrCodeItem {
// id("qr")
// data(state.qrCodeText)
// }
//
// bottomSheetDividerItem {
// id("sep0")
// }
// }
//
// if (state.otherCanShowQrCode) {
// bottomSheetVerificationActionItem {
// id("openCamera")
// title(scanOtherCodeTitle)
// titleColor(host.colorProvider.getColorFromAttribute(R.attr.colorPrimary))
// iconRes(R.drawable.ic_camera)
// iconColor(host.colorProvider.getColorFromAttribute(R.attr.colorPrimary))
// listener { host.listener?.openCamera() }
// }
//
// bottomSheetDividerItem {
// id("sep1")
// }
// }
//
// bottomSheetVerificationActionItem {
// id("openEmoji")
// title(host.stringProvider.getString(R.string.verification_scan_emoji_title))
// titleColor(host.colorProvider.getColorFromAttribute(R.attr.vctr_content_primary))
// subTitle(compareEmojiSubtitle)
// iconRes(R.drawable.ic_arrow_right)
// iconColor(host.colorProvider.getColorFromAttribute(R.attr.vctr_content_primary))
// listener { host.listener?.doVerifyBySas() }
// }
// } else if (state.sasModeAvailable) {
// bottomSheetVerificationActionItem {
// id("openEmoji")
// title(host.stringProvider.getString(R.string.verification_no_scan_emoji_title))
// titleColor(host.colorProvider.getColorFromAttribute(R.attr.colorPrimary))
// iconRes(R.drawable.ic_arrow_right)
// iconColor(host.colorProvider.getColorFromAttribute(R.attr.vctr_content_primary))
// listener { host.listener?.doVerifyBySas() }
// }
// } else if (!state.isReadySent) {
// // a bit of a special case, if you tapped on the timeline cell but not on a button
// buttonPositiveDestructiveButtonBarItem {
// id("accept_decline")
// positiveText(host.stringProvider.getString(R.string.action_accept).toEpoxyCharSequence())
// destructiveText(host.stringProvider.getString(R.string.action_decline).toEpoxyCharSequence())
// positiveButtonClickAction { host.listener?.acceptRequest() }
// destructiveButtonClickAction { host.listener?.declineRequest() }
// }
// }
//
// if (state.isMe && state.canCrossSign) {
// bottomSheetDividerItem {
// id("sep_notMe")
// }
//
// bottomSheetVerificationActionItem {
// id("wasnote")
// title(host.stringProvider.getString(R.string.verify_new_session_was_not_me))
// titleColor(host.colorProvider.getColorFromAttribute(R.attr.colorError))
// subTitle(host.stringProvider.getString(R.string.verify_new_session_compromized))
// iconRes(R.drawable.ic_arrow_right)
// iconColor(host.colorProvider.getColorFromAttribute(R.attr.vctr_content_primary))
// listener { host.listener?.onClickOnWasNotMe() }
// }
// }
// }
//
// interface Listener {
// fun openCamera()
// fun doVerifyBySas()
// fun onClickOnWasNotMe()
// fun acceptRequest()
// fun declineRequest()
// }
// }

View file

@ -1,136 +0,0 @@
// /*
// * Copyright 2019 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.app.features.crypto.verification.choose
//
// import android.app.Activity
// import android.os.Bundle
// import android.view.LayoutInflater
// import android.view.View
// import android.view.ViewGroup
// import com.airbnb.mvrx.fragmentViewModel
// import com.airbnb.mvrx.parentFragmentViewModel
// import com.airbnb.mvrx.withState
// import dagger.hilt.android.AndroidEntryPoint
// import im.vector.app.R
// import im.vector.app.core.extensions.cleanup
// import im.vector.app.core.extensions.configureWith
// import im.vector.app.core.extensions.registerStartForActivityResult
// import im.vector.app.core.platform.VectorBaseFragment
// import im.vector.app.core.utils.PERMISSIONS_FOR_TAKING_PHOTO
// import im.vector.app.core.utils.checkPermissions
// import im.vector.app.core.utils.onPermissionDeniedDialog
// import im.vector.app.core.utils.registerForPermissionsResult
// import im.vector.app.databinding.BottomSheetVerificationChildFragmentBinding
// import im.vector.app.features.crypto.verification.VerificationAction
// import im.vector.app.features.crypto.verification.VerificationBottomSheetViewModel
// import im.vector.app.features.qrcode.QrCodeScannerActivity
// import timber.log.Timber
// import javax.inject.Inject
//
// @AndroidEntryPoint
// class VerificationChooseMethodFragment :
// VectorBaseFragment<BottomSheetVerificationChildFragmentBinding>(),
// VerificationChooseMethodController.Listener {
//
// @Inject lateinit var controller: VerificationChooseMethodController
// private val viewModel by fragmentViewModel(VerificationChooseMethodViewModel::class)
//
// private val sharedViewModel by parentFragmentViewModel(VerificationBottomSheetViewModel::class)
//
// override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): BottomSheetVerificationChildFragmentBinding {
// return BottomSheetVerificationChildFragmentBinding.inflate(inflater, container, false)
// }
//
// override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
// super.onViewCreated(view, savedInstanceState)
//
// setupRecyclerView()
// }
//
// override fun onDestroyView() {
// views.bottomSheetVerificationRecyclerView.cleanup()
// controller.listener = null
// super.onDestroyView()
// }
//
// private fun setupRecyclerView() {
// views.bottomSheetVerificationRecyclerView.configureWith(controller, hasFixedSize = false, disableItemAnimation = true)
// controller.listener = this
// }
//
// override fun invalidate() = withState(viewModel) { state ->
// controller.update(state)
// }
//
// override fun doVerifyBySas() = withState(sharedViewModel) { state ->
// sharedViewModel.handle(
// VerificationAction.StartSASVerification
// )
// }
//
// private val openCameraActivityResultLauncher = registerForPermissionsResult { allGranted, deniedPermanently ->
// if (allGranted) {
// doOpenQRCodeScanner()
// } else if (deniedPermanently) {
// activity?.onPermissionDeniedDialog(R.string.denied_permission_camera)
// }
// }
//
// override fun openCamera() {
// if (checkPermissions(PERMISSIONS_FOR_TAKING_PHOTO, requireActivity(), openCameraActivityResultLauncher)) {
// doOpenQRCodeScanner()
// }
// }
//
// override fun onClickOnWasNotMe() {
// sharedViewModel.itWasNotMe()
// }
//
// override fun acceptRequest() {
// sharedViewModel.handle(VerificationAction.ReadyPendingVerification)
// }
//
// override fun declineRequest() {
// sharedViewModel.handle(VerificationAction.CancelPendingVerification)
// }
//
// private fun doOpenQRCodeScanner() {
// QrCodeScannerActivity.startForResult(requireActivity(), scanActivityResultLauncher)
// }
//
// private val scanActivityResultLauncher = registerStartForActivityResult { activityResult ->
// if (activityResult.resultCode == Activity.RESULT_OK) {
// val scannedQrCode = QrCodeScannerActivity.getResultText(activityResult.data)
// val wasQrCode = QrCodeScannerActivity.getResultIsQrCode(activityResult.data)
//
// if (wasQrCode && !scannedQrCode.isNullOrBlank()) {
// onRemoteQrCodeScanned(scannedQrCode)
// } else {
// Timber.w("It was not a QR code, or empty result")
// }
// }
// }
//
// private fun onRemoteQrCodeScanned(remoteQrCode: String) = withState(sharedViewModel) { state ->
// sharedViewModel.handle(
// VerificationAction.RemoteQrCodeScanned(
// state.otherUserId,
// state.pendingRequest.invoke()?.transactionId ?: "",
// remoteQrCode
// )
// )
// }
// }

View file

@ -1,172 +0,0 @@
// /*
// * Copyright 2019 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.app.features.crypto.verification.choose
//
// import com.airbnb.mvrx.MavericksState
// import com.airbnb.mvrx.MavericksViewModelFactory
// import com.airbnb.mvrx.ViewModelContext
// import dagger.assisted.Assisted
// import dagger.assisted.AssistedFactory
// import dagger.assisted.AssistedInject
// import dagger.hilt.EntryPoints
// import im.vector.app.core.di.MavericksAssistedViewModelFactory
// import im.vector.app.core.di.SingletonEntryPoint
// import im.vector.app.core.di.hiltMavericksViewModelFactory
// import im.vector.app.core.platform.EmptyAction
// import im.vector.app.core.platform.EmptyViewEvents
// import im.vector.app.core.platform.VectorViewModel
// import im.vector.app.features.crypto.verification.VerificationBottomSheet
// import kotlinx.coroutines.flow.launchIn
// import kotlinx.coroutines.flow.onEach
// import kotlinx.coroutines.launch
// import org.matrix.android.sdk.api.extensions.orFalse
// import org.matrix.android.sdk.api.session.Session
// import org.matrix.android.sdk.api.session.crypto.verification.EVerificationState
// import org.matrix.android.sdk.api.session.crypto.verification.PendingVerificationRequest
// import org.matrix.android.sdk.api.session.crypto.verification.QrCodeVerificationTransaction
// import org.matrix.android.sdk.api.session.crypto.verification.VerificationEvent
// import org.matrix.android.sdk.api.session.crypto.verification.VerificationService
// import org.matrix.android.sdk.api.session.crypto.verification.VerificationTransaction
//
// data class VerificationChooseMethodViewState(
// val otherUserId: String = "",
// val transactionId: String = "",
// val otherCanShowQrCode: Boolean = false,
// val otherCanScanQrCode: Boolean = false,
// val qrCodeText: String? = null,
// val sasModeAvailable: Boolean = false,
// val isMe: Boolean = false,
// val canCrossSign: Boolean = false,
// val isReadySent: Boolean = false
// ) : MavericksState
//
// class VerificationChooseMethodViewModel @AssistedInject constructor(
// @Assisted initialState: VerificationChooseMethodViewState,
// private val session: Session
// ) : VectorViewModel<VerificationChooseMethodViewState, EmptyAction, EmptyViewEvents>(initialState), VerificationService.Listener {
//
// init {
// // session.cryptoService().verificationService().addListener(this)
//
// session.cryptoService().verificationService()
// .requestEventFlow()
// .onEach {
// when (it) {
// // TODO check transaction id
// is VerificationEvent.RequestAdded -> verificationRequestCreated(it.request)
// is VerificationEvent.RequestUpdated -> verificationRequestUpdated(it.request)
// is VerificationEvent.TransactionAdded -> transactionCreated(it.transaction)
// is VerificationEvent.TransactionUpdated -> transactionUpdated(it.transaction)
// }
// }
// .launchIn(viewModelScope)
//
// viewModelScope.launch {
//
// val verificationService = session.cryptoService().verificationService()
// val pvr = verificationService.getExistingVerificationRequest(initialState.otherUserId, initialState.transactionId)
//
// // Get the QR code now, because transaction is already created, so transactionCreated() will not be called
// val qrCodeVerificationTransaction = verificationService.getExistingTransaction(initialState.otherUserId, initialState.transactionId)
//
// setState {
// VerificationChooseMethodViewState(
// otherUserId = initialState.otherUserId,
// isMe = session.myUserId == pvr?.otherUserId,
// canCrossSign = session.cryptoService().crossSigningService().canCrossSign(),
// transactionId = pvr?.transactionId ?: initialState.transactionId,
// otherCanShowQrCode = pvr?.otherCanShowQrCode.orFalse(),
// otherCanScanQrCode = pvr?.otherCanScanQrCode.orFalse(),
// qrCodeText = pvr?.qrCodeText,
// sasModeAvailable = pvr?.isSasSupported.orFalse(),
// isReadySent = pvr?.state == EVerificationState.Ready
// )
// }
// }
//
//
// }
//
// override fun transactionCreated(tx: VerificationTransaction) {
// transactionUpdated(tx)
// }
//
// override fun transactionUpdated(tx: VerificationTransaction) = withState { state ->
// // if (tx.transactionId == state.transactionId && tx is QrCodeVerificationTransaction) {
// // setState {
// // copy(
// // qrCodeText = tx.qrCodeText
// // )
// // }
// // }
// }
//
// override fun verificationRequestCreated(pr: PendingVerificationRequest) {
// verificationRequestUpdated(pr)
// }
//
// override fun verificationRequestUpdated(pr: PendingVerificationRequest) = withState { state ->
// viewModelScope.launch {
// val pvr = session.cryptoService().verificationService().getExistingVerificationRequest(state.otherUserId, state.transactionId)
//
// setState {
// copy(
// otherCanShowQrCode = pvr?.otherCanShowQrCode.orFalse(),
// otherCanScanQrCode = pvr?.otherCanScanQrCode.orFalse(),
// sasModeAvailable = pvr?.isSasSupported.orFalse(),
// isReadySent = pvr?.state == EVerificationState.Ready,
// qrCodeText = pvr?.qrCodeText
// )
// }
// }
// }
//
// @AssistedFactory
// interface Factory : MavericksAssistedViewModelFactory<VerificationChooseMethodViewModel, VerificationChooseMethodViewState> {
// override fun create(initialState: VerificationChooseMethodViewState): VerificationChooseMethodViewModel
// }
//
// companion object : MavericksViewModelFactory<VerificationChooseMethodViewModel, VerificationChooseMethodViewState> by hiltMavericksViewModelFactory() {
//
// override fun initialState(viewModelContext: ViewModelContext): VerificationChooseMethodViewState {
// val args: VerificationBottomSheet.VerificationArgs = viewModelContext.args()
// val session = EntryPoints.get(viewModelContext.app(), SingletonEntryPoint::class.java).activeSessionHolder().getActiveSession()
// val verificationService = session.cryptoService().verificationService()
// // val pvr = verificationService.getExistingVerificationRequest(args.otherUserId, args.verificationId)
//
// // Get the QR code now, because transaction is already created, so transactionCreated() will not be called
// // val qrCodeVerificationTransaction = verificationService.getExistingTransaction(args.otherUserId, args.verificationId ?: "")
//
// return VerificationChooseMethodViewState(
// otherUserId = args.otherUserId,
// // isMe = session.myUserId == pvr?.otherUserId,
// canCrossSign = session.cryptoService().crossSigningService().canCrossSign(),
// transactionId = args.verificationId ?: "",
// // otherCanShowQrCode = pvr?.otherCanShowQrCode().orFalse(),
// // otherCanScanQrCode = pvr?.otherCanScanQrCode().orFalse(),
// // qrCodeText = (qrCodeVerificationTransaction as? QrCodeVerificationTransaction)?.qrCodeText,
// // sasModeAvailable = pvr?.isSasSupported().orFalse()
// )
// }
// }
//
// override fun onCleared() {
// // session.cryptoService().verificationService().removeListener(this)
// super.onCleared()
// }
//
// override fun handle(action: EmptyAction) {}
// }

View file

@ -1,143 +0,0 @@
// /*
// * 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.app.features.crypto.verification.conclusion
//
// import com.airbnb.epoxy.EpoxyController
// import im.vector.app.R
// import im.vector.app.core.epoxy.bottomSheetDividerItem
// import im.vector.app.core.resources.ColorProvider
// import im.vector.app.core.resources.StringProvider
// import im.vector.app.features.crypto.verification.epoxy.bottomSheetVerificationActionItem
// import im.vector.app.features.crypto.verification.epoxy.bottomSheetVerificationBigImageItem
// import im.vector.app.features.crypto.verification.epoxy.bottomSheetVerificationNoticeItem
// import im.vector.app.features.html.EventHtmlRenderer
// import im.vector.lib.core.utils.epoxy.charsequence.toEpoxyCharSequence
// import org.matrix.android.sdk.api.session.crypto.model.RoomEncryptionTrustLevel
// import javax.inject.Inject
//
// class VerificationConclusionController @Inject constructor(
// private val stringProvider: StringProvider,
// private val colorProvider: ColorProvider,
// private val eventHtmlRenderer: EventHtmlRenderer
// ) : EpoxyController() {
//
// var listener: Listener? = null
//
// private var viewState: VerificationConclusionViewState? = null
//
// fun update(viewState: VerificationConclusionViewState) {
// this.viewState = viewState
// requestModelBuild()
// }
//
// override fun buildModels() {
// val state = viewState ?: return
// val host = this
//
// when (state.conclusionState) {
// ConclusionState.SUCCESS -> {
// bottomSheetVerificationNoticeItem {
// id("notice")
// notice(
// host.stringProvider.getString(
// if (state.isSelfVerification) R.string.verification_conclusion_ok_self_notice
// else R.string.verification_conclusion_ok_notice
// )
// .toEpoxyCharSequence()
// )
// }
//
// bottomSheetVerificationBigImageItem {
// id("image")
// roomEncryptionTrustLevel(RoomEncryptionTrustLevel.Trusted)
// }
//
// bottomDone()
// }
// ConclusionState.WARNING -> {
// bottomSheetVerificationNoticeItem {
// id("notice")
// notice(host.stringProvider.getString(R.string.verification_conclusion_not_secure).toEpoxyCharSequence())
// }
//
// bottomSheetVerificationBigImageItem {
// id("image")
// roomEncryptionTrustLevel(RoomEncryptionTrustLevel.Warning)
// }
//
// bottomSheetVerificationNoticeItem {
// id("warning_notice")
// notice(host.eventHtmlRenderer.render(host.stringProvider.getString(R.string.verification_conclusion_compromised)).toEpoxyCharSequence())
// }
//
// bottomGotIt()
// }
// ConclusionState.INVALID_QR_CODE -> {
// bottomSheetVerificationNoticeItem {
// id("invalid_qr")
// notice(host.stringProvider.getString(R.string.verify_invalid_qr_notice).toEpoxyCharSequence())
// }
//
// bottomGotIt()
// }
// ConclusionState.CANCELLED -> {
// bottomSheetVerificationNoticeItem {
// id("notice_cancelled")
// notice(host.stringProvider.getString(R.string.verify_cancelled_notice).toEpoxyCharSequence())
// }
//
// bottomGotIt()
// }
// }
// }
//
// private fun bottomDone() {
// val host = this
// bottomSheetDividerItem {
// id("sep0")
// }
//
// bottomSheetVerificationActionItem {
// id("done")
// title(host.stringProvider.getString(R.string.done))
// titleColor(host.colorProvider.getColorFromAttribute(R.attr.vctr_content_primary))
// iconRes(R.drawable.ic_arrow_right)
// iconColor(host.colorProvider.getColorFromAttribute(R.attr.vctr_content_primary))
// listener { host.listener?.onButtonTapped(true) }
// }
// }
//
// private fun bottomGotIt() {
// val host = this
// bottomSheetDividerItem {
// id("sep0")
// }
//
// bottomSheetVerificationActionItem {
// id("got_it")
// title(host.stringProvider.getString(R.string.sas_got_it))
// titleColor(host.colorProvider.getColorFromAttribute(R.attr.vctr_content_primary))
// iconRes(R.drawable.ic_arrow_right)
// iconColor(host.colorProvider.getColorFromAttribute(R.attr.vctr_content_primary))
// listener { host.listener?.onButtonTapped(false) }
// }
// }
//
// interface Listener {
// fun onButtonTapped(success: Boolean)
// }
// }

View file

@ -1,82 +0,0 @@
// /*
// * Copyright 2019 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.app.features.crypto.verification.conclusion
//
// import android.os.Bundle
// import android.os.Parcelable
// import android.view.LayoutInflater
// import android.view.View
// import android.view.ViewGroup
// import com.airbnb.mvrx.fragmentViewModel
// import com.airbnb.mvrx.parentFragmentViewModel
// import com.airbnb.mvrx.withState
// import dagger.hilt.android.AndroidEntryPoint
// import im.vector.app.core.extensions.cleanup
// import im.vector.app.core.extensions.configureWith
// import im.vector.app.core.platform.VectorBaseFragment
// import im.vector.app.databinding.BottomSheetVerificationChildFragmentBinding
// import im.vector.app.features.crypto.verification.VerificationAction
// import im.vector.app.features.crypto.verification.VerificationBottomSheetViewModel
// import kotlinx.parcelize.Parcelize
// import javax.inject.Inject
//
// @AndroidEntryPoint
// class VerificationConclusionFragment :
// VectorBaseFragment<BottomSheetVerificationChildFragmentBinding>(),
// VerificationConclusionController.Listener {
//
// @Inject lateinit var controller: VerificationConclusionController
//
// @Parcelize
// data class Args(
// val isSuccessFull: Boolean,
// val cancelReason: String?,
// val isMe: Boolean
// ) : Parcelable
//
// private val sharedViewModel by parentFragmentViewModel(VerificationBottomSheetViewModel::class)
//
// private val viewModel by fragmentViewModel(VerificationConclusionViewModel::class)
//
// override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): BottomSheetVerificationChildFragmentBinding {
// return BottomSheetVerificationChildFragmentBinding.inflate(inflater, container, false)
// }
//
// override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
// super.onViewCreated(view, savedInstanceState)
//
// setupRecyclerView()
// }
//
// override fun onDestroyView() {
// views.bottomSheetVerificationRecyclerView.cleanup()
// controller.listener = null
// super.onDestroyView()
// }
//
// private fun setupRecyclerView() {
// views.bottomSheetVerificationRecyclerView.configureWith(controller, hasFixedSize = false, disableItemAnimation = true)
// controller.listener = this
// }
//
// override fun invalidate() = withState(viewModel) { state ->
// controller.update(state)
// }
//
// override fun onButtonTapped(success: Boolean) {
// sharedViewModel.handle(VerificationAction.GotItConclusion(success))
// }
// }

View file

@ -1,68 +0,0 @@
// /*
// * Copyright 2019 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.app.features.crypto.verification.conclusion
//
// import com.airbnb.mvrx.MavericksState
// import com.airbnb.mvrx.MavericksViewModelFactory
// import com.airbnb.mvrx.ViewModelContext
// import im.vector.app.core.platform.EmptyAction
// import im.vector.app.core.platform.EmptyViewEvents
// import im.vector.app.core.platform.VectorViewModel
// import org.matrix.android.sdk.api.session.crypto.verification.CancelCode
// import org.matrix.android.sdk.api.session.crypto.verification.safeValueOf
//
// data class VerificationConclusionViewState(
// val conclusionState: ConclusionState = ConclusionState.CANCELLED,
// val isSelfVerification: Boolean = false
// ) : MavericksState
//
// enum class ConclusionState {
// SUCCESS,
// WARNING,
// CANCELLED,
// INVALID_QR_CODE
// }
//
// class VerificationConclusionViewModel(initialState: VerificationConclusionViewState) :
// VectorViewModel<VerificationConclusionViewState, EmptyAction, EmptyViewEvents>(initialState) {
//
// companion object : MavericksViewModelFactory<VerificationConclusionViewModel, VerificationConclusionViewState> {
//
// override fun initialState(viewModelContext: ViewModelContext): VerificationConclusionViewState? {
// val args = viewModelContext.args<VerificationConclusionFragment.Args>()
//
// return when (safeValueOf(args.cancelReason)) {
// CancelCode.QrCodeInvalid -> {
// VerificationConclusionViewState(ConclusionState.INVALID_QR_CODE, args.isMe)
// }
// CancelCode.MismatchedUser,
// CancelCode.MismatchedSas,
// CancelCode.MismatchedCommitment,
// CancelCode.MismatchedKeys -> {
// VerificationConclusionViewState(ConclusionState.WARNING, args.isMe)
// }
// else -> {
// VerificationConclusionViewState(
// if (args.isSuccessFull) ConclusionState.SUCCESS else ConclusionState.CANCELLED,
// args.isMe
// )
// }
// }
// }
// }
//
// override fun handle(action: EmptyAction) {}
// }

View file

@ -1,168 +0,0 @@
// /*
// * 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.app.features.crypto.verification.emoji
//
// import com.airbnb.epoxy.EpoxyController
// import com.airbnb.mvrx.Fail
// import com.airbnb.mvrx.Success
// import im.vector.app.R
// import im.vector.app.core.epoxy.bottomSheetDividerItem
// import im.vector.app.core.epoxy.errorWithRetryItem
// import im.vector.app.core.error.ErrorFormatter
// import im.vector.app.core.resources.ColorProvider
// import im.vector.app.core.resources.StringProvider
// import im.vector.app.features.crypto.verification.epoxy.bottomSheetVerificationActionItem
// import im.vector.app.features.crypto.verification.epoxy.bottomSheetVerificationDecimalCodeItem
// import im.vector.app.features.crypto.verification.epoxy.bottomSheetVerificationEmojisItem
// import im.vector.app.features.crypto.verification.epoxy.bottomSheetVerificationNoticeItem
// import im.vector.app.features.crypto.verification.epoxy.bottomSheetVerificationWaitingItem
// import im.vector.app.features.displayname.getBestName
// import im.vector.lib.core.utils.epoxy.charsequence.toEpoxyCharSequence
// import javax.inject.Inject
//
// class VerificationEmojiCodeController @Inject constructor(
// private val stringProvider: StringProvider,
// private val colorProvider: ColorProvider,
// private val errorFormatter: ErrorFormatter
// ) : EpoxyController() {
//
// var listener: Listener? = null
//
// private var viewState: VerificationEmojiCodeViewState? = null
//
// fun update(viewState: VerificationEmojiCodeViewState) {
// this.viewState = viewState
// requestModelBuild()
// }
//
// override fun buildModels() {
// val state = viewState ?: return
//
// if (state.supportsEmoji) {
// buildEmojiItem(state)
// } else {
// buildDecimal(state)
// }
// }
//
// private fun buildEmojiItem(state: VerificationEmojiCodeViewState) {
// val host = this
// when (val emojiDescription = state.emojiDescription) {
// is Success -> {
// bottomSheetVerificationNoticeItem {
// id("notice")
// notice(host.stringProvider.getString(R.string.verification_emoji_notice).toEpoxyCharSequence())
// }
//
// bottomSheetVerificationEmojisItem {
// id("emojis")
// emojiRepresentation0(emojiDescription()[0])
// emojiRepresentation1(emojiDescription()[1])
// emojiRepresentation2(emojiDescription()[2])
// emojiRepresentation3(emojiDescription()[3])
// emojiRepresentation4(emojiDescription()[4])
// emojiRepresentation5(emojiDescription()[5])
// emojiRepresentation6(emojiDescription()[6])
// }
//
// buildActions(state)
// }
// is Fail -> {
// errorWithRetryItem {
// id("error")
// text(host.errorFormatter.toHumanReadable(emojiDescription.error))
// }
// }
// else -> {
// bottomSheetVerificationWaitingItem {
// id("waiting")
// title(host.stringProvider.getString(R.string.please_wait))
// }
// }
// }
// }
//
// private fun buildDecimal(state: VerificationEmojiCodeViewState) {
// val host = this
// when (val decimalDescription = state.decimalDescription) {
// is Success -> {
// bottomSheetVerificationNoticeItem {
// id("notice")
// notice(host.stringProvider.getString(R.string.verification_code_notice).toEpoxyCharSequence())
// }
//
// bottomSheetVerificationDecimalCodeItem {
// id("decimal")
// code(state.decimalDescription.invoke() ?: "")
// }
//
// buildActions(state)
// }
// is Fail -> {
// errorWithRetryItem {
// id("error")
// text(host.errorFormatter.toHumanReadable(decimalDescription.error))
// }
// }
// else -> {
// bottomSheetVerificationWaitingItem {
// id("waiting")
// title(host.stringProvider.getString(R.string.please_wait))
// }
// }
// }
// }
//
// private fun buildActions(state: VerificationEmojiCodeViewState) {
// val host = this
// bottomSheetDividerItem {
// id("sep0")
// }
//
// if (state.isWaitingFromOther) {
// bottomSheetVerificationWaitingItem {
// id("waiting")
// title(host.stringProvider.getString(R.string.verification_request_waiting_for, state.otherUser.getBestName()))
// }
// } else {
// bottomSheetVerificationActionItem {
// id("ko")
// title(host.stringProvider.getString(R.string.verification_sas_do_not_match))
// titleColor(host.colorProvider.getColorFromAttribute(R.attr.colorError))
// iconRes(R.drawable.ic_check_off)
// iconColor(host.colorProvider.getColorFromAttribute(R.attr.colorError))
// listener { host.listener?.onDoNotMatchButtonTapped() }
// }
// bottomSheetDividerItem {
// id("sep1")
// }
// bottomSheetVerificationActionItem {
// id("ok")
// title(host.stringProvider.getString(R.string.verification_sas_match))
// titleColor(host.colorProvider.getColorFromAttribute(R.attr.colorPrimary))
// iconRes(R.drawable.ic_check_on)
// iconColor(host.colorProvider.getColorFromAttribute(R.attr.colorPrimary))
// listener { host.listener?.onMatchButtonTapped() }
// }
// }
// }
//
// interface Listener {
// fun onDoNotMatchButtonTapped()
// fun onMatchButtonTapped()
// }
// }

View file

@ -1,81 +0,0 @@
// /*
// * Copyright 2019 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.app.features.crypto.verification.emoji
//
// import android.os.Bundle
// import android.view.LayoutInflater
// import android.view.View
// import android.view.ViewGroup
// import com.airbnb.mvrx.fragmentViewModel
// import com.airbnb.mvrx.parentFragmentViewModel
// import com.airbnb.mvrx.withState
// import dagger.hilt.android.AndroidEntryPoint
// import im.vector.app.core.extensions.cleanup
// import im.vector.app.core.extensions.configureWith
// import im.vector.app.core.platform.VectorBaseFragment
// import im.vector.app.databinding.BottomSheetVerificationChildFragmentBinding
// import im.vector.app.features.crypto.verification.VerificationAction
// import im.vector.app.features.crypto.verification.VerificationBottomSheetViewModel
// import javax.inject.Inject
//
// @AndroidEntryPoint
// class VerificationEmojiCodeFragment :
// VectorBaseFragment<BottomSheetVerificationChildFragmentBinding>(),
// VerificationEmojiCodeController.Listener {
//
// @Inject lateinit var controller: VerificationEmojiCodeController
//
// private val viewModel by fragmentViewModel(VerificationEmojiCodeViewModel::class)
//
// private val sharedViewModel by parentFragmentViewModel(VerificationBottomSheetViewModel::class)
//
// override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): BottomSheetVerificationChildFragmentBinding {
// return BottomSheetVerificationChildFragmentBinding.inflate(inflater, container, false)
// }
//
// override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
// super.onViewCreated(view, savedInstanceState)
//
// setupRecyclerView()
// }
//
// override fun onDestroyView() {
// views.bottomSheetVerificationRecyclerView.cleanup()
// controller.listener = null
// super.onDestroyView()
// }
//
// private fun setupRecyclerView() {
// views.bottomSheetVerificationRecyclerView.configureWith(controller, hasFixedSize = false, disableItemAnimation = true)
// controller.listener = this
// }
//
// override fun invalidate() = withState(viewModel) { state ->
// controller.update(state)
// }
//
// override fun onMatchButtonTapped() = withState(viewModel) { state ->
// val otherUserId = state.otherUser.id
// val txId = state.transactionId ?: return@withState
// sharedViewModel.handle(VerificationAction.SASMatchAction)
// }
//
// override fun onDoNotMatchButtonTapped() = withState(viewModel) { state ->
// val otherUserId = state.otherUser.id
// val txId = state.transactionId ?: return@withState
// sharedViewModel.handle(VerificationAction.SASDoNotMatchAction)
// }
// }

View file

@ -1,209 +0,0 @@
// /*
// * Copyright 2019 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.app.features.crypto.verification.emoji
//
// import com.airbnb.mvrx.Async
// import com.airbnb.mvrx.Fail
// import com.airbnb.mvrx.Loading
// import com.airbnb.mvrx.MavericksState
// import com.airbnb.mvrx.MavericksViewModelFactory
// import com.airbnb.mvrx.Success
// import com.airbnb.mvrx.Uninitialized
// import com.airbnb.mvrx.ViewModelContext
// import dagger.assisted.Assisted
// import dagger.assisted.AssistedFactory
// import dagger.assisted.AssistedInject
// import dagger.hilt.EntryPoints
// import im.vector.app.core.di.MavericksAssistedViewModelFactory
// import im.vector.app.core.di.SingletonEntryPoint
// import im.vector.app.core.di.hiltMavericksViewModelFactory
// import im.vector.app.core.platform.EmptyAction
// import im.vector.app.core.platform.EmptyViewEvents
// import im.vector.app.core.platform.VectorViewModel
// import im.vector.app.features.crypto.verification.VerificationBottomSheet
// import kotlinx.coroutines.flow.launchIn
// import kotlinx.coroutines.flow.onEach
// import kotlinx.coroutines.launch
// import org.matrix.android.sdk.api.session.Session
// import org.matrix.android.sdk.api.session.crypto.verification.EmojiRepresentation
// import org.matrix.android.sdk.api.session.crypto.verification.SasVerificationTransaction
// import org.matrix.android.sdk.api.session.crypto.verification.VerificationEvent
// import org.matrix.android.sdk.api.session.crypto.verification.VerificationService
// import org.matrix.android.sdk.api.session.crypto.verification.VerificationTransaction
// import org.matrix.android.sdk.api.session.crypto.verification.VerificationTxState
// import org.matrix.android.sdk.api.session.getUserOrDefault
// import org.matrix.android.sdk.api.util.MatrixItem
// import org.matrix.android.sdk.api.util.toMatrixItem
//
// data class VerificationEmojiCodeViewState(
// val transactionId: String?,
// val otherUser: MatrixItem,
// val supportsEmoji: Boolean = true,
// val emojiDescription: Async<List<EmojiRepresentation>> = Uninitialized,
// val decimalDescription: Async<String> = Uninitialized,
// val isWaitingFromOther: Boolean = false
// ) : MavericksState
//
// class VerificationEmojiCodeViewModel @AssistedInject constructor(
// @Assisted initialState: VerificationEmojiCodeViewState,
// private val session: Session
// ) : VectorViewModel<VerificationEmojiCodeViewState, EmptyAction, EmptyViewEvents>(initialState), VerificationService.Listener {
//
// init {
//
// session.cryptoService().verificationService()
// .requestEventFlow()
// .onEach {
// when (it) {
// is VerificationEvent.RequestAdded -> verificationRequestCreated(it.request)
// is VerificationEvent.RequestUpdated -> verificationRequestUpdated(it.request)
// is VerificationEvent.TransactionAdded -> transactionCreated(it.transaction)
// is VerificationEvent.TransactionUpdated -> transactionUpdated(it.transaction)
// }
// }
// .launchIn(viewModelScope)
//
// viewModelScope.launch {
// refreshStateFromTx(
// session.cryptoService().verificationService()
// .getExistingTransaction(
// otherUserId = initialState.otherUser.id,
// tid = initialState.transactionId ?: ""
// ) as? SasVerificationTransaction
// )
//
// }
//
// // session.cryptoService().verificationService().addListener(this)
// }
//
// // override fun onCleared() {
// // session.cryptoService().verificationService().removeListener(this)
// // super.onCleared()
// // }
//
// private fun refreshStateFromTx(sasTx: SasVerificationTransaction?) {
// when (val state = sasTx?.state) {
// is VerificationTxState.None,
// is VerificationTxState.SasStarted,
// is VerificationTxState.SasAccepted,
// is VerificationTxState.SasKeySent -> {
// setState {
// copy(
// isWaitingFromOther = false,
// supportsEmoji = sasTx.supportsEmoji(),
// emojiDescription = Loading<List<EmojiRepresentation>>()
// .takeIf { sasTx.supportsEmoji() }
// ?: Uninitialized,
// decimalDescription = Loading<String>()
// .takeIf { sasTx.supportsEmoji().not() }
// ?: Uninitialized
// )
// }
// }
// is VerificationTxState.SasShortCodeReady -> {
// setState {
// copy(
// isWaitingFromOther = false,
// supportsEmoji = sasTx.supportsEmoji(),
// emojiDescription = if (sasTx.supportsEmoji()) Success(sasTx.getEmojiCodeRepresentation())
// else Uninitialized,
// decimalDescription = if (!sasTx.supportsEmoji()) Success(sasTx.getDecimalCodeRepresentation().orEmpty())
// else Uninitialized
// )
// }
// }
// is VerificationTxState.SasMacReceived -> {
// if (state.codeConfirmed) {
// setState {
// copy(isWaitingFromOther = true)
// }
// } else {
// setState {
// copy(
// isWaitingFromOther = false,
// supportsEmoji = sasTx.supportsEmoji(),
// emojiDescription = if (sasTx.supportsEmoji()) Success(sasTx.getEmojiCodeRepresentation())
// else Uninitialized,
// decimalDescription = if (!sasTx.supportsEmoji()) Success(sasTx.getDecimalCodeRepresentation().orEmpty())
// else Uninitialized
// )
// }
// }
// }
// is VerificationTxState.SasMacSent,
// is VerificationTxState.Verified -> {
// setState {
// copy(isWaitingFromOther = true)
// }
// }
// is VerificationTxState.Cancelled -> {
// // The fragment should not be rendered in this state,
// // it should have been replaced by a conclusion fragment
// setState {
// copy(
// isWaitingFromOther = false,
// supportsEmoji = sasTx.supportsEmoji(),
// emojiDescription = Fail(Throwable("Transaction Cancelled")),
// decimalDescription = Fail(Throwable("Transaction Cancelled"))
// )
// }
// }
// null -> {
// setState {
// copy(
// isWaitingFromOther = false,
// emojiDescription = Fail(Throwable("Unknown Transaction")),
// decimalDescription = Fail(Throwable("Unknown Transaction"))
// )
// }
// }
// else -> Unit
// }
// }
//
// override fun transactionCreated(tx: VerificationTransaction) {
// transactionUpdated(tx)
// }
//
// override fun transactionUpdated(tx: VerificationTransaction) = withState { state ->
// if (tx.transactionId == state.transactionId && tx is SasVerificationTransaction) {
// refreshStateFromTx(tx)
// }
// }
//
// @AssistedFactory
// interface Factory : MavericksAssistedViewModelFactory<VerificationEmojiCodeViewModel, VerificationEmojiCodeViewState> {
// override fun create(initialState: VerificationEmojiCodeViewState): VerificationEmojiCodeViewModel
// }
//
// companion object : MavericksViewModelFactory<VerificationEmojiCodeViewModel, VerificationEmojiCodeViewState> by hiltMavericksViewModelFactory() {
//
// override fun initialState(viewModelContext: ViewModelContext): VerificationEmojiCodeViewState {
// val args = viewModelContext.args<VerificationBottomSheet.VerificationArgs>()
// val session = EntryPoints.get(viewModelContext.app(), SingletonEntryPoint::class.java).activeSessionHolder().getActiveSession()
// val matrixItem = session.getUserOrDefault(args.otherUserId).toMatrixItem()
//
// return VerificationEmojiCodeViewState(
// transactionId = args.verificationId,
// otherUser = matrixItem
// )
// }
// }
//
// override fun handle(action: EmptyAction) {
// }
// }

View file

@ -1,63 +0,0 @@
/*
* Copyright (c) 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.app.features.crypto.verification.qrconfirmation
import com.airbnb.epoxy.EpoxyController
import im.vector.app.R
import im.vector.app.core.resources.ColorProvider
import im.vector.app.core.resources.StringProvider
import im.vector.app.features.crypto.verification.epoxy.bottomSheetVerificationBigImageItem
import im.vector.app.features.crypto.verification.epoxy.bottomSheetVerificationNoticeItem
import im.vector.app.features.crypto.verification.epoxy.bottomSheetVerificationWaitingItem
import im.vector.lib.core.utils.epoxy.charsequence.toEpoxyCharSequence
import org.matrix.android.sdk.api.session.crypto.model.RoomEncryptionTrustLevel
import javax.inject.Inject
class VerificationQRWaitingController @Inject constructor(
private val stringProvider: StringProvider,
private val colorProvider: ColorProvider
) : EpoxyController() {
private var args: VerificationQRWaitingFragment.Args? = null
fun update(args: VerificationQRWaitingFragment.Args) {
this.args = args
requestModelBuild()
}
override fun buildModels() {
val params = args ?: return
val host = this
bottomSheetVerificationNoticeItem {
id("notice")
apply {
notice(host.stringProvider.getString(R.string.qr_code_scanned_verif_waiting_notice).toEpoxyCharSequence())
}
}
bottomSheetVerificationBigImageItem {
id("image")
roomEncryptionTrustLevel(RoomEncryptionTrustLevel.Trusted)
}
bottomSheetVerificationWaitingItem {
id("waiting")
title(host.stringProvider.getString(R.string.qr_code_scanned_verif_waiting, params.otherUserName))
}
}
}

View file

@ -1,66 +0,0 @@
/*
* Copyright (c) 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.app.features.crypto.verification.qrconfirmation
import android.os.Bundle
import android.os.Parcelable
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.airbnb.mvrx.Mavericks
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.core.extensions.cleanup
import im.vector.app.core.extensions.configureWith
import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.databinding.BottomSheetVerificationChildFragmentBinding
import im.vector.lib.core.utils.compat.getParcelableCompat
import kotlinx.parcelize.Parcelize
import javax.inject.Inject
@AndroidEntryPoint
class VerificationQRWaitingFragment :
VectorBaseFragment<BottomSheetVerificationChildFragmentBinding>() {
@Inject lateinit var controller: VerificationQRWaitingController
@Parcelize
data class Args(
val isMe: Boolean,
val otherUserName: String
) : Parcelable
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): BottomSheetVerificationChildFragmentBinding {
return BottomSheetVerificationChildFragmentBinding.inflate(inflater, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setupRecyclerView()
(arguments?.getParcelableCompat<Args>(Mavericks.KEY_ARG))?.let {
controller.update(it)
}
}
override fun onDestroyView() {
views.bottomSheetVerificationRecyclerView.cleanup()
super.onDestroyView()
}
private fun setupRecyclerView() {
views.bottomSheetVerificationRecyclerView.configureWith(controller, hasFixedSize = false, disableItemAnimation = true)
}
}

View file

@ -1,99 +0,0 @@
// /*
// * 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.app.features.crypto.verification.qrconfirmation
//
// import com.airbnb.epoxy.EpoxyController
// import im.vector.app.R
// import im.vector.app.core.epoxy.bottomSheetDividerItem
// import im.vector.app.core.resources.ColorProvider
// import im.vector.app.core.resources.StringProvider
// import im.vector.app.features.crypto.verification.VerificationBottomSheetViewState
// import im.vector.app.features.crypto.verification.epoxy.bottomSheetVerificationActionItem
// import im.vector.app.features.crypto.verification.epoxy.bottomSheetVerificationBigImageItem
// import im.vector.app.features.crypto.verification.epoxy.bottomSheetVerificationNoticeItem
// import im.vector.app.features.displayname.getBestName
// import im.vector.lib.core.utils.epoxy.charsequence.toEpoxyCharSequence
// import org.matrix.android.sdk.api.session.crypto.model.RoomEncryptionTrustLevel
// import javax.inject.Inject
//
// class VerificationQrScannedByOtherController @Inject constructor(
// private val stringProvider: StringProvider,
// private val colorProvider: ColorProvider
// ) : EpoxyController() {
//
// var listener: Listener? = null
//
// private var viewState: VerificationBottomSheetViewState? = null
//
// fun update(viewState: VerificationBottomSheetViewState) {
// this.viewState = viewState
// requestModelBuild()
// }
//
// override fun buildModels() {
// val state = viewState ?: return
// val host = this
//
// bottomSheetVerificationNoticeItem {
// id("notice")
// apply {
// if (state.isMe) {
// notice(host.stringProvider.getString(R.string.qr_code_scanned_self_verif_notice).toEpoxyCharSequence())
// } else {
// val name = state.otherUserMxItem.getBestName()
// notice(host.stringProvider.getString(R.string.qr_code_scanned_by_other_notice, name).toEpoxyCharSequence())
// }
// }
// }
//
// bottomSheetVerificationBigImageItem {
// id("image")
// roomEncryptionTrustLevel(RoomEncryptionTrustLevel.Trusted)
// }
//
// bottomSheetDividerItem {
// id("sep0")
// }
//
// bottomSheetVerificationActionItem {
// id("deny")
// title(host.stringProvider.getString(R.string.qr_code_scanned_by_other_no))
// titleColor(host.colorProvider.getColorFromAttribute(R.attr.colorError))
// iconRes(R.drawable.ic_check_off)
// iconColor(host.colorProvider.getColorFromAttribute(R.attr.colorError))
// listener { host.listener?.onUserDeniesQrCodeScanned() }
// }
//
// bottomSheetDividerItem {
// id("sep1")
// }
//
// bottomSheetVerificationActionItem {
// id("confirm")
// title(host.stringProvider.getString(R.string.qr_code_scanned_by_other_yes))
// titleColor(host.colorProvider.getColorFromAttribute(R.attr.colorPrimary))
// iconRes(R.drawable.ic_check_on)
// iconColor(host.colorProvider.getColorFromAttribute(R.attr.colorPrimary))
// listener { host.listener?.onUserConfirmsQrCodeScanned() }
// }
// }
//
// interface Listener {
// fun onUserConfirmsQrCodeScanned()
// fun onUserDeniesQrCodeScanned()
// }
// }

View file

@ -1,73 +0,0 @@
// /*
// * Copyright 2019 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.app.features.crypto.verification.qrconfirmation
//
// import android.os.Bundle
// import android.view.LayoutInflater
// import android.view.View
// import android.view.ViewGroup
// import com.airbnb.mvrx.parentFragmentViewModel
// import com.airbnb.mvrx.withState
// import dagger.hilt.android.AndroidEntryPoint
// import im.vector.app.core.extensions.cleanup
// import im.vector.app.core.extensions.configureWith
// import im.vector.app.core.platform.VectorBaseFragment
// import im.vector.app.databinding.BottomSheetVerificationChildFragmentBinding
// import im.vector.app.features.crypto.verification.VerificationAction
// import im.vector.app.features.crypto.verification.VerificationBottomSheetViewModel
// import javax.inject.Inject
//
// @AndroidEntryPoint
// class VerificationQrScannedByOtherFragment :
// VectorBaseFragment<BottomSheetVerificationChildFragmentBinding>(),
// VerificationQrScannedByOtherController.Listener {
//
// @Inject lateinit var controller: VerificationQrScannedByOtherController
//
// private val sharedViewModel by parentFragmentViewModel(VerificationBottomSheetViewModel::class)
//
// override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): BottomSheetVerificationChildFragmentBinding {
// return BottomSheetVerificationChildFragmentBinding.inflate(inflater, container, false)
// }
//
// override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
// super.onViewCreated(view, savedInstanceState)
// setupRecyclerView()
// }
//
// override fun invalidate() = withState(sharedViewModel) { state ->
// controller.update(state)
// }
//
// override fun onDestroyView() {
// views.bottomSheetVerificationRecyclerView.cleanup()
// controller.listener = null
// super.onDestroyView()
// }
//
// private fun setupRecyclerView() {
// views.bottomSheetVerificationRecyclerView.configureWith(controller, hasFixedSize = false, disableItemAnimation = true)
// controller.listener = this
// }
//
// override fun onUserConfirmsQrCodeScanned() {
// sharedViewModel.handle(VerificationAction.OtherUserScannedSuccessfully)
// }
//
// override fun onUserDeniesQrCodeScanned() {
// sharedViewModel.handle(VerificationAction.OtherUserDidNotScanned)
// }
// }

View file

@ -1,185 +0,0 @@
// /*
// * Copyright 2019 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.app.features.crypto.verification.request
//
// import androidx.core.text.toSpannable
// import com.airbnb.epoxy.EpoxyController
// import com.airbnb.mvrx.Fail
// import com.airbnb.mvrx.Loading
// import com.airbnb.mvrx.Success
// import com.airbnb.mvrx.Uninitialized
// import im.vector.app.R
// import im.vector.app.core.epoxy.bottomSheetDividerItem
// import im.vector.app.core.resources.ColorProvider
// import im.vector.app.core.resources.StringProvider
// import im.vector.app.core.utils.colorizeMatchingText
// import im.vector.app.features.crypto.verification.VerificationBottomSheetViewState
// import im.vector.app.features.crypto.verification.epoxy.bottomSheetSelfWaitItem
// import im.vector.app.features.crypto.verification.epoxy.bottomSheetVerificationActionItem
// import im.vector.app.features.crypto.verification.epoxy.bottomSheetVerificationNoticeItem
// import im.vector.app.features.crypto.verification.epoxy.bottomSheetVerificationWaitingItem
// import im.vector.app.features.displayname.getBestName
// import im.vector.lib.core.utils.epoxy.charsequence.toEpoxyCharSequence
// import org.matrix.android.sdk.api.session.crypto.verification.EVerificationState
// import javax.inject.Inject
//
// class VerificationRequestController @Inject constructor(
// private val stringProvider: StringProvider,
// private val colorProvider: ColorProvider
// ) : EpoxyController() {
//
// var listener: Listener? = null
//
// private var viewState: VerificationBottomSheetViewState? = null
//
// fun update(viewState: VerificationBottomSheetViewState) {
// this.viewState = viewState
// requestModelBuild()
// }
//
// override fun buildModels() {
// val state = viewState ?: return
// val host = this
//
// if (state.selfVerificationMode) {
// if (state.hasAnyOtherSession) {
// bottomSheetVerificationNoticeItem {
// id("notice")
// notice(host.stringProvider.getString(R.string.verification_open_other_to_verify).toEpoxyCharSequence())
// }
//
// bottomSheetSelfWaitItem {
// id("waiting")
// }
//
// bottomSheetDividerItem {
// id("sep")
// }
// }
//
// if (state.quadSContainsSecrets) {
// val subtitle = if (state.hasAnyOtherSession) {
// stringProvider.getString(R.string.verification_use_passphrase)
// } else {
// null
// }
// bottomSheetVerificationActionItem {
// id("passphrase")
// title(host.stringProvider.getString(R.string.verification_cannot_access_other_session))
// titleColor(host.colorProvider.getColorFromAttribute(R.attr.vctr_content_primary))
// subTitle(subtitle)
// iconRes(R.drawable.ic_arrow_right)
// iconColor(host.colorProvider.getColorFromAttribute(R.attr.vctr_content_primary))
// listener { host.listener?.onClickRecoverFromPassphrase() }
// }
// }
//
// if (!state.isVerificationRequired) {
// bottomSheetDividerItem {
// id("sep1")
// }
//
// bottomSheetVerificationActionItem {
// id("skip")
// title(host.stringProvider.getString(R.string.action_skip))
// titleColor(host.colorProvider.getColorFromAttribute(R.attr.colorError))
// iconRes(R.drawable.ic_arrow_right)
// iconColor(host.colorProvider.getColorFromAttribute(R.attr.colorError))
// listener { host.listener?.onClickSkip() }
// }
// }
// } else {
// val styledText =
// if (state.isMe) {
// stringProvider.getString(R.string.verify_new_session_notice)
// } else {
// stringProvider.getString(R.string.verification_request_notice, state.otherUserId)
// .toSpannable()
// .colorizeMatchingText(state.otherUserId, colorProvider.getColorFromAttribute(R.attr.vctr_notice_text_color))
// }
//
// bottomSheetVerificationNoticeItem {
// id("notice")
// notice(styledText.toEpoxyCharSequence())
// }
//
// bottomSheetDividerItem {
// id("sep")
// }
//
// when (val pr = state.pendingRequest) {
// is Uninitialized -> {
// bottomSheetVerificationActionItem {
// id("start")
// title(host.stringProvider.getString(R.string.start_verification))
// titleColor(host.colorProvider.getColorFromAttribute(R.attr.colorPrimary))
// subTitle(host.stringProvider.getString(R.string.verification_request_start_notice))
// iconRes(R.drawable.ic_arrow_right)
// iconColor(host.colorProvider.getColorFromAttribute(R.attr.vctr_content_primary))
// listener { host.listener?.onClickOnVerificationStart() }
// }
// }
// is Loading -> {
// bottomSheetVerificationWaitingItem {
// id("waiting")
// title(host.stringProvider.getString(R.string.verification_request_waiting_for, state.otherUserMxItem.getBestName()))
// }
// }
// is Success -> {
// if (pr.invoke().state != EVerificationState.Ready) {
// if (state.isMe) {
// bottomSheetVerificationWaitingItem {
// id("waiting")
// title(host.stringProvider.getString(R.string.verification_request_waiting))
// }
// } else {
// bottomSheetVerificationWaitingItem {
// id("waiting")
// title(host.stringProvider.getString(R.string.verification_request_waiting_for, state.otherUserMxItem.getBestName()))
// }
// }
// }
// }
// is Fail -> Unit
// }
// }
//
// if (state.isMe && state.currentDeviceCanCrossSign && !state.selfVerificationMode) {
// bottomSheetDividerItem {
// id("sep_notMe")
// }
//
// bottomSheetVerificationActionItem {
// id("wasnote")
// title(host.stringProvider.getString(R.string.verify_new_session_was_not_me))
// titleColor(host.colorProvider.getColorFromAttribute(R.attr.colorError))
// subTitle(host.stringProvider.getString(R.string.verify_new_session_compromized))
// iconRes(R.drawable.ic_arrow_right)
// iconColor(host.colorProvider.getColorFromAttribute(R.attr.vctr_content_primary))
// listener { host.listener?.onClickOnWasNotMe() }
// }
// }
// }
//
// interface Listener {
// fun onClickOnVerificationStart()
// fun onClickOnWasNotMe()
// fun onClickRecoverFromPassphrase()
// fun onClickDismiss()
// fun onClickSkip()
// }
// }

View file

@ -1,85 +0,0 @@
// /*
// * Copyright 2019 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.app.features.crypto.verification.request
//
// import android.os.Bundle
// import android.view.LayoutInflater
// import android.view.View
// import android.view.ViewGroup
// import com.airbnb.mvrx.parentFragmentViewModel
// import com.airbnb.mvrx.withState
// import dagger.hilt.android.AndroidEntryPoint
// import im.vector.app.core.extensions.cleanup
// import im.vector.app.core.extensions.configureWith
// import im.vector.app.core.platform.VectorBaseFragment
// import im.vector.app.databinding.BottomSheetVerificationChildFragmentBinding
// import im.vector.app.features.crypto.verification.VerificationAction
// import im.vector.app.features.crypto.verification.VerificationBottomSheetViewModel
// import javax.inject.Inject
//
// @AndroidEntryPoint
// class VerificationRequestFragment :
// VectorBaseFragment<BottomSheetVerificationChildFragmentBinding>(),
// VerificationRequestController.Listener {
//
// @Inject lateinit var controller: VerificationRequestController
//
// private val viewModel by parentFragmentViewModel(VerificationBottomSheetViewModel::class)
//
// override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): BottomSheetVerificationChildFragmentBinding {
// return BottomSheetVerificationChildFragmentBinding.inflate(inflater, container, false)
// }
//
// override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
// super.onViewCreated(view, savedInstanceState)
// setupRecyclerView()
// }
//
// override fun onDestroyView() {
// views.bottomSheetVerificationRecyclerView.cleanup()
// controller.listener = null
// super.onDestroyView()
// }
//
// private fun setupRecyclerView() {
// views.bottomSheetVerificationRecyclerView.configureWith(controller, hasFixedSize = false, disableItemAnimation = true)
// controller.listener = this
// }
//
// override fun invalidate() = withState(viewModel) { state ->
// controller.update(state)
// }
//
// override fun onClickOnVerificationStart(): Unit = withState(viewModel) { state ->
// viewModel.handle(VerificationAction.RequestVerificationByDM)
// }
//
// override fun onClickRecoverFromPassphrase() {
// viewModel.handle(VerificationAction.VerifyFromPassphrase)
// }
//
// override fun onClickDismiss() {
// viewModel.handle(VerificationAction.SkipVerification)
// }
//
// override fun onClickSkip() {
// viewModel.queryCancel()
// }
//
// override fun onClickOnWasNotMe() {
// viewModel.itWasNotMe()
// }
// }

View file

@ -158,6 +158,9 @@ class SelfVerificationBottomSheet : VectorBaseBottomSheetDialogFragment<BottomSh
is VerificationBottomSheetViewEvents.RequestNotFound -> {
dismiss()
}
is VerificationBottomSheetViewEvents.ConfirmCancel -> {
// TODO? applies to self?
}
}
}
}

View file

@ -1,178 +0,0 @@
// /*
// * Copyright (c) 2022 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.app.features.crypto.verification.transaction
//
// import com.airbnb.epoxy.EpoxyController
// import com.airbnb.mvrx.Async
// import com.airbnb.mvrx.Fail
// import com.airbnb.mvrx.Loading
// import com.airbnb.mvrx.Success
// import com.airbnb.mvrx.Uninitialized
// import im.vector.app.R
// import im.vector.app.core.epoxy.bottomSheetDividerItem
// import im.vector.app.core.resources.ColorProvider
// import im.vector.app.core.resources.StringProvider
// import im.vector.app.features.crypto.verification.epoxy.bottomSheetVerificationActionItem
// import im.vector.app.features.crypto.verification.epoxy.bottomSheetVerificationBigImageItem
// import im.vector.app.features.crypto.verification.epoxy.bottomSheetVerificationEmojisItem
// import im.vector.app.features.crypto.verification.epoxy.bottomSheetVerificationNoticeItem
// import im.vector.app.features.crypto.verification.epoxy.bottomSheetVerificationWaitingItem
// import im.vector.app.features.html.EventHtmlRenderer
// import im.vector.lib.core.utils.epoxy.charsequence.toEpoxyCharSequence
// import org.matrix.android.sdk.api.session.crypto.model.RoomEncryptionTrustLevel
// import org.matrix.android.sdk.api.session.crypto.verification.CancelCode
// import org.matrix.android.sdk.api.session.crypto.verification.EmojiRepresentation
// import org.matrix.android.sdk.api.session.crypto.verification.SasVerificationTransaction
// import org.matrix.android.sdk.api.session.crypto.verification.VerificationTransaction
// import org.matrix.android.sdk.api.session.crypto.verification.VerificationTxState
// import javax.inject.Inject
//
// class VerificationTransactionController @Inject constructor(
// private val stringProvider: StringProvider,
// private val colorProvider: ColorProvider,
// private val eventHtmlRenderer: EventHtmlRenderer,
// ) : EpoxyController() {
//
// var aTransaction: Async<VerificationTransaction>? = null
//
// fun update(asyncTransaction: Async<VerificationTransaction>) {
// this.aTransaction = asyncTransaction
// requestModelBuild()
// }
//
// override fun buildModels() {
// val host = this
// when (aTransaction) {
// null,
// Uninitialized -> {
// // empty
// }
// is Fail -> {
// }
// is Loading -> {
// bottomSheetVerificationWaitingItem {
// id("waiting")
// title(host.stringProvider.getString(R.string.please_wait))
// }
// }
// is Success -> {
// val tx = aTransaction?.invoke() ?: return
// if (tx is SasVerificationTransaction) {
// when (val txState = tx.state) {
// VerificationTxState.SasShortCodeReady -> {
// buildEmojiItem(tx.getEmojiCodeRepresentation())
// }
// is VerificationTxState.Cancelled -> {
// renderCancel(txState.cancelCode)
// }
// is VerificationTxState.Done -> {
//
// }
// else -> {
// // waiting
// bottomSheetVerificationWaitingItem {
// id("waiting")
// title(host.stringProvider.getString(R.string.please_wait))
// }
// }
// }
// }
// }
// }
// }
//
// private fun renderCancel(cancelCode: CancelCode) {
// val host = this
// when (cancelCode) {
// CancelCode.QrCodeInvalid -> {
// // TODO
// }
// CancelCode.MismatchedUser,
// CancelCode.MismatchedSas,
// CancelCode.MismatchedCommitment,
// CancelCode.MismatchedKeys -> {
// bottomSheetVerificationNoticeItem {
// id("notice")
// notice(host.stringProvider.getString(R.string.verification_conclusion_not_secure).toEpoxyCharSequence())
// }
//
// bottomSheetVerificationBigImageItem {
// id("image")
// roomEncryptionTrustLevel(RoomEncryptionTrustLevel.Warning)
// }
//
// bottomSheetVerificationNoticeItem {
// id("warning_notice")
// notice(host.eventHtmlRenderer.render(host.stringProvider.getString(R.string.verification_conclusion_compromised)).toEpoxyCharSequence())
// }
// }
// else -> {
// bottomSheetVerificationNoticeItem {
// id("notice_cancelled")
// notice(host.stringProvider.getString(R.string.verify_cancelled_notice).toEpoxyCharSequence())
// }
// }
// }
// }
//
// private fun buildEmojiItem(emoji: List<EmojiRepresentation>) {
// val host = this
// bottomSheetVerificationNoticeItem {
// id("notice")
// notice(host.stringProvider.getString(R.string.verification_emoji_notice).toEpoxyCharSequence())
// }
//
// bottomSheetVerificationEmojisItem {
// id("emojis")
// emojiRepresentation0(emoji[0])
// emojiRepresentation1(emoji[1])
// emojiRepresentation2(emoji[2])
// emojiRepresentation3(emoji[3])
// emojiRepresentation4(emoji[4])
// emojiRepresentation5(emoji[5])
// emojiRepresentation6(emoji[6])
// }
//
// buildSasCodeActions()
// }
//
// private fun buildSasCodeActions() {
// val host = this
// bottomSheetDividerItem {
// id("sep0")
// }
// bottomSheetVerificationActionItem {
// id("ko")
// title(host.stringProvider.getString(R.string.verification_sas_do_not_match))
// titleColor(host.colorProvider.getColorFromAttribute(R.attr.colorError))
// iconRes(R.drawable.ic_check_off)
// iconColor(host.colorProvider.getColorFromAttribute(R.attr.colorError))
// // listener { host.listener?.onDoNotMatchButtonTapped() }
// }
// bottomSheetDividerItem {
// id("sep1")
// }
// bottomSheetVerificationActionItem {
// id("ok")
// title(host.stringProvider.getString(R.string.verification_sas_match))
// titleColor(host.colorProvider.getColorFromAttribute(R.attr.colorPrimary))
// iconRes(R.drawable.ic_check_on)
// iconColor(host.colorProvider.getColorFromAttribute(R.attr.colorPrimary))
// // listener { host.listener?.onMatchButtonTapped() }
// }
// }
// }

View file

@ -1,36 +0,0 @@
// /*
// * Copyright (c) 2022 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.app.features.crypto.verification.transaction
//
// import android.view.LayoutInflater
// import android.view.ViewGroup
// import com.airbnb.mvrx.parentFragmentViewModel
// import dagger.hilt.android.AndroidEntryPoint
// import im.vector.app.core.platform.VectorBaseFragment
// import im.vector.app.databinding.BottomSheetVerificationChildFragmentBinding
// import im.vector.app.features.crypto.verification.user.UserVerificationViewModel
//
// @AndroidEntryPoint
// class VerificationTransactionFragment : VectorBaseFragment<BottomSheetVerificationChildFragmentBinding>() {
//
// private val viewModel by parentFragmentViewModel(UserVerificationViewModel::class)
//
// override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): BottomSheetVerificationChildFragmentBinding {
// return BottomSheetVerificationChildFragmentBinding.inflate(inflater, container, false)
// }
//
// }

View file

@ -16,11 +16,14 @@
package im.vector.app.features.crypto.verification.user
import android.app.Dialog
import android.os.Bundle
import android.os.Parcelable
import android.view.KeyEvent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.text.toSpannable
import androidx.fragment.app.Fragment
import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState
@ -30,10 +33,13 @@ import im.vector.app.R
import im.vector.app.core.extensions.commitTransaction
import im.vector.app.core.extensions.toMvRxBundle
import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment
import im.vector.app.core.utils.colorizeMatchingText
import im.vector.app.databinding.BottomSheetVerificationBinding
import im.vector.app.features.crypto.verification.VerificationAction
import im.vector.app.features.crypto.verification.VerificationBottomSheetViewEvents
import im.vector.app.features.displayname.getBestName
import im.vector.app.features.home.AvatarRenderer
import im.vector.app.features.themes.ThemeUtils
import kotlinx.parcelize.Parcelize
import org.matrix.android.sdk.api.session.crypto.model.RoomEncryptionTrustLevel
import javax.inject.Inject
@ -59,6 +65,11 @@ class UserVerificationBottomSheet : VectorBaseBottomSheetDialogFragment<BottomSh
private val viewModel by fragmentViewModel(UserVerificationViewModel::class)
init {
// we manage dismiss/back manually to confirm cancel on verification
isCancelable = false
}
override fun getBinding(
inflater: LayoutInflater,
container: ViewGroup?
@ -97,6 +108,34 @@ class UserVerificationBottomSheet : VectorBaseBottomSheetDialogFragment<BottomSh
is VerificationBottomSheetViewEvents.RequestNotFound -> {
// no-op for user verification
}
is VerificationBottomSheetViewEvents.ConfirmCancel -> {
MaterialAlertDialogBuilder(requireContext())
.setTitle(getString(R.string.dialog_title_confirmation))
.setMessage(
getString(R.string.verify_cancel_other, event.otherUserId, event.deviceId ?: "*")
.toSpannable()
.colorizeMatchingText(event.otherUserId, ThemeUtils.getColor(requireContext(), R.attr.vctr_notice_text_color))
)
.setCancelable(false)
.setPositiveButton(R.string._resume, null)
.setNegativeButton(R.string.action_cancel) { _, _ ->
viewModel.handle(VerificationAction.CancelPendingVerification)
}
.show()
}
}
}
}
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
return super.onCreateDialog(savedInstanceState).apply {
setOnKeyListener { _, keyCode, keyEvent ->
if (keyCode == KeyEvent.KEYCODE_BACK && keyEvent.action == KeyEvent.ACTION_UP) {
viewModel.queryCancel()
true
} else {
false
}
}
}
}

View file

@ -73,7 +73,6 @@ class UserVerificationController @Inject constructor(
var state: UserVerificationViewState? = null
fun update(state: UserVerificationViewState) {
// Timber.w("VALR controller updated $state")
this.state = state
requestModelBuild()
}
@ -145,6 +144,9 @@ class UserVerificationController @Inject constructor(
}
EVerificationState.Cancelled -> {
renderCancel(pendingRequest.cancelConclusion ?: CancelCode.User)
gotIt {
listener?.onDone(false)
}
}
EVerificationState.HandledByOtherSession -> {
// we should dismiss

View file

@ -42,6 +42,7 @@ import org.matrix.android.sdk.api.Matrix
import org.matrix.android.sdk.api.extensions.orFalse
import org.matrix.android.sdk.api.extensions.tryOrNull
import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.crypto.verification.EVerificationState
import org.matrix.android.sdk.api.session.crypto.verification.EmojiRepresentation
import org.matrix.android.sdk.api.session.crypto.verification.PendingVerificationRequest
import org.matrix.android.sdk.api.session.crypto.verification.QRCodeVerificationState
@ -243,6 +244,29 @@ class UserVerificationViewModel @AssistedInject constructor(
}
}
fun queryCancel() = withState { state ->
// check if there is an existing request
val request = state.pendingRequest.invoke()
when (request?.state) {
EVerificationState.WaitingForReady,
EVerificationState.Requested,
EVerificationState.Ready,
EVerificationState.Started,
EVerificationState.WeStarted,
EVerificationState.WaitingForDone -> {
// query confirmation
_viewEvents.post(VerificationBottomSheetViewEvents.ConfirmCancel(request.otherUserId, request.otherDeviceId))
}
// EVerificationState.Done,
// EVerificationState.Cancelled,
// EVerificationState.HandledByOtherSession,
else -> {
// we can just dismiss?
_viewEvents.post(VerificationBottomSheetViewEvents.Dismiss)
}
}
}
override fun handle(action: VerificationAction) {
when (action) {
VerificationAction.CancelPendingVerification -> {