diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/state/DefaultStateService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/state/DefaultStateService.kt index 4948e3ace5..ff2afb5d61 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/state/DefaultStateService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/state/DefaultStateService.kt @@ -34,6 +34,7 @@ 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 java.lang.UnsupportedOperationException internal class DefaultStateService @AssistedInject constructor(@Assisted private val roomId: String, private val stateEventDataSource: StateEventDataSource, @@ -127,6 +128,7 @@ internal class DefaultStateService @AssistedInject constructor(@Assisted private override suspend fun updateJoinRule(joinRules: RoomJoinRules?, guestAccess: GuestAccess?) { if (joinRules != null) { + if (joinRules == RoomJoinRules.RESTRICTED) throw UnsupportedOperationException("No yet supported") sendStateEvent( eventType = EventType.STATE_ROOM_JOIN_RULES, body = mapOf("join_rule" to joinRules), diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/settings/RoomSettingsAction.kt b/vector/src/main/java/im/vector/app/features/roomprofile/settings/RoomSettingsAction.kt index 9f550ecbca..567caa5f97 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/settings/RoomSettingsAction.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/settings/RoomSettingsAction.kt @@ -17,6 +17,7 @@ package im.vector.app.features.roomprofile.settings import im.vector.app.core.platform.VectorViewModelAction +import org.matrix.android.sdk.api.session.room.model.GuestAccess import org.matrix.android.sdk.api.session.room.model.RoomHistoryVisibility import org.matrix.android.sdk.api.session.room.model.RoomJoinRules @@ -26,6 +27,7 @@ sealed class RoomSettingsAction : VectorViewModelAction { data class SetRoomTopic(val newTopic: String) : RoomSettingsAction() data class SetRoomHistoryVisibility(val visibility: RoomHistoryVisibility) : RoomSettingsAction() data class SetRoomJoinRule(val roomJoinRule: RoomJoinRules?) : RoomSettingsAction() + data class SetRoomGuestAccess(val guestAccess: GuestAccess) : RoomSettingsAction() object Save : RoomSettingsAction() object Cancel : RoomSettingsAction() diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/settings/RoomSettingsController.kt b/vector/src/main/java/im/vector/app/features/roomprofile/settings/RoomSettingsController.kt index 6b7a9139db..8096903b4c 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/settings/RoomSettingsController.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/settings/RoomSettingsController.kt @@ -24,8 +24,11 @@ import im.vector.app.core.resources.ColorProvider import im.vector.app.core.resources.StringProvider import im.vector.app.features.form.formEditTextItem import im.vector.app.features.form.formEditableAvatarItem +import im.vector.app.features.form.formSwitchItem import im.vector.app.features.home.AvatarRenderer import im.vector.app.features.home.room.detail.timeline.format.RoomHistoryVisibilityFormatter +import im.vector.app.features.settings.VectorPreferences +import org.matrix.android.sdk.api.session.room.model.GuestAccess import org.matrix.android.sdk.api.session.room.model.RoomJoinRules import org.matrix.android.sdk.api.util.toMatrixItem import javax.inject.Inject @@ -34,6 +37,7 @@ class RoomSettingsController @Inject constructor( private val stringProvider: StringProvider, private val avatarRenderer: AvatarRenderer, private val roomHistoryVisibilityFormatter: RoomHistoryVisibilityFormatter, + private val vectorPreferences: VectorPreferences, colorProvider: ColorProvider ) : TypedEpoxyController() { @@ -45,6 +49,7 @@ class RoomSettingsController @Inject constructor( fun onTopicChanged(topic: String) fun onHistoryVisibilityClicked() fun onJoinRuleClicked() + fun onToggleGuestAccess() } private val dividerColor = colorProvider.getColorFromAttribute(R.attr.vctr_list_divider_color) @@ -122,6 +127,20 @@ class RoomSettingsController @Inject constructor( editable = data.actionPermissions.canChangeJoinRule, action = { if (data.actionPermissions.canChangeJoinRule) callback?.onJoinRuleClicked() } ) + + val isPublic = (data.newRoomJoinRules.newJoinRules ?: data.currentRoomJoinRules) == RoomJoinRules.PUBLIC + if (vectorPreferences.developerMode() && isPublic) { + val guestAccess = data.newRoomJoinRules.newGuestAccess ?: data.currentGuestAccess + // add guest access option? + formSwitchItem { + id("guest_access") + title(stringProvider.getString(R.string.room_settings_guest_access_title)) + switchChecked(guestAccess == GuestAccess.CanJoin) + listener { + callback?.onToggleGuestAccess() + } + } + } } private fun RoomSettingsViewState.getJoinRuleWording(): String { diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/settings/RoomSettingsFragment.kt b/vector/src/main/java/im/vector/app/features/roomprofile/settings/RoomSettingsFragment.kt index dab99c388e..99df27b8f1 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/settings/RoomSettingsFragment.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/settings/RoomSettingsFragment.kt @@ -42,11 +42,11 @@ import im.vector.app.databinding.FragmentRoomSettingGenericBinding import im.vector.app.features.home.AvatarRenderer import im.vector.app.features.roomprofile.RoomProfileArgs import im.vector.app.features.roomprofile.RoomProfileSharedActionViewModel -import im.vector.app.features.roomprofile.settings.historyvisibility.RoomHistoryVisibilitySharedActionViewModel import im.vector.app.features.roomprofile.settings.historyvisibility.RoomHistoryVisibilityBottomSheet +import im.vector.app.features.roomprofile.settings.historyvisibility.RoomHistoryVisibilitySharedActionViewModel import im.vector.app.features.roomprofile.settings.joinrule.RoomJoinRuleBottomSheet import im.vector.app.features.roomprofile.settings.joinrule.RoomJoinRuleSharedActionViewModel - +import org.matrix.android.sdk.api.session.room.model.GuestAccess import org.matrix.android.sdk.api.util.toMatrixItem import java.util.UUID import javax.inject.Inject @@ -174,12 +174,18 @@ class RoomSettingsFragment @Inject constructor( .show(childFragmentManager, "RoomHistoryVisibilityBottomSheet") } - override fun onJoinRuleClicked() = withState(viewModel) { state -> + override fun onJoinRuleClicked() = withState(viewModel) { state -> val currentJoinRule = state.newRoomJoinRules.newJoinRules ?: state.currentRoomJoinRules RoomJoinRuleBottomSheet.newInstance(currentJoinRule) .show(childFragmentManager, "RoomJoinRuleBottomSheet") } + override fun onToggleGuestAccess() = withState(viewModel) { state -> + val currentGuestAccess = state.newRoomJoinRules.newGuestAccess ?: state.currentGuestAccess + val toggled = if (currentGuestAccess == GuestAccess.Forbidden) GuestAccess.CanJoin else GuestAccess.Forbidden + viewModel.handle(RoomSettingsAction.SetRoomGuestAccess(toggled)) + } + override fun onImageReady(uri: Uri?) { uri ?: return viewModel.handle( diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/settings/RoomSettingsViewModel.kt b/vector/src/main/java/im/vector/app/features/roomprofile/settings/RoomSettingsViewModel.kt index 93814d3062..c9271f5357 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/settings/RoomSettingsViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/settings/RoomSettingsViewModel.kt @@ -21,8 +21,8 @@ import com.airbnb.mvrx.FragmentViewModelContext import com.airbnb.mvrx.MvRxViewModelFactory import com.airbnb.mvrx.ViewModelContext import dagger.assisted.Assisted -import dagger.assisted.AssistedInject import dagger.assisted.AssistedFactory +import dagger.assisted.AssistedInject import im.vector.app.core.extensions.exhaustive import im.vector.app.core.platform.VectorViewModel import im.vector.app.features.powerlevel.PowerLevelsObservableFactory @@ -190,6 +190,7 @@ class RoomSettingsViewModel @AssistedInject constructor(@Assisted initialState: is RoomSettingsAction.SetRoomTopic -> setState { copy(newTopic = action.newTopic) } is RoomSettingsAction.SetRoomHistoryVisibility -> setState { copy(newHistoryVisibility = action.visibility) } is RoomSettingsAction.SetRoomJoinRule -> handleSetRoomJoinRule(action) + is RoomSettingsAction.SetRoomGuestAccess -> handleSetGuestAccess(action) is RoomSettingsAction.Save -> saveSettings() is RoomSettingsAction.Cancel -> cancel() }.exhaustive @@ -198,7 +199,17 @@ class RoomSettingsViewModel @AssistedInject constructor(@Assisted initialState: private fun handleSetRoomJoinRule(action: RoomSettingsAction.SetRoomJoinRule) = withState { state -> setState { copy(newRoomJoinRules = RoomSettingsViewState.NewJoinRule( - action.roomJoinRule.takeIf { it != state.currentRoomJoinRules } + newJoinRules = action.roomJoinRule.takeIf { it != state.currentRoomJoinRules }, + newGuestAccess = state.newRoomJoinRules.newGuestAccess.takeIf { it != state.currentGuestAccess } + )) + } + } + + private fun handleSetGuestAccess(action: RoomSettingsAction.SetRoomGuestAccess) = withState { state -> + setState { + copy(newRoomJoinRules = RoomSettingsViewState.NewJoinRule( + newJoinRules = state.newRoomJoinRules.newJoinRules.takeIf { it != state.currentRoomJoinRules }, + newGuestAccess = action.guestAccess.takeIf { it != state.currentGuestAccess } )) } } @@ -230,8 +241,8 @@ class RoomSettingsViewModel @AssistedInject constructor(@Assisted initialState: val summary = state.roomSummary.invoke() when (val avatarAction = state.avatarAction) { - RoomSettingsViewState.AvatarAction.None -> Unit - RoomSettingsViewState.AvatarAction.DeleteAvatar -> { + RoomSettingsViewState.AvatarAction.None -> Unit + RoomSettingsViewState.AvatarAction.DeleteAvatar -> { operationList.add(room.rx().deleteAvatar()) } is RoomSettingsViewState.AvatarAction.UpdateAvatar -> { diff --git a/vector/src/main/res/values/strings.xml b/vector/src/main/res/values/strings.xml index 40d3cc5e1f..4bc0424c32 100644 --- a/vector/src/main/res/values/strings.xml +++ b/vector/src/main/res/values/strings.xml @@ -1405,6 +1405,7 @@ Changes to who can read history will only apply to future messages in this room. The visibility of existing history will be unchanged. Who can access this room? Room access + Allow guests to join Room addresses