diff --git a/library/ui-strings/src/main/res/values/strings.xml b/library/ui-strings/src/main/res/values/strings.xml
index 108fe7db7c..822e9d3865 100644
--- a/library/ui-strings/src/main/res/values/strings.xml
+++ b/library/ui-strings/src/main/res/values/strings.xml
@@ -3368,7 +3368,6 @@
Linking with this device is not supported.
The linking wasn’t completed in the required time.
The request was denied on the other device.
- The request failed.
Open ${app_name} on your other device
Go to Settings -> Security & Privacy -> Show All Sessions
Select \'Show QR code\'
diff --git a/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginConnectionStatus.kt b/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginConnectionStatus.kt
index 4de191f863..330562b874 100644
--- a/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginConnectionStatus.kt
+++ b/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginConnectionStatus.kt
@@ -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()
}
diff --git a/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginErrorType.kt b/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginErrorType.kt
new file mode 100644
index 0000000000..9a6cc13de0
--- /dev/null
+++ b/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginErrorType.kt
@@ -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,
+}
diff --git a/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginStatusFragment.kt b/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginStatusFragment.kt
index fb372cbb2f..1c0841aa11 100644
--- a/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginStatusFragment.kt
+++ b/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginStatusFragment.kt
@@ -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() {
@@ -78,12 +77,11 @@ class QrCodeLoginStatusFragment : VectorBaseFragment 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)
}
}
diff --git a/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginViewModel.kt b/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginViewModel.kt
index d0c34b83af..da3348653c 100644
--- a/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginViewModel.kt
+++ b/vector/src/main/java/im/vector/app/features/login/qr/QrCodeLoginViewModel.kt
@@ -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(initialState) {
- val TAG: String = QrCodeLoginViewModel::class.java.simpleName
-
@AssistedFactory
interface Factory : MavericksAssistedViewModelFactory {
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)
)
}
}