Capability: do not update data if the corresponding request fails
This commit is contained in:
parent
88e8c11ee5
commit
d14f1dd1ab
|
@ -19,7 +19,6 @@ package im.vector.matrix.android.internal.session.homeserver
|
|||
import com.zhuinden.monarchy.Monarchy
|
||||
import im.vector.matrix.android.api.auth.data.Versions
|
||||
import im.vector.matrix.android.api.auth.data.isLoginAndRegistrationSupportedBySdk
|
||||
import im.vector.matrix.android.api.extensions.orFalse
|
||||
import im.vector.matrix.android.api.session.homeserver.HomeServerCapabilities
|
||||
import im.vector.matrix.android.internal.database.model.HomeServerCapabilitiesEntity
|
||||
import im.vector.matrix.android.internal.database.query.getOrCreate
|
||||
|
@ -50,9 +49,11 @@ internal class DefaultGetHomeServerCapabilitiesTask @Inject constructor(
|
|||
return
|
||||
}
|
||||
|
||||
val uploadCapabilities = executeRequest<GetUploadCapabilitiesResult>(eventBus) {
|
||||
val uploadCapabilities = runCatching {
|
||||
executeRequest<GetUploadCapabilitiesResult>(eventBus) {
|
||||
apiCall = capabilitiesAPI.getUploadCapabilities()
|
||||
}
|
||||
}.getOrNull()
|
||||
|
||||
val capabilities = runCatching {
|
||||
executeRequest<GetCapabilitiesResult>(eventBus) {
|
||||
|
@ -66,22 +67,27 @@ internal class DefaultGetHomeServerCapabilitiesTask @Inject constructor(
|
|||
}
|
||||
}.getOrNull()
|
||||
|
||||
|
||||
insertInDb(capabilities, uploadCapabilities, versions)
|
||||
}
|
||||
|
||||
private suspend fun insertInDb(getCapabilitiesResult: GetCapabilitiesResult?,
|
||||
getUploadCapabilitiesResult: GetUploadCapabilitiesResult,
|
||||
getUploadCapabilitiesResult: GetUploadCapabilitiesResult?,
|
||||
getVersionResult: Versions?) {
|
||||
monarchy.awaitTransaction { realm ->
|
||||
val homeServerCapabilitiesEntity = HomeServerCapabilitiesEntity.getOrCreate(realm)
|
||||
|
||||
if (getCapabilitiesResult != null) {
|
||||
homeServerCapabilitiesEntity.canChangePassword = getCapabilitiesResult.canChangePassword()
|
||||
}
|
||||
|
||||
if (getUploadCapabilitiesResult != null) {
|
||||
homeServerCapabilitiesEntity.maxUploadFileSize = getUploadCapabilitiesResult.maxUploadSize
|
||||
?: HomeServerCapabilities.MAX_UPLOAD_FILE_SIZE_UNKNOWN
|
||||
}
|
||||
|
||||
homeServerCapabilitiesEntity.lastVersionIdentityServerSupported = getVersionResult?.isLoginAndRegistrationSupportedBySdk().orFalse()
|
||||
if (getVersionResult != null) {
|
||||
homeServerCapabilitiesEntity.lastVersionIdentityServerSupported = getVersionResult.isLoginAndRegistrationSupportedBySdk()
|
||||
}
|
||||
|
||||
homeServerCapabilitiesEntity.lastUpdatedTimestamp = Date().time
|
||||
}
|
||||
|
|
|
@ -53,6 +53,6 @@ internal data class ChangePassword(
|
|||
)
|
||||
|
||||
// The spec says: If not present, the client should assume that password changes are possible via the API
|
||||
internal fun GetCapabilitiesResult?.canChangePassword(): Boolean {
|
||||
return this?.capabilities?.changePassword?.enabled.orTrue()
|
||||
internal fun GetCapabilitiesResult.canChangePassword(): Boolean {
|
||||
return capabilities?.changePassword?.enabled.orTrue()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue