mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-15 01:35:07 +08:00
Code review
This commit is contained in:
parent
a7dc7e8d8a
commit
efdaa49e70
@ -48,6 +48,15 @@ data class HomeServerCapabilities(
|
||||
UNKNOWN
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a feature is supported by the homeserver.
|
||||
* @return
|
||||
* UNKNOWN if the server does not implement room caps
|
||||
* UNSUPPORTED if this feature is not supported
|
||||
* SUPPORTED if this feature is supported by a stable version
|
||||
* SUPPORTED_UNSTABLE if this feature is supported by an unstable version
|
||||
* (unstable version should only be used for dev/experimental purpose)
|
||||
*/
|
||||
fun isFeatureSupported(feature: String): RoomCapabilitySupport {
|
||||
if (roomVersions?.capabilities == null) return RoomCapabilitySupport.UNKNOWN
|
||||
val info = roomVersions.capabilities[feature] ?: return RoomCapabilitySupport.UNSUPPORTED
|
||||
@ -74,6 +83,12 @@ data class HomeServerCapabilities(
|
||||
return info.preferred == byRoomVersion || info.support.contains(byRoomVersion)
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this method to know if you should force a version when creating
|
||||
* a room that requires this feature.
|
||||
* You can also use #isFeatureSupported prior to this call to check if the
|
||||
* feature is supported and report some feedback to user.
|
||||
*/
|
||||
fun versionOverrideForFeature(feature: String) : String? {
|
||||
val cap = roomVersions?.capabilities?.get(feature)
|
||||
return cap?.preferred ?: cap?.support?.lastOrNull()
|
||||
|
@ -16,11 +16,10 @@
|
||||
|
||||
package org.matrix.android.sdk.api.session.homeserver
|
||||
|
||||
import com.squareup.moshi.JsonClass
|
||||
|
||||
data class RoomVersionCapabilities(
|
||||
val defaultRoomVersion: String,
|
||||
val supportedVersion: List<RoomVersionInfo>,
|
||||
// Keys are capabilities defined per spec, as for now knock or restricted
|
||||
val capabilities: Map<String, RoomCapabilitySupport>?
|
||||
)
|
||||
|
||||
@ -29,7 +28,6 @@ data class RoomVersionInfo(
|
||||
val status: RoomVersionStatus
|
||||
)
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class RoomCapabilitySupport(
|
||||
val preferred: String?,
|
||||
val support: List<String>
|
||||
|
@ -101,8 +101,4 @@ interface Room :
|
||||
* Use this room as a Space, if the type is correct.
|
||||
*/
|
||||
fun asSpace(): Space?
|
||||
|
||||
suspend fun setJoinRulePublic()
|
||||
suspend fun setJoinRuleInviteOnly()
|
||||
suspend fun setJoinRuleRestricted(allowList: List<String>)
|
||||
}
|
||||
|
@ -92,4 +92,8 @@ interface StateService {
|
||||
* @param eventTypes Set of eventType to observe. If empty, all state events will be observed
|
||||
*/
|
||||
fun getStateEventsLive(eventTypes: Set<String>, stateKey: QueryStringValue = QueryStringValue.NoCondition): LiveData<List<Event>>
|
||||
|
||||
suspend fun setJoinRulePublic()
|
||||
suspend fun setJoinRuleInviteOnly()
|
||||
suspend fun setJoinRuleRestricted(allowList: List<String>)
|
||||
}
|
||||
|
@ -24,8 +24,6 @@ import org.matrix.android.sdk.api.session.room.accountdata.RoomAccountDataServic
|
||||
import org.matrix.android.sdk.api.session.room.alias.AliasService
|
||||
import org.matrix.android.sdk.api.session.room.call.RoomCallService
|
||||
import org.matrix.android.sdk.api.session.room.members.MembershipService
|
||||
import org.matrix.android.sdk.api.session.room.model.RoomJoinRules
|
||||
import org.matrix.android.sdk.api.session.room.model.RoomJoinRulesAllowEntry
|
||||
import org.matrix.android.sdk.api.session.room.model.RoomSummary
|
||||
import org.matrix.android.sdk.api.session.room.model.RoomType
|
||||
import org.matrix.android.sdk.api.session.room.model.relation.RelationService
|
||||
@ -166,20 +164,4 @@ internal class DefaultRoom(override val roomId: String,
|
||||
if (roomSummary()?.roomType != RoomType.SPACE) return null
|
||||
return DefaultSpace(this, roomSummaryDataSource, viaParameterFinder)
|
||||
}
|
||||
|
||||
override suspend fun setJoinRulePublic() {
|
||||
stateService.updateJoinRule(RoomJoinRules.PUBLIC, null)
|
||||
}
|
||||
|
||||
override suspend fun setJoinRuleInviteOnly() {
|
||||
stateService.updateJoinRule(RoomJoinRules.INVITE, null)
|
||||
}
|
||||
|
||||
override suspend fun setJoinRuleRestricted(allowList: List<String>) {
|
||||
// we need to compute correct via parameters and check if PL are correct
|
||||
val allowEntries = allowList.map { spaceId ->
|
||||
RoomJoinRulesAllowEntry(spaceId, viaParameterFinder.computeViaParamsForRestricted(spaceId, 3))
|
||||
}
|
||||
stateService.updateJoinRule(RoomJoinRules.RESTRICTED, null, allowEntries)
|
||||
}
|
||||
}
|
||||
|
@ -36,11 +36,13 @@ import org.matrix.android.sdk.api.util.JsonDict
|
||||
import org.matrix.android.sdk.api.util.MimeTypes
|
||||
import org.matrix.android.sdk.api.util.Optional
|
||||
import org.matrix.android.sdk.internal.session.content.FileUploader
|
||||
import org.matrix.android.sdk.internal.session.permalinks.ViaParameterFinder
|
||||
|
||||
internal class DefaultStateService @AssistedInject constructor(@Assisted private val roomId: String,
|
||||
private val stateEventDataSource: StateEventDataSource,
|
||||
private val sendStateTask: SendStateTask,
|
||||
private val fileUploader: FileUploader
|
||||
private val fileUploader: FileUploader,
|
||||
private val viaParameterFinder: ViaParameterFinder
|
||||
) : StateService {
|
||||
|
||||
@AssistedFactory
|
||||
@ -168,4 +170,20 @@ internal class DefaultStateService @AssistedInject constructor(@Assisted private
|
||||
stateKey = null
|
||||
)
|
||||
}
|
||||
|
||||
override suspend fun setJoinRulePublic() {
|
||||
updateJoinRule(RoomJoinRules.PUBLIC, null)
|
||||
}
|
||||
|
||||
override suspend fun setJoinRuleInviteOnly() {
|
||||
updateJoinRule(RoomJoinRules.INVITE, null)
|
||||
}
|
||||
|
||||
override suspend fun setJoinRuleRestricted(allowList: List<String>) {
|
||||
// we need to compute correct via parameters and check if PL are correct
|
||||
val allowEntries = allowList.map { spaceId ->
|
||||
RoomJoinRulesAllowEntry(spaceId, viaParameterFinder.computeViaParamsForRestricted(spaceId, 3))
|
||||
}
|
||||
updateJoinRule(RoomJoinRules.RESTRICTED, null, allowEntries)
|
||||
}
|
||||
}
|
||||
|
@ -188,6 +188,7 @@ class RoomJoinRuleChooseRestrictedViewModel @AssistedInject constructor(
|
||||
|
||||
fun handleSubmit() = withState { state ->
|
||||
setState { copy(updatingStatus = Loading()) }
|
||||
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
when (state.currentRoomJoinRules) {
|
||||
|
@ -32,7 +32,7 @@
|
||||
|
||||
<Button
|
||||
android:id="@+id/cancelButton"
|
||||
style="@style/Widget.Vector.Button.Outlined"
|
||||
style="@style/Widget.Vector.Button.Text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="16dp"
|
||||
|
@ -1484,7 +1484,7 @@
|
||||
<string name="room_create_member_of_space_name_can_join">Members of Space %s can find, preview and join.</string>
|
||||
<string name="allow_space_member_to_find_and_access">Allow space members to find and access.</string>
|
||||
<string name="spaces_which_can_access">Spaces which can access</string>
|
||||
<string name="decide_which_spaces_can_access">Decide which spaces can access this room. If a space is selected its members will be able to find and join Room name.</string>
|
||||
<string name="decide_which_spaces_can_access">Decide which spaces can access this room. If a space is selected its members will be able to find and join Room name.</string>
|
||||
<string name="select_spaces">Select spaces</string>
|
||||
<string name="tap_to_edit_spaces">Tap to edit spaces</string>
|
||||
<string name="decide_who_can_find_and_join">Decide who can find and join this room.</string>
|
||||
@ -3478,6 +3478,8 @@
|
||||
|
||||
<string name="upgrade_room_for_restricted">Anyone in %s will be able to find and join this room - no need to manually invite everyone. You’ll be able to change this in room settings anytime.</string>
|
||||
<string name="upgrade_room_for_restricted_no_param">Anyone in a parent space will be able to find and join this room - no need to manually invite everyone. You’ll be able to change this in room settings anytime.</string>
|
||||
<string name="upgrade_room_for_restricted">Anyone in %s will be able to find and join this room - no need to manually invite everyone. You’ll be able to change this in room settings anytime.</string>
|
||||
<string name="upgrade_room_for_restricted_no_param">Anyone in a parent space will be able to find and join this room - no need to manually invite everyone. You’ll be able to change this in room settings anytime.</string>
|
||||
|
||||
<string name="upgrade_room_for_restricted_note">Please note upgrading will make a new version of the room. All current messages will stay in this archived room.</string>
|
||||
<string name="upgrade_room_for_restricted_note">Please note upgrading will make a new version of the room. All current messages will stay in this archived room.</string>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user