Add lab flag to use restricted access rule

Fixes #3226
This commit is contained in:
Valere 2021-04-26 15:40:41 +02:00
parent 46834d2178
commit 3378e23cc2
4 changed files with 53 additions and 7 deletions

View File

@ -150,14 +150,13 @@ class VectorPreferences @Inject constructor(private val context: Context) {
private const val SETTINGS_ENABLE_SEND_VOICE_FEATURE_PREFERENCE_KEY = "SETTINGS_ENABLE_SEND_VOICE_FEATURE_PREFERENCE_KEY"
const val SETTINGS_LABS_ALLOW_EXTENDED_LOGS = "SETTINGS_LABS_ALLOW_EXTENDED_LOGS"
const val SETTINGS_LABS_USE_RESTRICTED_JOIN_RULE = "SETTINGS_LABS_USE_RESTRICTED_JOIN_RULE"
private const val SETTINGS_DEVELOPER_MODE_PREFERENCE_KEY = "SETTINGS_DEVELOPER_MODE_PREFERENCE_KEY"
private const val SETTINGS_LABS_SHOW_HIDDEN_EVENTS_PREFERENCE_KEY = "SETTINGS_LABS_SHOW_HIDDEN_EVENTS_PREFERENCE_KEY"
private const val SETTINGS_LABS_ENABLE_SWIPE_TO_REPLY = "SETTINGS_LABS_ENABLE_SWIPE_TO_REPLY"
private const val SETTINGS_DEVELOPER_MODE_FAIL_FAST_PREFERENCE_KEY = "SETTINGS_DEVELOPER_MODE_FAIL_FAST_PREFERENCE_KEY"
const val SETTINGS_LABS_USE_SPACES = "SETTINGS_LABS_USE_SPACES"
// SETTINGS_LABS_HIDE_TECHNICAL_E2E_ERRORS
private const val SETTINGS_LABS_SHOW_COMPLETE_HISTORY_IN_ENCRYPTED_ROOM = "SETTINGS_LABS_SHOW_COMPLETE_HISTORY_IN_ENCRYPTED_ROOM"
const val SETTINGS_LABS_UNREAD_NOTIFICATIONS_AS_TAB = "SETTINGS_LABS_UNREAD_NOTIFICATIONS_AS_TAB"
@ -236,6 +235,7 @@ class VectorPreferences @Inject constructor(private val context: Context) {
SETTINGS_DEVELOPER_MODE_PREFERENCE_KEY,
SETTINGS_LABS_SHOW_HIDDEN_EVENTS_PREFERENCE_KEY,
SETTINGS_LABS_ALLOW_EXTENDED_LOGS,
SETTINGS_LABS_USE_RESTRICTED_JOIN_RULE,
SETTINGS_DEVELOPER_MODE_FAIL_FAST_PREFERENCE_KEY,
SETTINGS_USE_RAGE_SHAKE_KEY,
@ -944,4 +944,8 @@ class VectorPreferences @Inject constructor(private val context: Context) {
BackgroundSyncMode.FDROID_BACKGROUND_SYNC_MODE_FOR_BATTERY
}
}
fun labsUseExperimentalRestricted(): Boolean {
return defaultPrefs.getBoolean(SETTINGS_LABS_USE_RESTRICTED_JOIN_RULE, false)
}
}

View File

@ -18,8 +18,14 @@ package im.vector.app.features.spaces.create
import android.net.Uri
import im.vector.app.core.platform.ViewModelTask
import im.vector.app.features.raw.wellknown.getElementWellknown
import im.vector.app.features.raw.wellknown.isE2EByDefault
import im.vector.app.features.settings.VectorPreferences
import org.matrix.android.sdk.api.extensions.tryOrNull
import org.matrix.android.sdk.api.raw.RawService
import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.room.failure.CreateRoomFailure
import org.matrix.android.sdk.api.session.room.model.RoomDirectoryVisibility
import org.matrix.android.sdk.api.session.room.model.RoomJoinRulesAllowEntry
import org.matrix.android.sdk.api.session.room.model.create.CreateRoomParams
import org.matrix.android.sdk.api.session.room.model.create.CreateRoomPreset
@ -44,8 +50,9 @@ data class CreateSpaceTaskParams(
)
class CreateSpaceViewModelTask @Inject constructor(
private val session: Session
// private val stringProvider: StringProvider
private val session: Session,
private val vectorPreferences: VectorPreferences,
private val rawService: RawService
) : ViewModelTask<CreateSpaceTaskParams, CreateSpaceTaskResult> {
override suspend fun execute(params: CreateSpaceTaskParams): CreateSpaceTaskResult {
@ -59,16 +66,27 @@ class CreateSpaceViewModelTask @Inject constructor(
val childErrors = mutableMapOf<String, Throwable>()
val childIds = mutableListOf<String>()
val e2eByDefault = tryOrNull {
rawService.getElementWellknown(session.myUserId)
?.isE2EByDefault()
?: true
} ?: true
params.defaultRooms
.filter { it.isNotBlank() }
.forEach { roomName ->
try {
val roomId = try {
if (params.isPublic) {
session.createRoom(CreateRoomParams().apply {
this.name = roomName
this.preset = CreateRoomPreset.PRESET_PUBLIC_CHAT })
session.createRoom(
CreateRoomParams().apply {
this.name = roomName
this.preset = CreateRoomPreset.PRESET_PUBLIC_CHAT
}
)
} else {
if (vectorPreferences.labsUseExperimentalRestricted()) {
session.createRoom(CreateRoomParams().apply {
this.name = roomName
this.joinRuleRestricted = listOf(
@ -77,7 +95,20 @@ class CreateSpaceViewModelTask @Inject constructor(
via = session.sessionParams.homeServerHost?.let { listOf(it) } ?: emptyList()
)
)
if (e2eByDefault) {
this.enableEncryption()
}
})
} else {
session.createRoom(CreateRoomParams().apply {
this.name = roomName
visibility = RoomDirectoryVisibility.PRIVATE
this.preset = CreateRoomPreset.PRESET_PRIVATE_CHAT
if (e2eByDefault) {
this.enableEncryption()
}
})
}
}
} catch (timeout: CreateRoomFailure.CreatedWithTimeout) {
// we ignore that?

View File

@ -3337,4 +3337,8 @@
<string name="spaces_beta_welcome_to_spaces">Welcome to Spaces!</string>
<string name="spaces_beta_welcome_to_spaces_desc">Spaces are ways to group rooms and people for work, fun or just yourself.</string>
<string name="you_are_invited">You are invited</string>
<string name="labs_use_restricted_join_rule">Experimental Space - Restricted Room.</string>
<string name="labs_use_restricted_join_rule_desc">Warning requires server support and experimental room version</string>
</resources>

View File

@ -43,6 +43,13 @@
android:defaultValue="false"
android:key="SETTINGS_LABS_UNREAD_NOTIFICATIONS_AS_TAB"
android:title="@string/labs_show_unread_notifications_as_tab" />
<im.vector.app.core.preference.VectorSwitchPreference
android:defaultValue="false"
android:key="SETTINGS_LABS_USE_RESTRICTED_JOIN_RULE"
android:title="@string/labs_use_restricted_join_rule"
android:summary="@string/labs_use_restricted_join_rule_desc"/>
<!--</im.vector.app.core.preference.VectorPreferenceCategory>-->
</androidx.preference.PreferenceScreen>