Fix default encrypted for restricted

+ hide restricted rule if no current space selected
This commit is contained in:
Valere 2021-09-27 09:52:54 +02:00
parent cde6e8cc1b
commit 97dc07f8c9
5 changed files with 30 additions and 9 deletions

1
changelog.d/4045.bugfix Normal file
View file

@ -0,0 +1 @@
Align new room encryption default to Web

View file

@ -165,7 +165,11 @@ class CreateRoomController @Inject constructor(
host.stringProvider.getString(R.string.create_room_encryption_description) host.stringProvider.getString(R.string.create_room_encryption_description)
} }
) )
switchChecked(viewState.isEncrypted) if (viewState.isEncrypted != null) {
switchChecked(viewState.isEncrypted)
} else {
switchChecked(viewState.defaultEncrypted[viewState.roomJoinRules] ?: false)
}
listener { value -> listener { value ->
host.listener?.setIsEncrypted(value) host.listener?.setIsEncrypted(value)

View file

@ -163,8 +163,9 @@ class CreateRoomFragment @Inject constructor(
} }
override fun selectVisibility() = withState(viewModel) { state -> override fun selectVisibility() = withState(viewModel) { state ->
// If restricted is supported and the user is in the context of a parent space
val allowed = if (state.supportsRestricted) { // then show restricted option.
val allowed = if (state.supportsRestricted && state.parentSpaceId != null) {
listOf(RoomJoinRules.INVITE, RoomJoinRules.PUBLIC, RoomJoinRules.RESTRICTED) listOf(RoomJoinRules.INVITE, RoomJoinRules.PUBLIC, RoomJoinRules.RESTRICTED)
} else { } else {
listOf(RoomJoinRules.INVITE, RoomJoinRules.PUBLIC) listOf(RoomJoinRules.INVITE, RoomJoinRules.PUBLIC)

View file

@ -109,8 +109,13 @@ class CreateRoomViewModel @AssistedInject constructor(@Assisted private val init
setState { setState {
copy( copy(
isEncrypted = RoomJoinRules.INVITE == roomJoinRules && adminE2EByDefault, hsAdminHasDisabledE2E = !adminE2EByDefault,
hsAdminHasDisabledE2E = !adminE2EByDefault defaultEncrypted = mapOf(
RoomJoinRules.INVITE to adminE2EByDefault,
RoomJoinRules.PUBLIC to false,
RoomJoinRules.RESTRICTED to adminE2EByDefault
)
) )
} }
} }
@ -286,8 +291,17 @@ class CreateRoomViewModel @AssistedInject constructor(@Assisted private val init
disableFederation = state.disableFederation disableFederation = state.disableFederation
// Encryption // Encryption
if (state.isEncrypted) { // we ignore the isEncrypted for public room as the switch is hidden in this case
enableEncryption() if (state.roomJoinRules != RoomJoinRules.PUBLIC && state.isEncrypted != null) {
// the user explicitly switch the toggle
if (state.isEncrypted) {
enableEncryption()
}
} else {
// based on default
if (state.defaultEncrypted[state.roomJoinRules] == true) {
enableEncryption()
}
} }
} }

View file

@ -28,7 +28,7 @@ data class CreateRoomViewState(
val roomName: String = "", val roomName: String = "",
val roomTopic: String = "", val roomTopic: String = "",
val roomJoinRules: RoomJoinRules = RoomJoinRules.INVITE, val roomJoinRules: RoomJoinRules = RoomJoinRules.INVITE,
val isEncrypted: Boolean = false, val isEncrypted: Boolean? = null,
val showAdvanced: Boolean = false, val showAdvanced: Boolean = false,
val disableFederation: Boolean = false, val disableFederation: Boolean = false,
val homeServerName: String = "", val homeServerName: String = "",
@ -38,7 +38,8 @@ data class CreateRoomViewState(
val parentSpaceSummary: RoomSummary? = null, val parentSpaceSummary: RoomSummary? = null,
val supportsRestricted: Boolean = false, val supportsRestricted: Boolean = false,
val aliasLocalPart: String? = null, val aliasLocalPart: String? = null,
val isSubSpace: Boolean = false val isSubSpace: Boolean = false,
val defaultEncrypted: Map<RoomJoinRules, Boolean> = emptyMap()
) : MvRxState { ) : MvRxState {
constructor(args: CreateRoomArgs) : this( constructor(args: CreateRoomArgs) : this(