adding support for the homeserver display name and avatar capabilities
- MSC3283 https://github.com/matrix-org/synapse/pull/11933 - includes session database migration
This commit is contained in:
parent
a5f4413f6c
commit
d8d6358d15
|
@ -21,6 +21,18 @@ data class HomeServerCapabilities(
|
|||
* True if it is possible to change the password of the account.
|
||||
*/
|
||||
val canChangePassword: Boolean = true,
|
||||
/**
|
||||
* True if it is possible to change the display name of the account.
|
||||
*/
|
||||
val canChangeDisplayName: Boolean = true,
|
||||
/**
|
||||
* True if it is possible to change the avatar of the account.
|
||||
*/
|
||||
val canChangeAvatar: Boolean = true,
|
||||
/**
|
||||
* True if it is possible to change the 3pid associations of the account.
|
||||
*/
|
||||
val canChange3pid: Boolean = true,
|
||||
/**
|
||||
* Max size of file which can be uploaded to the homeserver in bytes. [MAX_UPLOAD_FILE_SIZE_UNKNOWN] if unknown or not retrieved yet
|
||||
*/
|
||||
|
@ -76,6 +88,7 @@ data class HomeServerCapabilities(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun isFeatureSupported(feature: String, byRoomVersion: String): Boolean {
|
||||
if (roomVersions?.capabilities == null) return false
|
||||
val info = roomVersions.capabilities[feature] ?: return false
|
||||
|
|
|
@ -42,6 +42,7 @@ import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo021
|
|||
import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo022
|
||||
import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo023
|
||||
import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo024
|
||||
import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo025
|
||||
import org.matrix.android.sdk.internal.util.Normalizer
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
@ -85,5 +86,6 @@ internal class RealmSessionStoreMigration @Inject constructor(
|
|||
if (oldVersion < 22) MigrateSessionTo022(realm).perform()
|
||||
if (oldVersion < 23) MigrateSessionTo023(realm).perform()
|
||||
if (oldVersion < 24) MigrateSessionTo024(realm).perform()
|
||||
if (oldVersion < 25) MigrateSessionTo025(realm).perform()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,6 +35,9 @@ internal object HomeServerCapabilitiesMapper {
|
|||
fun map(entity: HomeServerCapabilitiesEntity): HomeServerCapabilities {
|
||||
return HomeServerCapabilities(
|
||||
canChangePassword = entity.canChangePassword,
|
||||
canChangeDisplayName = entity.canChangeDisplayName,
|
||||
canChangeAvatar = entity.canChangeAvatar,
|
||||
canChange3pid = entity.canChange3pid,
|
||||
maxUploadFileSize = entity.maxUploadFileSize,
|
||||
lastVersionIdentityServerSupported = entity.lastVersionIdentityServerSupported,
|
||||
defaultIdentityServerUrl = entity.defaultIdentityServerUrl,
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright (c) 2022 The Matrix.org Foundation C.I.C.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
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.util.database.RealmMigrator
|
||||
|
||||
class MigrateSessionTo025(realm: DynamicRealm) : RealmMigrator(realm, 25) {
|
||||
|
||||
override fun doMigrate(realm: DynamicRealm) {
|
||||
realm.schema.get("HomeServerCapabilitiesEntity")
|
||||
?.addField(HomeServerCapabilitiesEntityFields.CAN_CHANGE_DISPLAY_NAME, Boolean::class.java)
|
||||
?.addField(HomeServerCapabilitiesEntityFields.CAN_CHANGE_AVATAR, Boolean::class.java)
|
||||
?.addField(HomeServerCapabilitiesEntityFields.CAN_CHANGE3PID, Boolean::class.java)
|
||||
}
|
||||
}
|
|
@ -21,6 +21,9 @@ import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilities
|
|||
|
||||
internal open class HomeServerCapabilitiesEntity(
|
||||
var canChangePassword: Boolean = true,
|
||||
var canChangeDisplayName: Boolean = true,
|
||||
var canChangeAvatar: Boolean = true,
|
||||
var canChange3pid: Boolean = true,
|
||||
var roomVersionsJson: String? = null,
|
||||
var maxUploadFileSize: Long = HomeServerCapabilities.MAX_UPLOAD_FILE_SIZE_UNKNOWN,
|
||||
var lastVersionIdentityServerSupported: Boolean = false,
|
||||
|
|
|
@ -18,7 +18,6 @@ package org.matrix.android.sdk.internal.session.homeserver
|
|||
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
import org.matrix.android.sdk.api.extensions.orTrue
|
||||
import org.matrix.android.sdk.api.util.JsonDict
|
||||
|
||||
/**
|
||||
|
@ -42,6 +41,25 @@ internal data class Capabilities(
|
|||
@Json(name = "m.change_password")
|
||||
val changePassword: BooleanCapability? = null,
|
||||
|
||||
/**
|
||||
* Capability to indicate if the user can change their display name.
|
||||
* True if the user can change their display name, false otherwise.
|
||||
*/
|
||||
@Json(name = "m.set_displayname")
|
||||
val changeDisplayName: BooleanCapability? = null,
|
||||
|
||||
/**
|
||||
* Capability to indicate if the user can change their avatar.
|
||||
* True if the user can change their avatar, false otherwise.
|
||||
*/
|
||||
@Json(name = "m.set_avatar_url")
|
||||
val changeAvatar: BooleanCapability? = null,
|
||||
/**
|
||||
* Capability to indicate if the user can change add, remove or change 3PID associations.
|
||||
* True if the user can change their 3PID associations, false otherwise.
|
||||
*/
|
||||
@Json(name = "m.3pid_changes")
|
||||
val change3pid: BooleanCapability? = null,
|
||||
/**
|
||||
* This capability describes the default and available room versions a server supports, and at what level of stability.
|
||||
* Clients should make use of this capability to determine if users need to be encouraged to upgrade their rooms.
|
||||
|
@ -88,8 +106,3 @@ internal data class RoomVersions(
|
|||
@Json(name = "org.matrix.msc3244.room_capabilities")
|
||||
val roomCapabilities: JsonDict? = null
|
||||
)
|
||||
|
||||
// The spec says: If not present, the client should assume that password changes are possible via the API
|
||||
internal fun GetCapabilitiesResult.canChangePassword(): Boolean {
|
||||
return capabilities?.changePassword?.enabled.orTrue()
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import com.zhuinden.monarchy.Monarchy
|
|||
import org.matrix.android.sdk.api.MatrixPatterns.getDomain
|
||||
import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig
|
||||
import org.matrix.android.sdk.api.auth.wellknown.WellknownResult
|
||||
import org.matrix.android.sdk.api.extensions.orTrue
|
||||
import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilities
|
||||
import org.matrix.android.sdk.internal.auth.version.Versions
|
||||
import org.matrix.android.sdk.internal.auth.version.isLoginAndRegistrationSupportedBySdk
|
||||
|
@ -108,9 +109,16 @@ internal class DefaultGetHomeServerCapabilitiesTask @Inject constructor(
|
|||
val homeServerCapabilitiesEntity = HomeServerCapabilitiesEntity.getOrCreate(realm)
|
||||
|
||||
if (getCapabilitiesResult != null) {
|
||||
homeServerCapabilitiesEntity.canChangePassword = getCapabilitiesResult.canChangePassword()
|
||||
val capabilities = getCapabilitiesResult.capabilities
|
||||
|
||||
homeServerCapabilitiesEntity.roomVersionsJson = getCapabilitiesResult.capabilities?.roomVersions?.let {
|
||||
// The spec says: If not present, the client should assume that
|
||||
// password, display name, avatar changes and 3pid changes are possible via the API
|
||||
homeServerCapabilitiesEntity.canChangePassword = capabilities?.changePassword?.enabled.orTrue()
|
||||
homeServerCapabilitiesEntity.canChangeDisplayName = capabilities?.changeDisplayName?.enabled.orTrue()
|
||||
homeServerCapabilitiesEntity.canChangeAvatar = capabilities?.changeAvatar?.enabled.orTrue()
|
||||
homeServerCapabilitiesEntity.canChange3pid = capabilities?.change3pid?.enabled.orTrue()
|
||||
|
||||
homeServerCapabilitiesEntity.roomVersionsJson = capabilities?.roomVersions?.let {
|
||||
MoshiProvider.providesMoshi().adapter(RoomVersions::class.java).toJson(it)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue