scheduling a refresh of the homeserver capabilities on introduction of new fields

This commit is contained in:
Adam Brown 2022-02-14 12:05:44 +00:00
parent 83cc88060a
commit 4519dec7eb
2 changed files with 13 additions and 0 deletions

View File

@ -18,6 +18,7 @@ package org.matrix.android.sdk.internal.database.migration
import io.realm.DynamicRealm
import org.matrix.android.sdk.internal.database.model.HomeServerCapabilitiesEntityFields
import org.matrix.android.sdk.internal.extensions.forceRefreshOfHomeServerCapabilities
import org.matrix.android.sdk.internal.util.database.RealmMigrator
class MigrateSessionTo025(realm: DynamicRealm) : RealmMigrator(realm, 25) {
@ -27,5 +28,6 @@ class MigrateSessionTo025(realm: DynamicRealm) : RealmMigrator(realm, 25) {
?.addField(HomeServerCapabilitiesEntityFields.CAN_CHANGE_DISPLAY_NAME, Boolean::class.java)
?.addField(HomeServerCapabilitiesEntityFields.CAN_CHANGE_AVATAR, Boolean::class.java)
?.addField(HomeServerCapabilitiesEntityFields.CAN_CHANGE3PID, Boolean::class.java)
?.forceRefreshOfHomeServerCapabilities()
}
}

View File

@ -18,6 +18,8 @@ package org.matrix.android.sdk.internal.extensions
import io.realm.RealmList
import io.realm.RealmObject
import io.realm.RealmObjectSchema
import org.matrix.android.sdk.internal.database.model.HomeServerCapabilitiesEntityFields
internal fun RealmObject.assertIsManaged() {
check(isManaged) { "${javaClass.simpleName} entity should be managed to use this function" }
@ -31,3 +33,12 @@ internal fun <T> RealmList<T>.clearWith(delete: (T) -> Unit) {
first()?.let { delete.invoke(it) }
}
}
/**
* Schedule a refresh of the HomeServers capabilities
*/
internal fun RealmObjectSchema?.forceRefreshOfHomeServerCapabilities(): RealmObjectSchema? {
return this?.transform { obj ->
obj.setLong(HomeServerCapabilitiesEntityFields.LAST_UPDATED_TIMESTAMP, 0)
}
}