mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-03-18 04:08:44 +03:00
PR review part 1
This commit is contained in:
parent
3e53fa710a
commit
ec515ced66
17 changed files with 110 additions and 66 deletions
|
@ -33,7 +33,11 @@ data class HomeServerCapabilities(
|
|||
* Default identity server url, provided in Wellknown
|
||||
*/
|
||||
val defaultIdentityServerUrl: String? = null,
|
||||
|
||||
/**
|
||||
* Room versions supported by the server
|
||||
* 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.
|
||||
*/
|
||||
val roomVersions: RoomVersionCapabilities? = null
|
||||
) {
|
||||
companion object {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2020 The Matrix.org Foundation C.I.C.
|
||||
* Copyright 2021 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.
|
||||
|
|
|
@ -17,7 +17,9 @@
|
|||
package org.matrix.android.sdk.api.session.room.version
|
||||
|
||||
interface RoomVersionService {
|
||||
|
||||
/**
|
||||
* Return the room version of this room
|
||||
*/
|
||||
fun getRoomVersion(): String
|
||||
|
||||
/**
|
||||
|
@ -26,8 +28,18 @@ interface RoomVersionService {
|
|||
*/
|
||||
suspend fun upgradeToVersion(version: String): String
|
||||
|
||||
/**
|
||||
* Get the recommended room version for the current homeserver
|
||||
*/
|
||||
fun getRecommendedVersion() : String
|
||||
|
||||
/**
|
||||
* Ask if the user has enough power level to upgrade the room
|
||||
*/
|
||||
fun userMayUpgradeRoom(userId: String): Boolean
|
||||
|
||||
/**
|
||||
* Return true if the current room version is declared unstable by the homeserver
|
||||
*/
|
||||
fun isUsingUnstableRoomVersion(): Boolean
|
||||
}
|
||||
|
|
|
@ -312,5 +312,9 @@ class RealmSessionStoreMigration @Inject constructor() : RealmMigration {
|
|||
Timber.d("Step 14 -> 15")
|
||||
realm.schema.get("HomeServerCapabilitiesEntity")
|
||||
?.addField(HomeServerCapabilitiesEntityFields.ROOM_VERSION_JSON, String::class.java)
|
||||
?.transform { obj ->
|
||||
// Schedule a refresh of the capabilities
|
||||
obj.setLong(HomeServerCapabilitiesEntityFields.LAST_UPDATED_TIMESTAMP, 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,20 +37,29 @@ internal object HomeServerCapabilitiesMapper {
|
|||
maxUploadFileSize = entity.maxUploadFileSize,
|
||||
lastVersionIdentityServerSupported = entity.lastVersionIdentityServerSupported,
|
||||
defaultIdentityServerUrl = entity.defaultIdentityServerUrl,
|
||||
roomVersions = entity.roomVersionJson?.let {
|
||||
tryOrNull {
|
||||
MoshiProvider.providesMoshi().adapter(RoomVersions::class.java).fromJson(it)?.let {
|
||||
RoomVersionCapabilities(
|
||||
defaultRoomVersion = it.default ?: DefaultRoomVersionService.DEFAULT_ROOM_VERSION,
|
||||
supportedVersion = it.available.entries.map { entry ->
|
||||
RoomVersionInfo(entry.key, RoomVersionStatus.STABLE
|
||||
.takeIf { entry.value == "stable" }
|
||||
?: RoomVersionStatus.UNSTABLE)
|
||||
roomVersions = mapRoomVersion(entity.roomVersionsJson)
|
||||
)
|
||||
}
|
||||
|
||||
private fun mapRoomVersion(roomVersionsJson: String?): RoomVersionCapabilities? {
|
||||
roomVersionsJson ?: return null
|
||||
|
||||
return tryOrNull {
|
||||
MoshiProvider.providesMoshi().adapter(RoomVersions::class.java).fromJson(roomVersionsJson)?.let {
|
||||
RoomVersionCapabilities(
|
||||
defaultRoomVersion = it.default ?: DefaultRoomVersionService.DEFAULT_ROOM_VERSION,
|
||||
supportedVersion = it.available.entries.map { entry ->
|
||||
RoomVersionInfo(
|
||||
version = entry.key,
|
||||
status = if (entry.value == "stable") {
|
||||
RoomVersionStatus.STABLE
|
||||
} else {
|
||||
RoomVersionStatus.UNSTABLE
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,11 +21,11 @@ import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilities
|
|||
|
||||
internal open class HomeServerCapabilitiesEntity(
|
||||
var canChangePassword: Boolean = true,
|
||||
var roomVersionsJson: String? = null,
|
||||
var maxUploadFileSize: Long = HomeServerCapabilities.MAX_UPLOAD_FILE_SIZE_UNKNOWN,
|
||||
var lastVersionIdentityServerSupported: Boolean = false,
|
||||
var defaultIdentityServerUrl: String? = null,
|
||||
var lastUpdatedTimestamp: Long = 0L,
|
||||
var roomVersionJson: String? = null
|
||||
var lastUpdatedTimestamp: Long = 0L
|
||||
) : RealmObject() {
|
||||
|
||||
companion object
|
||||
|
|
|
@ -16,18 +16,12 @@
|
|||
|
||||
package org.matrix.android.sdk.internal.session.homeserver
|
||||
|
||||
import com.zhuinden.monarchy.Monarchy
|
||||
import io.realm.Realm
|
||||
import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilities
|
||||
import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilitiesService
|
||||
import org.matrix.android.sdk.internal.database.mapper.HomeServerCapabilitiesMapper
|
||||
import org.matrix.android.sdk.internal.database.model.HomeServerCapabilitiesEntity
|
||||
import org.matrix.android.sdk.internal.database.query.get
|
||||
import org.matrix.android.sdk.internal.di.SessionDatabase
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class DefaultHomeServerCapabilitiesService @Inject constructor(
|
||||
@SessionDatabase private val monarchy: Monarchy,
|
||||
private val homeServerCapabilitiesDataSource: HomeServerCapabilitiesDataSource,
|
||||
private val getHomeServerCapabilitiesTask: GetHomeServerCapabilitiesTask
|
||||
) : HomeServerCapabilitiesService {
|
||||
|
||||
|
@ -36,11 +30,7 @@ internal class DefaultHomeServerCapabilitiesService @Inject constructor(
|
|||
}
|
||||
|
||||
override fun getHomeServerCapabilities(): HomeServerCapabilities {
|
||||
return Realm.getInstance(monarchy.realmConfiguration).use { realm ->
|
||||
HomeServerCapabilitiesEntity.get(realm)?.let {
|
||||
HomeServerCapabilitiesMapper.map(it)
|
||||
}
|
||||
}
|
||||
return homeServerCapabilitiesDataSource.getHomeServerCapabilities()
|
||||
?: HomeServerCapabilities()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,11 +61,14 @@ internal data class ChangePassword(
|
|||
@JsonClass(generateAdapter = true)
|
||||
internal data class RoomVersions(
|
||||
/**
|
||||
* Required. True if the user can change their password, false otherwise.
|
||||
* Required. The default room version the server is using for new rooms.
|
||||
*/
|
||||
@Json(name = "default")
|
||||
val default: String?,
|
||||
|
||||
/**
|
||||
* Required. A detailed description of the room versions the server supports.
|
||||
*/
|
||||
@Json(name = "available")
|
||||
val available: JsonDict
|
||||
)
|
||||
|
|
|
@ -106,7 +106,7 @@ internal class DefaultGetHomeServerCapabilitiesTask @Inject constructor(
|
|||
if (getCapabilitiesResult != null) {
|
||||
homeServerCapabilitiesEntity.canChangePassword = getCapabilitiesResult.canChangePassword()
|
||||
|
||||
homeServerCapabilitiesEntity.roomVersionJson = getCapabilitiesResult.capabilities?.roomVersions?.let {
|
||||
homeServerCapabilitiesEntity.roomVersionsJson = getCapabilitiesResult.capabilities?.roomVersions?.let {
|
||||
MoshiProvider.providesMoshi().adapter(RoomVersions::class.java).toJson(it)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright (c) 2021 New Vector Ltd
|
||||
*
|
||||
* 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.session.homeserver
|
||||
|
||||
import com.zhuinden.monarchy.Monarchy
|
||||
import io.realm.Realm
|
||||
import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilities
|
||||
import org.matrix.android.sdk.internal.database.mapper.HomeServerCapabilitiesMapper
|
||||
import org.matrix.android.sdk.internal.database.model.HomeServerCapabilitiesEntity
|
||||
import org.matrix.android.sdk.internal.database.query.get
|
||||
import org.matrix.android.sdk.internal.di.SessionDatabase
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class HomeServerCapabilitiesDataSource @Inject constructor(
|
||||
@SessionDatabase private val monarchy: Monarchy
|
||||
) {
|
||||
fun getHomeServerCapabilities(): HomeServerCapabilities? {
|
||||
return Realm.getInstance(monarchy.realmConfiguration).use { realm ->
|
||||
HomeServerCapabilitiesEntity.get(realm)?.let {
|
||||
HomeServerCapabilitiesMapper.map(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -68,10 +68,11 @@ internal class DefaultRoom(override val roomId: String,
|
|||
private val roomMembersService: MembershipService,
|
||||
private val roomPushRuleService: RoomPushRuleService,
|
||||
private val roomAccountDataService: RoomAccountDataService,
|
||||
private val roomVersionService: RoomVersionService,
|
||||
private val sendStateTask: SendStateTask,
|
||||
private val viaParameterFinder: ViaParameterFinder,
|
||||
private val searchTask: SearchTask,
|
||||
private val roomVersionService: RoomVersionService) :
|
||||
private val searchTask: SearchTask
|
||||
) :
|
||||
Room,
|
||||
TimelineService by timelineService,
|
||||
SendService by sendService,
|
||||
|
|
|
@ -89,10 +89,10 @@ internal class DefaultRoomFactory @Inject constructor(private val cryptoService:
|
|||
roomMembersService = membershipServiceFactory.create(roomId),
|
||||
roomPushRuleService = roomPushRuleServiceFactory.create(roomId),
|
||||
roomAccountDataService = roomAccountDataServiceFactory.create(roomId),
|
||||
roomVersionService = roomVersionServiceFactory.create(roomId),
|
||||
sendStateTask = sendStateTask,
|
||||
searchTask = searchTask,
|
||||
viaParameterFinder = viaParameterFinder,
|
||||
roomVersionService = roomVersionServiceFactory.create(roomId)
|
||||
viaParameterFinder = viaParameterFinder
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,11 +16,9 @@
|
|||
|
||||
package org.matrix.android.sdk.internal.session.room.version
|
||||
|
||||
import com.zhuinden.monarchy.Monarchy
|
||||
import dagger.assisted.Assisted
|
||||
import dagger.assisted.AssistedFactory
|
||||
import dagger.assisted.AssistedInject
|
||||
import io.realm.Realm
|
||||
import org.matrix.android.sdk.api.query.QueryStringValue
|
||||
import org.matrix.android.sdk.api.session.events.model.EventType
|
||||
import org.matrix.android.sdk.api.session.events.model.toModel
|
||||
|
@ -29,15 +27,12 @@ import org.matrix.android.sdk.api.session.room.model.PowerLevelsContent
|
|||
import org.matrix.android.sdk.api.session.room.model.create.RoomCreateContent
|
||||
import org.matrix.android.sdk.api.session.room.powerlevels.PowerLevelsHelper
|
||||
import org.matrix.android.sdk.api.session.room.version.RoomVersionService
|
||||
import org.matrix.android.sdk.internal.database.mapper.HomeServerCapabilitiesMapper
|
||||
import org.matrix.android.sdk.internal.database.model.HomeServerCapabilitiesEntity
|
||||
import org.matrix.android.sdk.internal.database.query.get
|
||||
import org.matrix.android.sdk.internal.di.SessionDatabase
|
||||
import org.matrix.android.sdk.internal.session.homeserver.HomeServerCapabilitiesDataSource
|
||||
import org.matrix.android.sdk.internal.session.room.state.StateEventDataSource
|
||||
|
||||
internal class DefaultRoomVersionService @AssistedInject constructor(
|
||||
@Assisted private val roomId: String,
|
||||
@SessionDatabase private val monarchy: Monarchy,
|
||||
private val homeServerCapabilitiesDataSource: HomeServerCapabilitiesDataSource,
|
||||
private val stateEventDataSource: StateEventDataSource,
|
||||
private val roomVersionUpgradeTask: RoomVersionUpgradeTask
|
||||
) : RoomVersionService {
|
||||
|
@ -59,29 +54,20 @@ internal class DefaultRoomVersionService @AssistedInject constructor(
|
|||
override suspend fun upgradeToVersion(version: String): String {
|
||||
return roomVersionUpgradeTask.execute(
|
||||
RoomVersionUpgradeTask.Params(
|
||||
roomId, version
|
||||
roomId = roomId,
|
||||
newVersion = version
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
override fun getRecommendedVersion(): String {
|
||||
return Realm.getInstance(monarchy.realmConfiguration).use { realm ->
|
||||
HomeServerCapabilitiesEntity.get(realm)?.let {
|
||||
HomeServerCapabilitiesMapper.map(it)
|
||||
}?.roomVersions?.defaultRoomVersion ?: DEFAULT_ROOM_VERSION
|
||||
}
|
||||
return homeServerCapabilitiesDataSource.getHomeServerCapabilities()?.roomVersions?.defaultRoomVersion ?: DEFAULT_ROOM_VERSION
|
||||
}
|
||||
|
||||
override fun isUsingUnstableRoomVersion(): Boolean {
|
||||
var isUsingUnstable: Boolean
|
||||
Realm.getInstance(monarchy.realmConfiguration).use { realm ->
|
||||
val versionCaps = HomeServerCapabilitiesEntity.get(realm)?.let {
|
||||
HomeServerCapabilitiesMapper.map(it)
|
||||
}?.roomVersions
|
||||
val currentVersion = getRoomVersion()
|
||||
isUsingUnstable = versionCaps?.supportedVersion?.firstOrNull { it.version == currentVersion }?.status == RoomVersionStatus.UNSTABLE
|
||||
}
|
||||
return isUsingUnstable
|
||||
val versionCaps = homeServerCapabilitiesDataSource.getHomeServerCapabilities()?.roomVersions
|
||||
val currentVersion = getRoomVersion()
|
||||
return versionCaps?.supportedVersion?.firstOrNull { it.version == currentVersion }?.status == RoomVersionStatus.UNSTABLE
|
||||
}
|
||||
|
||||
override fun userMayUpgradeRoom(userId: String): Boolean {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2019 New Vector Ltd
|
||||
* Copyright 2021 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -23,10 +23,7 @@ import im.vector.app.core.epoxy.VectorEpoxyHolder
|
|||
import im.vector.app.core.epoxy.VectorEpoxyModel
|
||||
|
||||
/**
|
||||
* A generic list item.
|
||||
* Displays an item with a title, and optional description.
|
||||
* Can display an accessory on the right, that can be an image or an indeterminate progress.
|
||||
* If provided with an action, will display a button at the bottom of the list item.
|
||||
* A generic progress bar item.
|
||||
*/
|
||||
@EpoxyModelClass(layout = R.layout.item_generic_progress)
|
||||
abstract class GenericProgressBarItem : VectorEpoxyModel<GenericProgressBarItem.Holder>() {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<ProgressBar xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/genericProgressBar"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
style="@style/Widget.Vector.ProgressBar.Horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="8dp" />
|
|
@ -24,10 +24,10 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:paddingStart="4dp"
|
||||
android:paddingEnd="0dp"
|
||||
android:accessibilityLiveRegion="polite"
|
||||
android:gravity="start"
|
||||
android:paddingStart="4dp"
|
||||
android:paddingEnd="0dp"
|
||||
android:textColor="?vctr_content_primary"
|
||||
tools:text="@string/room_do_not_have_permission_to_post" />
|
||||
|
||||
|
|
|
@ -2736,7 +2736,7 @@
|
|||
<string name="settings_server_upload_size_content">Your homeserver accepts attachments (files, media, etc.) with a size up to %s.</string>
|
||||
<string name="settings_server_upload_size_unknown">The limit is unknown.</string>
|
||||
<!-- Only visible in developer mode-->
|
||||
<string name="settings_server_room_versions">Room Versions 🕶</string>
|
||||
<string name="settings_server_room_versions">Room Versions 👓</string>
|
||||
<string name="settings_server_default_room_version">Default Version</string>
|
||||
<string name="settings_server_room_version_stable">stable</string>
|
||||
<string name="settings_server_room_version_unstable">unstable</string>
|
||||
|
|
Loading…
Add table
Reference in a new issue