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_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_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_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>

View file

@ -16,11 +16,9 @@
package im.vector.app.features.login.qr
import org.matrix.android.sdk.internal.rendezvous.RendezvousFailureReason
sealed class QrCodeLoginConnectionStatus {
object ConnectingToDevice : QrCodeLoginConnectionStatus()
data class Connected(val securityCode: String, val canConfirmSecurityCode: Boolean) : 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.databinding.FragmentQrCodeLoginStatusBinding
import im.vector.app.features.themes.ThemeUtils
import org.matrix.android.sdk.internal.rendezvous.RendezvousFailureReason
@AndroidEntryPoint
class QrCodeLoginStatusFragment : VectorBaseFragment<FragmentQrCodeLoginStatusBinding>() {
@ -78,12 +77,11 @@ class QrCodeLoginStatusFragment : VectorBaseFragment<FragmentQrCodeLoginStatusBi
)
}
private fun getErrorCode(reason: RendezvousFailureReason): String {
return when (reason) {
RendezvousFailureReason.UnsupportedAlgorithm, RendezvousFailureReason.UnsupportedTransport -> 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)
RendezvousFailureReason.UserDeclined -> getString(R.string.qr_code_login_header_failed_denied_description)
else -> getString(R.string.qr_code_login_header_failed_other_description)
private fun getErrorCode(errorType: QrCodeLoginErrorType): String {
return when (errorType) {
QrCodeLoginErrorType.DEVICE_IS_NOT_SUPPORTED -> getString(R.string.qr_code_login_header_failed_device_is_not_supported_description)
QrCodeLoginErrorType.TIMEOUT -> getString(R.string.qr_code_login_header_failed_timeout_description)
QrCodeLoginErrorType.REQUEST_WAS_DENIED -> getString(R.string.qr_code_login_header_failed_denied_description)
}
}

View file

@ -23,19 +23,13 @@ import dagger.assisted.AssistedInject
import im.vector.app.core.di.MavericksAssistedViewModelFactory
import im.vector.app.core.di.hiltMavericksViewModelFactory
import im.vector.app.core.platform.VectorViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
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(
@Assisted private val initialState: QrCodeLoginViewState
@Assisted private val initialState: QrCodeLoginViewState,
) : VectorViewModel<QrCodeLoginViewState, QrCodeLoginAction, QrCodeLoginViewEvents>(initialState) {
val TAG: String = QrCodeLoginViewModel::class.java.simpleName
@AssistedFactory
interface Factory : MavericksAssistedViewModelFactory<QrCodeLoginViewModel, QrCodeLoginViewState> {
override fun create(initialState: QrCodeLoginViewState): QrCodeLoginViewModel
@ -65,64 +59,32 @@ class QrCodeLoginViewModel @AssistedInject constructor(
}
private fun handleOnQrCodeScanned(action: QrCodeLoginAction.OnQrCodeScanned) {
Timber.tag(TAG).d("Scanned code: ${action.qrCode}")
val rendezvous = Rendezvous.buildChannelFromCode(action.qrCode) { reason ->
Timber.tag(TAG).d("Rendezvous cancelled: $reason")
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)
if (isValidQrCode(action.qrCode)) {
setState {
copy(
connectionStatus = QrCodeLoginConnectionStatus.ConnectingToDevice
)
}
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!
// viewModelScope.launch {
// delay(3000)
// onFailed(QrCodeLoginErrorType.TIMEOUT, true)
// delay(3000)
// onConnectionEstablished("1234-ABCD-5678-EFGH")
// delay(3000)
// onSigningIn()
// delay(3000)
// 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()
// }
// TODO. UI test purpose. Fixme remove!
viewModelScope.launch {
delay(3000)
onFailed(QrCodeLoginErrorType.TIMEOUT, true)
delay(3000)
onConnectionEstablished("1234-ABCD-5678-EFGH")
delay(3000)
onSigningIn()
delay(3000)
onFailed(QrCodeLoginErrorType.DEVICE_IS_NOT_SUPPORTED, false)
}
}
private fun onFailed(reason: RendezvousFailureReason) {
private fun onFailed(errorType: QrCodeLoginErrorType, canTryAgain: Boolean) {
setState {
copy(
connectionStatus = QrCodeLoginConnectionStatus.Failed(reason, reason.canRetry)
connectionStatus = QrCodeLoginConnectionStatus.Failed(errorType, canTryAgain)
)
}
}