Revert "Partial implementation of QR login logic"

This reverts commit 4b14ee4695.
This commit is contained in:
Hugh Nimmo-Smith 2022-10-13 21:48:25 +01:00
parent 90fa5d5345
commit e305478dda
5 changed files with 50 additions and 70 deletions

View File

@ -3368,7 +3368,6 @@
<string name="qr_code_login_header_failed_device_is_not_supported_description">Linking with this device is not supported.</string> <string name="qr_code_login_header_failed_device_is_not_supported_description">Linking with this device is not supported.</string>
<string name="qr_code_login_header_failed_timeout_description">The linking wasnt completed in the required time.</string> <string name="qr_code_login_header_failed_timeout_description">The linking wasnt completed in the required time.</string>
<string name="qr_code_login_header_failed_denied_description">The request was denied on the other device.</string> <string name="qr_code_login_header_failed_denied_description">The request was denied on the other device.</string>
<string name="qr_code_login_header_failed_other_description">The request failed.</string>
<string name="qr_code_login_new_device_instruction_1">Open ${app_name} on your other device</string> <string name="qr_code_login_new_device_instruction_1">Open ${app_name} on your other device</string>
<string name="qr_code_login_new_device_instruction_2">Go to Settings -> Security &amp; Privacy -> Show All Sessions</string> <string name="qr_code_login_new_device_instruction_2">Go to Settings -> Security &amp; Privacy -> Show All Sessions</string>
<string name="qr_code_login_new_device_instruction_3">Select \'Show QR code\'</string> <string name="qr_code_login_new_device_instruction_3">Select \'Show QR code\'</string>

View File

@ -16,11 +16,9 @@
package im.vector.app.features.login.qr package im.vector.app.features.login.qr
import org.matrix.android.sdk.internal.rendezvous.RendezvousFailureReason
sealed class QrCodeLoginConnectionStatus { sealed class QrCodeLoginConnectionStatus {
object ConnectingToDevice : QrCodeLoginConnectionStatus() object ConnectingToDevice : QrCodeLoginConnectionStatus()
data class Connected(val securityCode: String, val canConfirmSecurityCode: Boolean) : QrCodeLoginConnectionStatus() data class Connected(val securityCode: String, val canConfirmSecurityCode: Boolean) : QrCodeLoginConnectionStatus()
object SigningIn : QrCodeLoginConnectionStatus() object SigningIn : QrCodeLoginConnectionStatus()
data class Failed(val errorType: RendezvousFailureReason, val canTryAgain: Boolean) : QrCodeLoginConnectionStatus() data class Failed(val errorType: QrCodeLoginErrorType, val canTryAgain: Boolean) : QrCodeLoginConnectionStatus()
} }

View File

