Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the option "Convertir en salon privé (irréversible)" #1008

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/1007.improvements
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove the option "Convertir en salon privé (irréversible)"
2 changes: 0 additions & 2 deletions library/ui-strings/src/main/res/values-fr/strings_tchap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@
<string name="tchap_scan_media_warning_apk">Pour des raisons de sécurité l’installation d’application à partir de ${app_name} n’est pas autorisée.</string>

<!-- tchap room settings -->
<string name="tchap_room_settings_convert_to_private">Convertir en salon privé (irréversible)</string>
<string name="tchap_room_settings_convert_to_private_prompt_msg"><b>Cette action est irréversible.</b>\nVoulez-vous vraiment convertir ce forum en salon privé ?</string>
<string name="tchap_room_settings_room_access_title">Gestion des comptes externes</string>
<string name="tchap_room_settings_room_access_restricted">Les externes ne sont pas autorisés à rejoindre ce salon</string>
<string name="tchap_room_settings_room_access_unrestricted">Les externes sont autorisés à rejoindre ce salon</string>
Expand Down
2 changes: 0 additions & 2 deletions library/ui-strings/src/main/res/values/strings_tchap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@
<string name="tchap_scan_media_warning_apk">For security reasons, installing applications from ${app_name} is not allowed.</string>

