Set guest access in developer mode
This commit is contained in:
parent
14103b1e7c
commit
5a84456f1f
|
@ -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.MimeTypes
|
||||||
import org.matrix.android.sdk.api.util.Optional
|
import org.matrix.android.sdk.api.util.Optional
|
||||||
import org.matrix.android.sdk.internal.session.content.FileUploader
|
import org.matrix.android.sdk.internal.session.content.FileUploader
|
||||||
|
import java.lang.UnsupportedOperationException
|
||||||
|
|
||||||
internal class DefaultStateService @AssistedInject constructor(@Assisted private val roomId: String,
|
internal class DefaultStateService @AssistedInject constructor(@Assisted private val roomId: String,
|
||||||
private val stateEventDataSource: StateEventDataSource,
|
private val stateEventDataSource: StateEventDataSource,
|
||||||
|
@ -127,6 +128,7 @@ internal class DefaultStateService @AssistedInject constructor(@Assisted private
|
||||||
|
|
||||||
override suspend fun updateJoinRule(joinRules: RoomJoinRules?, guestAccess: GuestAccess?) {
|
override suspend fun updateJoinRule(joinRules: RoomJoinRules?, guestAccess: GuestAccess?) {
|
||||||
if (joinRules != null) {
|
if (joinRules != null) {
|
||||||
|
if (joinRules == RoomJoinRules.RESTRICTED) throw UnsupportedOperationException("No yet supported")
|
||||||
sendStateEvent(
|
sendStateEvent(
|
||||||
eventType = EventType.STATE_ROOM_JOIN_RULES,
|
eventType = EventType.STATE_ROOM_JOIN_RULES,
|
||||||
body = mapOf("join_rule" to joinRules),
|
body = mapOf("join_rule" to joinRules),
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
package im.vector.app.features.roomprofile.settings
|
package im.vector.app.features.roomprofile.settings
|
||||||
|
|
||||||
import im.vector.app.core.platform.VectorViewModelAction
|
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.RoomHistoryVisibility
|
||||||
import org.matrix.android.sdk.api.session.room.model.RoomJoinRules
|
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 SetRoomTopic(val newTopic: String) : RoomSettingsAction()
|
||||||
data class SetRoomHistoryVisibility(val visibility: RoomHistoryVisibility) : RoomSettingsAction()
|
data class SetRoomHistoryVisibility(val visibility: RoomHistoryVisibility) : RoomSettingsAction()
|
||||||
data class SetRoomJoinRule(val roomJoinRule: RoomJoinRules?) : RoomSettingsAction()
|
data class SetRoomJoinRule(val roomJoinRule: RoomJoinRules?) : RoomSettingsAction()
|
||||||
|
data class SetRoomGuestAccess(val guestAccess: GuestAccess) : RoomSettingsAction()
|
||||||
|
|
||||||
object Save : RoomSettingsAction()
|
object Save : RoomSettingsAction()
|
||||||
object Cancel : RoomSettingsAction()
|
object Cancel : RoomSettingsAction()
|
||||||
|
|
|
@ -24,8 +24,11 @@ import im.vector.app.core.resources.ColorProvider
|
||||||
import im.vector.app.core.resources.StringProvider
|
import im.vector.app.core.resources.StringProvider
|
||||||
import im.vector.app.features.form.formEditTextItem
|
import im.vector.app.features.form.formEditTextItem
|
||||||
import im.vector.app.features.form.formEditableAvatarItem
|
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.AvatarRenderer
|
||||||
import im.vector.app.features.home.room.detail.timeline.format.RoomHistoryVisibilityFormatter
|
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.session.room.model.RoomJoinRules
|
||||||
import org.matrix.android.sdk.api.util.toMatrixItem
|
import org.matrix.android.sdk.api.util.toMatrixItem
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
@ -34,6 +37,7 @@ class RoomSettingsController @Inject constructor(
|
||||||
private val stringProvider: StringProvider,
|
private val stringProvider: StringProvider,
|
||||||
private val avatarRenderer: AvatarRenderer,
|
private val avatarRenderer: AvatarRenderer,
|
||||||
private val roomHistoryVisibilityFormatter: RoomHistoryVisibilityFormatter,
|
private val roomHistoryVisibilityFormatter: RoomHistoryVisibilityFormatter,
|
||||||
|
private val vectorPreferences: VectorPreferences,
|
||||||
colorProvider: ColorProvider
|
colorProvider: ColorProvider
|
||||||
) : TypedEpoxyController<RoomSettingsViewState>() {
|
) : TypedEpoxyController<RoomSettingsViewState>() {
|
||||||
|
|
||||||
|
@ -45,6 +49,7 @@ class RoomSettingsController @Inject constructor(
|
||||||
fun onTopicChanged(topic: String)
|
fun onTopicChanged(topic: String)
|
||||||
fun onHistoryVisibilityClicked()
|
fun onHistoryVisibilityClicked()
|
||||||
fun onJoinRuleClicked()
|
fun onJoinRuleClicked()
|
||||||
|
fun onToggleGuestAccess()
|
||||||
}
|
}
|
||||||
|
|
||||||
private val dividerColor = colorProvider.getColorFromAttribute(R.attr.vctr_list_divider_color)
|
private val dividerColor = colorProvider.getColorFromAttribute(R.attr.vctr_list_divider_color)
|
||||||
|
@ -122,6 +127,20 @@ class RoomSettingsController @Inject constructor(
|
||||||
editable = data.actionPermissions.canChangeJoinRule,
|
editable = data.actionPermissions.canChangeJoinRule,
|
||||||
action = { if (data.actionPermissions.canChangeJoinRule) callback?.onJoinRuleClicked() }
|
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 {
|
private fun RoomSettingsViewState.getJoinRuleWording(): String {
|
||||||
|
|
|
@ -42,11 +42,11 @@ import im.vector.app.databinding.FragmentRoomSettingGenericBinding
|
||||||
import im.vector.app.features.home.AvatarRenderer
|
import im.vector.app.features.home.AvatarRenderer
|
||||||
import im.vector.app.features.roomprofile.RoomProfileArgs
|
import im.vector.app.features.roomprofile.RoomProfileArgs
|
||||||
import im.vector.app.features.roomprofile.RoomProfileSharedActionViewModel
|
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.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.RoomJoinRuleBottomSheet
|
||||||
import im.vector.app.features.roomprofile.settings.joinrule.RoomJoinRuleSharedActionViewModel
|
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 org.matrix.android.sdk.api.util.toMatrixItem
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
@ -174,12 +174,18 @@ class RoomSettingsFragment @Inject constructor(
|
||||||
.show(childFragmentManager, "RoomHistoryVisibilityBottomSheet")
|
.show(childFragmentManager, "RoomHistoryVisibilityBottomSheet")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onJoinRuleClicked() = withState(viewModel) { state ->
|
override fun onJoinRuleClicked() = withState(viewModel) { state ->
|
||||||
val currentJoinRule = state.newRoomJoinRules.newJoinRules ?: state.currentRoomJoinRules
|
val currentJoinRule = state.newRoomJoinRules.newJoinRules ?: state.currentRoomJoinRules
|
||||||
RoomJoinRuleBottomSheet.newInstance(currentJoinRule)
|
RoomJoinRuleBottomSheet.newInstance(currentJoinRule)
|
||||||
.show(childFragmentManager, "RoomJoinRuleBottomSheet")
|
.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?) {
|
override fun onImageReady(uri: Uri?) {
|
||||||
uri ?: return
|
uri ?: return
|
||||||
viewModel.handle(
|
viewModel.handle(
|
||||||
|
|
|
@ -21,8 +21,8 @@ import com.airbnb.mvrx.FragmentViewModelContext
|
||||||
import com.airbnb.mvrx.MvRxViewModelFactory
|
import com.airbnb.mvrx.MvRxViewModelFactory
|
||||||
import com.airbnb.mvrx.ViewModelContext
|
import com.airbnb.mvrx.ViewModelContext
|
||||||
import dagger.assisted.Assisted
|
import dagger.assisted.Assisted
|
||||||
import dagger.assisted.AssistedInject
|
|
||||||
import dagger.assisted.AssistedFactory
|
import dagger.assisted.AssistedFactory
|
||||||
|
import dagger.assisted.AssistedInject
|
||||||
import im.vector.app.core.extensions.exhaustive
|
import im.vector.app.core.extensions.exhaustive
|
||||||
import im.vector.app.core.platform.VectorViewModel
|
import im.vector.app.core.platform.VectorViewModel
|
||||||
import im.vector.app.features.powerlevel.PowerLevelsObservableFactory
|
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.SetRoomTopic -> setState { copy(newTopic = action.newTopic) }
|
||||||
is RoomSettingsAction.SetRoomHistoryVisibility -> setState { copy(newHistoryVisibility = action.visibility) }
|
is RoomSettingsAction.SetRoomHistoryVisibility -> setState { copy(newHistoryVisibility = action.visibility) }
|
||||||
is RoomSettingsAction.SetRoomJoinRule -> handleSetRoomJoinRule(action)
|
is RoomSettingsAction.SetRoomJoinRule -> handleSetRoomJoinRule(action)
|
||||||
|
is RoomSettingsAction.SetRoomGuestAccess -> handleSetGuestAccess(action)
|
||||||
is RoomSettingsAction.Save -> saveSettings()
|
is RoomSettingsAction.Save -> saveSettings()
|
||||||
is RoomSettingsAction.Cancel -> cancel()
|
is RoomSettingsAction.Cancel -> cancel()
|
||||||
}.exhaustive
|
}.exhaustive
|
||||||
|
@ -198,7 +199,17 @@ class RoomSettingsViewModel @AssistedInject constructor(@Assisted initialState:
|
||||||
private fun handleSetRoomJoinRule(action: RoomSettingsAction.SetRoomJoinRule) = withState { state ->
|
private fun handleSetRoomJoinRule(action: RoomSettingsAction.SetRoomJoinRule) = withState { state ->
|
||||||
setState {
|
setState {
|
||||||
copy(newRoomJoinRules = RoomSettingsViewState.NewJoinRule(
|
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()
|
val summary = state.roomSummary.invoke()
|
||||||
|
|
||||||
when (val avatarAction = state.avatarAction) {
|
when (val avatarAction = state.avatarAction) {
|
||||||
RoomSettingsViewState.AvatarAction.None -> Unit
|
RoomSettingsViewState.AvatarAction.None -> Unit
|
||||||
RoomSettingsViewState.AvatarAction.DeleteAvatar -> {
|
RoomSettingsViewState.AvatarAction.DeleteAvatar -> {
|
||||||
operationList.add(room.rx().deleteAvatar())
|
operationList.add(room.rx().deleteAvatar())
|
||||||
}
|
}
|
||||||
is RoomSettingsViewState.AvatarAction.UpdateAvatar -> {
|
is RoomSettingsViewState.AvatarAction.UpdateAvatar -> {
|
||||||
|
|
|
@ -1405,6 +1405,7 @@
|
||||||
<string name="room_settings_room_read_history_dialog_subtitle">Changes to who can read history will only apply to future messages in this room. The visibility of existing history will be unchanged.</string>
|
<string name="room_settings_room_read_history_dialog_subtitle">Changes to who can read history will only apply to future messages in this room. The visibility of existing history will be unchanged.</string>
|
||||||
<string name="room_settings_room_access_rules_pref_dialog_title">Who can access this room?</string>
|
<string name="room_settings_room_access_rules_pref_dialog_title">Who can access this room?</string>
|
||||||
<string name="room_settings_room_access_title">Room access</string>
|
<string name="room_settings_room_access_title">Room access</string>
|
||||||
|
<string name="room_settings_guest_access_title">Allow guests to join</string>
|
||||||
|
|
||||||
<!-- room settings : alias -->
|
<!-- room settings : alias -->
|
||||||
<string name="room_settings_alias_title">Room addresses</string>
|
<string name="room_settings_alias_title">Room addresses</string>
|
||||||
|
|
Loading…
Reference in New Issue