Fix / annoying loading to get active sessions

Start with what's known locally
This commit is contained in:
Valere 2020-02-04 18:50:28 +01:00
parent 320dc4accd
commit 4506b7d6e6
2 changed files with 20 additions and 2 deletions

View file

@ -426,6 +426,15 @@ class VectorSettingsSecurityPrivacyFragment @Inject constructor(
// ============================================================================================================== // ==============================================================================================================
private fun refreshMyDevice() { private fun refreshMyDevice() {
session.getUserDevices(session.myUserId).map {
DeviceInfo(
user_id = session.myUserId,
deviceId = it.deviceId,
displayName = it.displayName()
)
}.let {
refreshCryptographyPreference(it)
}
// TODO Move to a ViewModel... // TODO Move to a ViewModel...
session.getDevicesList(object : MatrixCallback<DevicesListResponse> { session.getDevicesList(object : MatrixCallback<DevicesListResponse> {
override fun onSuccess(data: DevicesListResponse) { override fun onSuccess(data: DevicesListResponse) {

View file

@ -115,11 +115,20 @@ class DevicesViewModel @AssistedInject constructor(@Assisted initialState: Devic
* It can be any mobile devices, and any browsers. * It can be any mobile devices, and any browsers.
*/ */
private fun refreshDevicesList() { private fun refreshDevicesList() {
if (session.isCryptoEnabled() && !session.sessionParams.credentials.deviceId.isNullOrEmpty()) { if (!session.sessionParams.credentials.deviceId.isNullOrEmpty()) {
// display something asap
val localKnown = session.getUserDevices(session.myUserId).map {
DeviceInfo(
user_id = session.myUserId,
deviceId = it.deviceId,
displayName = it.displayName()
)
}
setState { setState {
copy( copy(
// Keep known list if we have it, and let refresh go in backgroung // Keep known list if we have it, and let refresh go in backgroung
devices = this.devices.takeIf { it is Success } ?: Loading() devices = this.devices.takeIf { it is Success } ?: Success(localKnown)
) )
} }