Skip to content

Commit

Permalink
Code review
Browse files Browse the repository at this point in the history
  • Loading branch information
BillCarsonFr committed Jul 27, 2021
1 parent 40a19b0 commit eae2f73
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>?
)

Expand All @@ -29,7 +28,6 @@ data class RoomVersionInfo(
val status: RoomVersionStatus
)

@JsonClass(generateAdapter = true)
data class RoomCapabilitySupport(
val preferred: String?,
val support: List<String>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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>)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ class RoomJoinRuleChooseRestrictedViewModel @AssistedInject constructor(

fun handleSubmit() = withState { state ->
setState { copy(updatingStatus = Loading()) }

viewModelScope.launch {
try {
when (state.currentRoomJoinRules) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions vector/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1471,7 +1471,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>
Expand Down Expand Up @@ -3446,8 +3446,8 @@

<string name="error_failed_to_join_room">Sorry, an error occurred while trying to join: %s</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">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>

0 comments on commit eae2f73

Please sign in to comment.