@ -0,0 +1,23 @@
/*
* 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.login.qr
enum class QrCodeLoginErrorType {
DEVICE_IS_NOT_SUPPORTED,
TIMEOUT,
REQUEST_WAS_DENIED,
}

View File

@ -27,7 +27,6 @@ import im.vector.app.R
import im.vector.app.core.platform.VectorBaseFragment import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.databinding.FragmentQrCodeLoginStatusBinding import im.vector.app.databinding.FragmentQrCodeLoginStatusBinding
import im.vector.app.features.themes.ThemeUtils import im.vector.app.features.themes.ThemeUtils
import org.matrix.android.sdk.internal.rendezvous.RendezvousFailureReason
@AndroidEntryPoint @AndroidEntryPoint
class QrCodeLoginStatusFragment : VectorBaseFragment<FragmentQrCodeLoginStatusBinding>() { class QrCodeLoginStatusFragment : VectorBaseFragment<FragmentQrCodeLoginStatusBinding>() {
@ -78,12 +77,11 @@ class QrCodeLoginStatusFragment : VectorBaseFragment<FragmentQrCodeLoginStatusBi
) )
} }
private fun getErrorCode(reason: RendezvousFailureReason): String { private fun getErrorCode(errorType: QrCodeLoginErrorType): String {
return when (reason) { return when (errorType) {
RendezvousFailureReason.UnsupportedAlgorithm, RendezvousFailureReason.UnsupportedTransport -> getString(R.string.qr_code_login_header_failed_device_is_not_supported_description) QrCodeLoginErrorType.DEVICE_IS_NOT_SUPPORTED -> getString(R.string.qr_code_login_header_failed_device_is_not_supported_description)
RendezvousFailureReason.Expired -> getString(R.string.qr_code_login_header_failed_timeout_description) QrCodeLoginErrorType.TIMEOUT -> getString(R.string.qr_code_login_header_failed_timeout_description)
RendezvousFailureReason.UserDeclined -> getString(R.string.qr_code_login_header_failed_denied_description) QrCodeLoginErrorType.REQUEST_WAS_DENIED -> getString(R.string.qr_code_login_header_failed_denied_description)
else -> getString(R.string.qr_code_login_header_failed_other_description)
} }
} }

View File

@ -23,19 +23,13 @@ import dagger.assisted.AssistedInject
import im.vector.app.core.di.MavericksAssistedViewModelFactory import im.vector.app.core.di.MavericksAssistedViewModelFactory
import im.vector.app.core.di.hiltMavericksViewModelFactory import im.vector.app.core.di.hiltMavericksViewModelFactory
import im.vector.app.core.platform.VectorViewModel import im.vector.app.core.platform.VectorViewModel
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.internal.rendezvous.Rendezvous
import org.matrix.android.sdk.internal.rendezvous.RendezvousFailureReason
import timber.log.Timber
class QrCodeLoginViewModel @AssistedInject constructor( class QrCodeLoginViewModel @AssistedInject constructor(
@Assisted private val initialState: QrCodeLoginViewState @Assisted private val initialState: QrCodeLoginViewState,
) : VectorViewModel<QrCodeLoginViewState, QrCodeLoginAction, QrCodeLoginViewEvents>(initialState) { ) : VectorViewModel<QrCodeLoginViewState, QrCodeLoginAction, QrCodeLoginViewEvents>(initialState) {
val TAG: String = QrCodeLoginViewModel::class.java.simpleName
@AssistedFactory @AssistedFactory
interface Factory : MavericksAssistedViewModelFactory<QrCodeLoginViewModel, QrCodeLoginViewState> { interface Factory : MavericksAssistedViewModelFactory<QrCodeLoginViewModel, QrCodeLoginViewState> {
override fun create(initialState: QrCodeLoginViewState): QrCodeLoginViewModel override fun create(initialState: QrCodeLoginViewState): QrCodeLoginViewModel
@ -65,64 +59,32 @@ class QrCodeLoginViewModel @AssistedInject constructor(
} }
private fun handleOnQrCodeScanned(action: QrCodeLoginAction.OnQrCodeScanned) { private fun handleOnQrCodeScanned(action: QrCodeLoginAction.OnQrCodeScanned) {
Timber.tag(TAG).d("Scanned code: ${action.qrCode}") if (isValidQrCode(action.qrCode)) {
setState {
val rendezvous = Rendezvous.buildChannelFromCode(action.qrCode) { reason -> copy(
Timber.tag(TAG).d("Rendezvous cancelled: $reason") connectionStatus = QrCodeLoginConnectionStatus.ConnectingToDevice
onFailed(reason) )
}
setState {
copy(
connectionStatus = QrCodeLoginConnectionStatus.ConnectingToDevice
)
}
_viewEvents.post(QrCodeLoginViewEvents.NavigateToStatusScreen)
viewModelScope.launch(Dispatchers.IO) {
val confirmationCode = rendezvous.startAfterScanningCode()
Timber.tag(TAG).i("Established secure channel with checksum: $confirmationCode")
confirmationCode ?.let {
onConnectionEstablished(it)
} }
rendezvous.completeOnNewDevice() _viewEvents.post(QrCodeLoginViewEvents.NavigateToStatusScreen)
} }
// if (isValidQrCode(action.qrCode)) {
// setState {
// copy(
// connectionStatus = QrCodeLoginConnectionStatus.ConnectingToDevice
// )
// }
// _viewEvents.post(QrCodeLoginViewEvents.NavigateToStatusScreen)
// }
//
// // TODO. UI test purpose. Fixme remove! // TODO. UI test purpose. Fixme remove!
// viewModelScope.launch { viewModelScope.launch {
// delay(3000) delay(3000)
// onFailed(QrCodeLoginErrorType.TIMEOUT, true) onFailed(QrCodeLoginErrorType.TIMEOUT, true)
// delay(3000) delay(3000)
// onConnectionEstablished("1234-ABCD-5678-EFGH") onConnectionEstablished("1234-ABCD-5678-EFGH")
// delay(3000) delay(3000)
// onSigningIn() onSigningIn()
// delay(3000) delay(3000)
// onFailed(QrCodeLoginErrorType.DEVICE_IS_NOT_SUPPORTED, false) onFailed(QrCodeLoginErrorType.DEVICE_IS_NOT_SUPPORTED, false)
// } }
// // TODO. UI test purpose. Fixme remove!
// viewModelScope.launch {
// delay(3000)
// onConnectionEstablished("1234-ABCD-5678-EFGH")
// delay(3000)
// onSigningIn()
// }
} }
private fun onFailed(errorType: QrCodeLoginErrorType, canTryAgain: Boolean) {
private fun onFailed(reason: RendezvousFailureReason) {
setState { setState {
copy( copy(
connectionStatus = QrCodeLoginConnectionStatus.Failed(reason, reason.canRetry) connectionStatus = QrCodeLoginConnectionStatus.Failed(errorType, canTryAgain)
) )
} }
} }