mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-10-31 16:22:49 +00:00
Made the hooks of room creation and security & privacy screen more generic.
This commit is contained in:
+16
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright (c) 2026 Element Creations Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.features.securityandprivacy.impl.root
|
||||
|
||||
import dev.zacsweers.metro.ContributesBinding
|
||||
import io.element.android.libraries.di.RoomScope
|
||||
|
||||
@ContributesBinding(RoomScope::class)
|
||||
class NoopSecurityAndPrivacyExtension : SecurityAndPrivacyExtension {
|
||||
override suspend fun isPublicAccessAllowed(): Boolean = true
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright (c) 2026 Element Creations Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.features.securityandprivacy.impl.root
|
||||
|
||||
/** Lets a build-specific implementation adjust what the security and privacy screen offers. */
|
||||
interface SecurityAndPrivacyExtension {
|
||||
/** Whether the room access may be changed to anyone. */
|
||||
suspend fun isPublicAccessAllowed(): Boolean
|
||||
}
|
||||
+4
-3
@@ -65,6 +65,7 @@ class SecurityAndPrivacyPresenter(
|
||||
private val room: JoinedRoom,
|
||||
private val featureFlagService: FeatureFlagService,
|
||||
private val sessionEnterpriseService: SessionEnterpriseService,
|
||||
private val securityAndPrivacyExtension: SecurityAndPrivacyExtension,
|
||||
) : Presenter<SecurityAndPrivacyState> {
|
||||
@AssistedFactory
|
||||
interface Factory {
|
||||
@@ -89,8 +90,8 @@ class SecurityAndPrivacyPresenter(
|
||||
value = sessionEnterpriseService.isEncryptionDisabledByHomeserver()
|
||||
}
|
||||
|
||||
val arePublicRoomsDisabledByHomeserver by produceState(false) {
|
||||
value = sessionEnterpriseService.arePublicRoomsDisabledByHomeserver()
|
||||
val isPublicAccessAllowed by produceState(true) {
|
||||
value = securityAndPrivacyExtension.isPublicAccessAllowed()
|
||||
}
|
||||
|
||||
val savedIsVisibleInRoomDirectory = remember { mutableStateOf<AsyncData<Boolean>>(AsyncData.Uninitialized) }
|
||||
@@ -258,7 +259,7 @@ class SecurityAndPrivacyPresenter(
|
||||
selectableJoinedSpaces = selectableJoinedSpaces,
|
||||
spaceSelectionMode = spaceSelectionMode,
|
||||
isEncryptionDisabledByHomeserver = isEncryptionDisabledByHomeserver,
|
||||
arePublicRoomsDisabledByHomeserver = arePublicRoomsDisabledByHomeserver,
|
||||
isPublicAccessAllowed = isPublicAccessAllowed,
|
||||
eventSink = ::handleEvent,
|
||||
)
|
||||
|
||||
|
||||
+3
-3
@@ -28,7 +28,7 @@ data class SecurityAndPrivacyState(
|
||||
val editedSettings: SecurityAndPrivacySettings,
|
||||
val homeserverName: String,
|
||||
val isEncryptionDisabledByHomeserver: Boolean,
|
||||
private val arePublicRoomsDisabledByHomeserver: Boolean,
|
||||
private val isPublicAccessAllowed: Boolean,
|
||||
val showEnableEncryptionConfirmation: Boolean,
|
||||
private val isKnockEnabled: Boolean,
|
||||
val saveAction: AsyncAction<Unit>,
|
||||
@@ -42,8 +42,8 @@ data class SecurityAndPrivacyState(
|
||||
|
||||
// Show Anyone option when:
|
||||
// - Anyone is the current saved value, OR
|
||||
// - The homeserver allows public rooms
|
||||
val showAnyoneOption = savedSettings.roomAccess == SecurityAndPrivacyRoomAccess.Anyone || !arePublicRoomsDisabledByHomeserver
|
||||
// - Public access is allowed
|
||||
val showAnyoneOption = savedSettings.roomAccess == SecurityAndPrivacyRoomAccess.Anyone || isPublicAccessAllowed
|
||||
|
||||
// Show SpaceMember option in two cases:
|
||||
// - SpaceMember is the current saved value
|
||||
|
||||
+2
-6
@@ -37,10 +37,6 @@ open class SecurityAndPrivacyStatePreviewParam : PreviewParameterProvider<Securi
|
||||
showEncryptionConfirmation = true,
|
||||
isSpace = false,
|
||||
),
|
||||
aSecurityAndPrivacyState(
|
||||
arePublicRoomsDisabledByHomeserver = true,
|
||||
isSpace = false,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -143,7 +139,7 @@ fun aSecurityAndPrivacyState(
|
||||
selectableJoinedSpaces: Set<SpaceRoom> = emptySet(),
|
||||
spaceSelectionMode: SpaceSelectionMode = SpaceSelectionMode.None,
|
||||
isEncryptionDisabledByHomeserver: Boolean = false,
|
||||
arePublicRoomsDisabledByHomeserver: Boolean = false,
|
||||
isPublicAccessAllowed: Boolean = true,
|
||||
eventSink: (SecurityAndPrivacyEvent) -> Unit = {}
|
||||
) = SecurityAndPrivacyState(
|
||||
editedSettings = editedSettings,
|
||||
@@ -157,6 +153,6 @@ fun aSecurityAndPrivacyState(
|
||||
selectableJoinedSpaces = selectableJoinedSpaces.toImmutableSet(),
|
||||
spaceSelectionMode = spaceSelectionMode,
|
||||
isEncryptionDisabledByHomeserver = isEncryptionDisabledByHomeserver,
|
||||
arePublicRoomsDisabledByHomeserver = arePublicRoomsDisabledByHomeserver,
|
||||
isPublicAccessAllowed = isPublicAccessAllowed,
|
||||
eventSink = eventSink,
|
||||
)
|
||||
|
||||
+2
-43
@@ -34,8 +34,6 @@ import io.element.android.libraries.matrix.test.room.aRoomInfo
|
||||
import io.element.android.libraries.matrix.test.room.powerlevels.FakeRoomPermissions
|
||||
import io.element.android.libraries.matrix.test.spaces.FakeSpaceService
|
||||
import io.element.android.libraries.previewutils.room.aSpaceRoom
|
||||
import io.element.android.tests.testutils.consumeItemsUntilPredicate
|
||||
import io.element.android.tests.testutils.consumeItemsUntilTimeout
|
||||
import io.element.android.tests.testutils.lambda.assert
|
||||
import io.element.android.tests.testutils.lambda.lambdaError
|
||||
import io.element.android.tests.testutils.lambda.lambdaRecorder
|
||||
@@ -1050,10 +1048,7 @@ class SecurityAndPrivacyPresenterTest {
|
||||
|
||||
@Test
|
||||
fun `present - showEncryptionSection is false if the HS disabled encryption`() = runTest {
|
||||
val sessionEnterpriseService = FakeSessionEnterpriseService(
|
||||
isEncryptionDisabledResult = { true },
|
||||
arePublicRoomsDisabledResult = { false },
|
||||
)
|
||||
val sessionEnterpriseService = FakeSessionEnterpriseService(isEncryptionDisabledResult = { true })
|
||||
val presenter = createSecurityAndPrivacyPresenter(
|
||||
sessionEnterpriseService = sessionEnterpriseService,
|
||||
)
|
||||
@@ -1065,42 +1060,6 @@ class SecurityAndPrivacyPresenterTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `present - showAnyoneOption is false if the HS disabled public rooms`() = runTest {
|
||||
val presenter = createSecurityAndPrivacyPresenter(
|
||||
sessionEnterpriseService = FakeSessionEnterpriseService(
|
||||
isEncryptionDisabledResult = { false },
|
||||
arePublicRoomsDisabledResult = { true },
|
||||
),
|
||||
)
|
||||
presenter.test {
|
||||
consumeItemsUntilPredicate { !it.showAnyoneOption }
|
||||
cancelAndIgnoreRemainingEvents()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `present - showAnyoneOption is true if the HS disabled public rooms but the room is already public`() = runTest {
|
||||
val presenter = createSecurityAndPrivacyPresenter(
|
||||
room = FakeJoinedRoom(
|
||||
baseRoom = FakeBaseRoom(
|
||||
roomPermissions = roomPermissions(),
|
||||
getRoomVisibilityResult = { Result.success(RoomVisibility.Public) },
|
||||
initialRoomInfo = aRoomInfo(historyVisibility = RoomHistoryVisibility.Shared, joinRule = JoinRule.Public)
|
||||
),
|
||||
),
|
||||
sessionEnterpriseService = FakeSessionEnterpriseService(
|
||||
isEncryptionDisabledResult = { false },
|
||||
arePublicRoomsDisabledResult = { true },
|
||||
),
|
||||
)
|
||||
presenter.test {
|
||||
val states = consumeItemsUntilTimeout()
|
||||
assertThat(states).isNotEmpty()
|
||||
assertThat(states.all { it.showAnyoneOption }).isTrue()
|
||||
}
|
||||
}
|
||||
|
||||
private fun roomPermissions(
|
||||
canChangeRoomAccess: Boolean = true,
|
||||
canChangeHistoryVisibility: Boolean = true,
|
||||
@@ -1141,7 +1100,6 @@ class SecurityAndPrivacyPresenterTest {
|
||||
spaceSelectionStateHolder: SpaceSelectionStateHolder = SpaceSelectionStateHolder(),
|
||||
sessionEnterpriseService: FakeSessionEnterpriseService = FakeSessionEnterpriseService(
|
||||
isEncryptionDisabledResult = { false },
|
||||
arePublicRoomsDisabledResult = { false },
|
||||
)
|
||||
): SecurityAndPrivacyPresenter {
|
||||
return SecurityAndPrivacyPresenter(
|
||||
@@ -1151,6 +1109,7 @@ class SecurityAndPrivacyPresenterTest {
|
||||
featureFlagService = featureFlagService,
|
||||
spaceSelectionStateHolder = spaceSelectionStateHolder,
|
||||
sessionEnterpriseService = sessionEnterpriseService,
|
||||
securityAndPrivacyExtension = NoopSecurityAndPrivacyExtension(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user