<!-- tchap room settings -->
<string name="tchap_room_settings_convert_to_private">Convert to private room (irreversible)</string>
<string name="tchap_room_settings_convert_to_private_prompt_msg"><b>This action is irreversible.</b>\nAre you sure you want to convert this forum into a private room?</string>
<string name="tchap_room_settings_room_access_title">External accounts handling</string>
<string name="tchap_room_settings_room_access_restricted">The externals are not allowed to join this room</string>
<string name="tchap_room_settings_room_access_unrestricted">The externals are allowed to join this room</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ sealed class RoomSettingsAction : VectorViewModelAction {
data class SetRoomHistoryVisibility(val visibility: RoomHistoryVisibility) : RoomSettingsAction()
data class SetRoomJoinRule(val roomJoinRule: RoomJoinRules) : RoomSettingsAction()
data class SetRoomGuestAccess(val guestAccess: GuestAccess) : RoomSettingsAction()
object RemoveFromRoomsDirectory : RoomSettingsAction()
object AllowExternalUsersToJoin : RoomSettingsAction()

object Save : RoomSettingsAction()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import im.vector.app.R
import im.vector.app.core.epoxy.dividerItem
import im.vector.app.core.epoxy.profiles.buildProfileAction
import im.vector.app.core.epoxy.profiles.buildProfileSection
import im.vector.app.core.error.ErrorFormatter
import im.vector.app.core.resources.StringProvider
import im.vector.app.core.ui.list.verticalMarginItem
import im.vector.app.core.utils.DimensionConverter
Expand All @@ -32,7 +31,6 @@ import im.vector.app.features.form.formEditableAvatarItem
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.RoomDirectoryVisibility
import org.matrix.android.sdk.api.util.toMatrixItem
import javax.inject.Inject

Expand All @@ -41,7 +39,6 @@ class RoomSettingsController @Inject constructor(
private val avatarRenderer: AvatarRenderer,
private val dimensionConverter: DimensionConverter,
private val roomHistoryVisibilityFormatter: RoomHistoryVisibilityFormatter,
private val errorFormatter: ErrorFormatter,
private val vectorPreferences: VectorPreferences
) : TypedEpoxyController<RoomSettingsViewState>() {

Expand All @@ -54,7 +51,6 @@ class RoomSettingsController @Inject constructor(
fun onHistoryVisibilityClicked()
fun onJoinRuleClicked()
fun onToggleGuestAccess()
fun onRemoveFromRoomsDirectory()
fun onAccessByLinkClicked()
fun onAllowExternalUsersToJoin()
}
Expand Down Expand Up @@ -153,12 +149,6 @@ class RoomSettingsController @Inject constructor(

buildRoomAccessRules(data, roomType)

if (data.actionPermissions.canRemoveFromRoomsDirectory &&
(roomType == TchapRoomType.FORUM ||
(roomType == TchapRoomType.UNKNOWN && data.roomDirectoryVisibility() == RoomDirectoryVisibility.PUBLIC))) {
buildRemoveFromRoomsDirectory()
}

// Tchap: Disable "Allow guest to join" switch
// val isPublic = (data.newRoomJoinRules.newJoinRules ?: data.currentRoomJoinRules) == RoomJoinRules.PUBLIC
// if (vectorPreferences.developerMode() && isPublic) {
Expand All @@ -178,18 +168,6 @@ class RoomSettingsController @Inject constructor(
// }
}

private fun buildRemoveFromRoomsDirectory() {
val host = this
buildProfileAction(
id = "removeFromRoomsDirectory",
title = stringProvider.getString(R.string.tchap_room_settings_convert_to_private),
divider = true,
destructive = true,
editable = false,
action = { host.callback?.onRemoveFromRoomsDirectory() }
)
}

private fun buildRoomAccessRules(data: RoomSettingsViewState, roomType: TchapRoomType) {
val host = this
if (data.actionPermissions.canChangeRoomAccessRules && roomType == TchapRoomType.PRIVATE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,17 +206,6 @@ class RoomSettingsFragment :
viewModel.handle(RoomSettingsAction.SetRoomGuestAccess(toggled))
}

override fun onRemoveFromRoomsDirectory() {
MaterialAlertDialogBuilder(requireContext(), R.style.ThemeOverlay_Vector_MaterialAlertDialog_Destructive)
.setTitle(R.string.dialog_title_warning)
.setMessage(getString(R.string.tchap_room_settings_convert_to_private_prompt_msg))
.setPositiveButton(R.string.yes) { _, _ ->
viewModel.handle(RoomSettingsAction.RemoveFromRoomsDirectory)
}
.setNegativeButton(R.string.action_cancel, null)
.show()
}

override fun onImageReady(uri: Uri?) {
uri ?: return
viewModel.handle(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,13 @@
package im.vector.app.features.roomprofile.settings

import androidx.core.net.toFile
import com.airbnb.mvrx.Fail
import com.airbnb.mvrx.Loading
import com.airbnb.mvrx.MavericksViewModelFactory
import com.airbnb.mvrx.Success
import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject
import fr.gouv.tchap.android.sdk.api.session.events.model.TchapEventType
import fr.gouv.tchap.android.sdk.api.session.room.model.RoomAccessRules
import fr.gouv.tchap.android.sdk.api.session.room.model.RoomAccessRulesContent
import fr.gouv.tchap.core.utils.RoomUtils
import fr.gouv.tchap.core.utils.TchapRoomType
import im.vector.app.core.di.MavericksAssistedViewModelFactory
import im.vector.app.core.di.hiltMavericksViewModelFactory
import im.vector.app.core.platform.VectorViewModel
Expand All @@ -48,9 +43,7 @@ import org.matrix.android.sdk.api.session.events.model.toModel
import org.matrix.android.sdk.api.session.getRoom
import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilities
import org.matrix.android.sdk.api.session.room.model.RoomAvatarContent
import org.matrix.android.sdk.api.session.room.model.RoomDirectoryVisibility
import org.matrix.android.sdk.api.session.room.model.RoomGuestAccessContent
import org.matrix.android.sdk.api.session.room.model.RoomHistoryVisibility
import org.matrix.android.sdk.api.session.room.model.RoomHistoryVisibilityContent
import org.matrix.android.sdk.api.session.room.model.RoomJoinRulesContent
import org.matrix.android.sdk.api.session.room.powerlevels.PowerLevelsHelper
Expand Down Expand Up @@ -97,34 +90,6 @@ class RoomSettingsViewModel @AssistedInject constructor(
}
}

private fun fetchRoomDirectoryVisibility() {
setState {
copy(
roomDirectoryVisibility = Loading()
)
}
viewModelScope.launch {
runCatching {
session.roomDirectoryService().getRoomDirectoryVisibility(room.roomId)
}.fold(
{
setState {
copy(
roomDirectoryVisibility = Success(it)
)
}
},
{
setState {
copy(
roomDirectoryVisibility = Fail(it)
)
}
}
)
}
}

private fun observeState() {
onEach(
RoomSettingsViewState::avatarAction,
Expand Down Expand Up @@ -157,9 +122,6 @@ class RoomSettingsViewModel @AssistedInject constructor(
.unwrap()
.execute { async ->
val roomSummary = async.invoke()

if (roomSummary?.let { RoomUtils.getRoomType(it) } == TchapRoomType.UNKNOWN) fetchRoomDirectoryVisibility()

copy(
roomSummary = async,
newName = roomSummary?.name,
Expand Down Expand Up @@ -199,12 +161,7 @@ class RoomSettingsViewModel @AssistedInject constructor(
canChangeRoomAccessRules = powerLevelsHelper.isUserAllowedToSend(
session.myUserId, true,
TchapEventType.STATE_ROOM_ACCESS_RULES
),
// Tchap: Custom parameter
canRemoveFromRoomsDirectory = powerLevelsHelper.isUserAllowedToSend(session.myUserId, true, EventType.STATE_ROOM_JOIN_RULES) &&
powerLevelsHelper.isUserAllowedToSend(session.myUserId, true, EventType.STATE_ROOM_CANONICAL_ALIAS) &&
powerLevelsHelper.isUserAllowedToSend(session.myUserId, true, EventType.STATE_ROOM_ENCRYPTION) &&
powerLevelsHelper.isUserAllowedToSend(session.myUserId, true, EventType.STATE_ROOM_HISTORY_VISIBILITY)
)
)
setState {
copy(actionPermissions = permissions)
Expand Down Expand Up @@ -266,7 +223,6 @@ class RoomSettingsViewModel @AssistedInject constructor(
is RoomSettingsAction.SetRoomHistoryVisibility -> setState { copy(newHistoryVisibility = action.visibility) }
is RoomSettingsAction.SetRoomJoinRule -> handleSetRoomJoinRule(action)
is RoomSettingsAction.SetRoomGuestAccess -> handleSetGuestAccess(action)
RoomSettingsAction.RemoveFromRoomsDirectory -> handleRemoveFromRoomsDirectory()
RoomSettingsAction.AllowExternalUsersToJoin -> handleAllowExternalUsersToJoin()
is RoomSettingsAction.Save -> saveSettings()
is RoomSettingsAction.Cancel -> cancel()
Expand Down Expand Up @@ -298,33 +254,6 @@ class RoomSettingsViewModel @AssistedInject constructor(
}
}

/**
* Several changes are required:
* The new members can access only on invite.
* The encryption has to be enabled by default.
* The room will become private.
* The history visibility value is replaced with invited.
*/
private fun handleRemoveFromRoomsDirectory() {
session.coroutineScope.launch {
updateLoadingState(isLoading = true)
try {
// Update first the joinrule to INVITE.
room.stateService().setJoinRuleInviteOnly()
// Turn on the encryption in this room (if this is not already done).
if (!room.roomCryptoService().isEncrypted()) room.roomCryptoService().enableEncryption()
// Remove the room from the room directory.
session.roomDirectoryService().setRoomDirectoryVisibility(room.roomId, RoomDirectoryVisibility.PRIVATE)
} catch (failure: Throwable) {
updateLoadingState(isLoading = false)
_viewEvents.post(RoomSettingsViewEvents.Failure(failure))
}
// Update history visibility.
tryOrNull { room.stateService().updateHistoryReadability(RoomHistoryVisibility.INVITED) }
updateLoadingState(isLoading = false)
}
}

private fun handleAllowExternalUsersToJoin() {
session.coroutineScope.launch {
updateLoadingState(isLoading = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import im.vector.app.R
import im.vector.app.core.resources.StringProvider
import im.vector.app.features.roomprofile.RoomProfileArgs
import org.matrix.android.sdk.api.session.room.model.GuestAccess
import org.matrix.android.sdk.api.session.room.model.RoomDirectoryVisibility
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.RoomSummary
Expand All @@ -47,7 +46,6 @@ data class RoomSettingsViewState(
val actionPermissions: ActionPermissions = ActionPermissions(),
val supportsRestricted: Boolean = false,
val canUpgradeToRestricted: Boolean = false,
val roomDirectoryVisibility: Async<RoomDirectoryVisibility> = Uninitialized
) : MavericksState {

constructor(args: RoomProfileArgs) : this(roomId = args.roomId)
Expand All @@ -60,7 +58,6 @@ data class RoomSettingsViewState(
val canChangeJoinRule: Boolean = false,
val canChangeCanonicalAlias: Boolean = false,
val canAddChildren: Boolean = false,
val canRemoveFromRoomsDirectory: Boolean = false,
val canChangeRoomAccessRules: Boolean = false
) {
val canChangeAccessByLink: Boolean
Expand Down
Loading