Skip to content
Snippets Groups Projects
Commit 6692f34b authored by Adrien Béraud's avatar Adrien Béraud Committed by Adrien Béraud
Browse files

linkdevice: handle addDevice errors

Change-Id: I4b3e39cec92ab1ea2592ecfea1402646fe014096
parent 7883f09f
No related branches found
No related tags found
No related merge requests found
...@@ -55,6 +55,7 @@ class ExportSideViewModel @Inject constructor( ...@@ -55,6 +55,7 @@ class ExportSideViewModel @Inject constructor(
private val _uiState = MutableStateFlow<AddDeviceExportState>(AddDeviceExportState.Init()) private val _uiState = MutableStateFlow<AddDeviceExportState>(AddDeviceExportState.Init())
val uiState: StateFlow<AddDeviceExportState> = _uiState.asStateFlow() val uiState: StateFlow<AddDeviceExportState> = _uiState.asStateFlow()
private val accountId = accountService.currentAccount!!.accountId
private var operationId: Long? = null private var operationId: Long? = null
private var compositeDisposable = CompositeDisposable() private var compositeDisposable = CompositeDisposable()
...@@ -66,35 +67,39 @@ class ExportSideViewModel @Inject constructor( ...@@ -66,35 +67,39 @@ class ExportSideViewModel @Inject constructor(
|| (jamiAuthentication.length != 59) || (jamiAuthentication.length != 59)
) { ) {
Log.w(TAG, "Invalid input: $jamiAuthentication") Log.w(TAG, "Invalid input: $jamiAuthentication")
_uiState.value = // If state is unchanged, error is not emitted again.
AddDeviceExportState.Init() // If state is unchanged, error is not emitted again. _uiState.value = AddDeviceExportState.Init()
_uiState.value = AddDeviceExportState.Init(ExportSideInputError.INVALID_INPUT) _uiState.value = AddDeviceExportState.Init(ExportSideInputError.INVALID_INPUT)
return return
} }
operationId = accountService val operationId = accountService.addDevice(accountId, jamiAuthentication)
.addDevice(accountService.currentAccount!!.accountId, jamiAuthentication) if (operationId < 0) {
Log.e(TAG, "Failed to add device: $jamiAuthentication $operationId")
_uiState.value = when (operationId) {
-1L -> AddDeviceExportState.Init(ExportSideInputError.INVALID_INPUT)
else -> AddDeviceExportState.Done(AuthError.UNKNOWN)
}
return
}
this.operationId = operationId
assert(compositeDisposable.size() == 0) // Should not have any subscription. assert(compositeDisposable.size() == 0) // Should not have any subscription.
accountService.authResultObservable accountService.authResultObservable
.filter { .filter { it.accountId == accountId && it.operationId == operationId }
it.accountId == accountService.currentAccount?.accountId
&& it.operationId == operationId
}
.observeOn(mUiScheduler) .observeOn(mUiScheduler)
.subscribe { it: AuthResult -> .subscribe(this::updateAuthState)
updateAuthState(it) .apply { compositeDisposable.add(this) }
}.apply { compositeDisposable.add(this) }
} }
fun onIdentityConfirmation() { fun onIdentityConfirmation() {
accountService.confirmAddDevice(accountService.currentAccount!!.accountId, operationId!!) accountService.confirmAddDevice(accountId, operationId!!)
} }
fun onCancel() { fun onCancel() {
val operationId = operationId ?: return val operationId = operationId ?: return
accountService.cancelAddDevice(accountService.currentAccount!!.accountId, operationId) accountService.cancelAddDevice(accountId, operationId)
} }
// There is no token to be received in export side. // There is no token to be received in export side.
...@@ -103,7 +108,6 @@ class ExportSideViewModel @Inject constructor( ...@@ -103,7 +108,6 @@ class ExportSideViewModel @Inject constructor(
} }
override fun onConnectingSignal() { override fun onConnectingSignal() {
// Nothing to do here.
_uiState.value = AddDeviceExportState.Connecting _uiState.value = AddDeviceExportState.Connecting
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment