Fix bunch of issues around login/logout and introduces messages feature
This commit is contained in:
parent
bb88919bb3
commit
823cef8b7c
19 changed files with 314 additions and 89 deletions
|
|
@ -1,10 +1,6 @@
|
|||
package io.element.android.x.features.login
|
||||
|
||||
import android.util.Log
|
||||
import com.airbnb.mvrx.Fail
|
||||
import com.airbnb.mvrx.Loading
|
||||
import com.airbnb.mvrx.MavericksViewModel
|
||||
import com.airbnb.mvrx.Success
|
||||
import io.element.android.x.matrix.MatrixInstance
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
|
|
@ -24,13 +20,11 @@ class LoginViewModel(initialState: LoginViewState) :
|
|||
|
||||
private fun handleSubmit() = withState { state ->
|
||||
viewModelScope.launch {
|
||||
setState { copy(isLoggedIn = Loading()) }
|
||||
try {
|
||||
suspend {
|
||||
matrix.login(state.homeserver, state.login, state.password)
|
||||
setState { copy(isLoggedIn = Success(Unit)) }
|
||||
} catch (throwable: Throwable) {
|
||||
Log.e("Error", "Cannot login", throwable)
|
||||
setState { copy(isLoggedIn = Fail(throwable)) }
|
||||
Unit
|
||||
}.execute {
|
||||
copy(isLoggedIn = it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue