Iterate on rendering the "Ask to join" option.
This commit is contained in:
@@ -155,7 +155,7 @@ class SecurityAndPrivacyPresenter(
|
||||
editedSettings = editedSettings,
|
||||
homeserverName = homeserverName,
|
||||
showEnableEncryptionConfirmation = showEnableEncryptionConfirmation,
|
||||
showAskToJoinOption = isKnockEnabled || savedSettings.roomAccess == SecurityAndPrivacyRoomAccess.AskToJoin,
|
||||
isKnockEnabled = isKnockEnabled,
|
||||
saveAction = saveAction.value,
|
||||
permissions = permissions,
|
||||
eventSink = ::handleEvents
|
||||
|
||||
@@ -19,7 +19,7 @@ data class SecurityAndPrivacyState(
|
||||
val editedSettings: SecurityAndPrivacySettings,
|
||||
val homeserverName: String,
|
||||
val showEnableEncryptionConfirmation: Boolean,
|
||||
val showAskToJoinOption: Boolean,
|
||||
val isKnockEnabled: Boolean,
|
||||
val saveAction: AsyncAction<Unit>,
|
||||
private val permissions: SecurityAndPrivacyPermissions,
|
||||
val eventSink: (SecurityAndPrivacyEvents) -> Unit
|
||||
|
||||
@@ -31,7 +31,7 @@ open class SecurityAndPrivacyStateProvider : PreviewParameterProvider<SecurityAn
|
||||
savedSettings = aSecurityAndPrivacySettings(
|
||||
roomAccess = SecurityAndPrivacyRoomAccess.SpaceMember
|
||||
),
|
||||
showAskToJoinOption = false,
|
||||
isKnockEnabled = false,
|
||||
),
|
||||
aSecurityAndPrivacyState(
|
||||
editedSettings = aSecurityAndPrivacySettings(
|
||||
@@ -55,6 +55,12 @@ open class SecurityAndPrivacyStateProvider : PreviewParameterProvider<SecurityAn
|
||||
aSecurityAndPrivacyState(
|
||||
saveAction = AsyncAction.Loading
|
||||
),
|
||||
aSecurityAndPrivacyState(
|
||||
savedSettings = aSecurityAndPrivacySettings(
|
||||
roomAccess = SecurityAndPrivacyRoomAccess.AskToJoin
|
||||
),
|
||||
isKnockEnabled = false,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -84,7 +90,7 @@ fun aSecurityAndPrivacyState(
|
||||
canChangeEncryption = true,
|
||||
canChangeRoomVisibility = true
|
||||
),
|
||||
showAskToJoinOption: Boolean = true,
|
||||
isKnockEnabled: Boolean = true,
|
||||
eventSink: (SecurityAndPrivacyEvents) -> Unit = {}
|
||||
) = SecurityAndPrivacyState(
|
||||
editedSettings = editedSettings,
|
||||
@@ -92,7 +98,7 @@ fun aSecurityAndPrivacyState(
|
||||
homeserverName = homeserverName,
|
||||
showEnableEncryptionConfirmation = showEncryptionConfirmation,
|
||||
saveAction = saveAction,
|
||||
showAskToJoinOption = showAskToJoinOption,
|
||||
isKnockEnabled = isKnockEnabled,
|
||||
permissions = permissions,
|
||||
eventSink = eventSink
|
||||
)
|
||||
|
||||
@@ -81,7 +81,7 @@ fun SecurityAndPrivacyView(
|
||||
modifier = Modifier.padding(top = 24.dp),
|
||||
edited = state.editedSettings.roomAccess,
|
||||
saved = state.savedSettings.roomAccess,
|
||||
showAskToJoinOption = state.showAskToJoinOption,
|
||||
isKnockEnabled = state.isKnockEnabled,
|
||||
onSelectOption = { state.eventSink(SecurityAndPrivacyEvents.ChangeRoomAccess(it)) },
|
||||
)
|
||||
}
|
||||
@@ -177,7 +177,7 @@ private fun SecurityAndPrivacySection(
|
||||
private fun RoomAccessSection(
|
||||
edited: SecurityAndPrivacyRoomAccess,
|
||||
saved: SecurityAndPrivacyRoomAccess,
|
||||
showAskToJoinOption: Boolean,
|
||||
isKnockEnabled: Boolean,
|
||||
onSelectOption: (SecurityAndPrivacyRoomAccess) -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
@@ -191,12 +191,16 @@ private fun RoomAccessSection(
|
||||
trailingContent = ListItemContent.RadioButton(selected = edited == SecurityAndPrivacyRoomAccess.InviteOnly),
|
||||
onClick = { onSelectOption(SecurityAndPrivacyRoomAccess.InviteOnly) },
|
||||
)
|
||||
if (showAskToJoinOption) {
|
||||
// Show Ask to join option in two cases:
|
||||
// - the Knock FF is enabled
|
||||
// - AskToJoin is the current saved value
|
||||
if (saved == SecurityAndPrivacyRoomAccess.AskToJoin || isKnockEnabled) {
|
||||
ListItem(
|
||||
headlineContent = { Text(text = stringResource(R.string.screen_security_and_privacy_ask_to_join_option_title)) },
|
||||
supportingContent = { Text(text = stringResource(R.string.screen_security_and_privacy_ask_to_join_option_description)) },
|
||||
trailingContent = ListItemContent.RadioButton(selected = edited == SecurityAndPrivacyRoomAccess.AskToJoin),
|
||||
onClick = { onSelectOption(SecurityAndPrivacyRoomAccess.AskToJoin) },
|
||||
enabled = isKnockEnabled,
|
||||
)
|
||||
}
|
||||
ListItem(
|
||||
|
||||
@@ -41,7 +41,7 @@ class SecurityAndPrivacyPresenterTest {
|
||||
assertThat(showRoomVisibilitySections).isFalse()
|
||||
assertThat(showHistoryVisibilitySection).isFalse()
|
||||
assertThat(showEncryptionSection).isFalse()
|
||||
assertThat(showAskToJoinOption).isFalse()
|
||||
assertThat(isKnockEnabled).isFalse()
|
||||
}
|
||||
with(awaitItem()) {
|
||||
assertThat(editedSettings).isEqualTo(savedSettings)
|
||||
@@ -52,7 +52,7 @@ class SecurityAndPrivacyPresenterTest {
|
||||
assertThat(showRoomVisibilitySections).isFalse()
|
||||
assertThat(showHistoryVisibilitySection).isTrue()
|
||||
assertThat(showEncryptionSection).isTrue()
|
||||
assertThat(showAskToJoinOption).isFalse()
|
||||
assertThat(isKnockEnabled).isFalse()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -341,7 +341,7 @@ class SecurityAndPrivacyPresenterTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `present - showAskToJoinOption is true if the Knock feature flag is enabled`() = runTest {
|
||||
fun `present - isKnockEnabled is true if the Knock feature flag is enabled`() = runTest {
|
||||
val presenter = createSecurityAndPrivacyPresenter(
|
||||
featureFlagService = FakeFeatureFlagService(
|
||||
initialState = mapOf(
|
||||
@@ -350,30 +350,8 @@ class SecurityAndPrivacyPresenterTest {
|
||||
)
|
||||
)
|
||||
presenter.test {
|
||||
assertThat(awaitItem().showAskToJoinOption).isFalse()
|
||||
assertThat(awaitItem().showAskToJoinOption).isTrue()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `present - showAskToJoinOption is true if ask to join is the current value Knock feature flag is enabled`() = runTest {
|
||||
val presenter = createSecurityAndPrivacyPresenter(
|
||||
featureFlagService = FakeFeatureFlagService(
|
||||
initialState = mapOf(
|
||||
FeatureFlags.Knock.key to false,
|
||||
)
|
||||
),
|
||||
room = FakeJoinedRoom(
|
||||
baseRoom = FakeBaseRoom(
|
||||
canSendStateResult = { _, _ -> Result.success(true) },
|
||||
getRoomVisibilityResult = { Result.success(RoomVisibility.Private) },
|
||||
initialRoomInfo = aRoomInfo(historyVisibility = RoomHistoryVisibility.Shared, joinRule = JoinRule.Knock)
|
||||
),
|
||||
)
|
||||
)
|
||||
presenter.test {
|
||||
assertThat(awaitItem().showAskToJoinOption).isTrue()
|
||||
cancelAndIgnoreRemainingEvents()
|
||||
assertThat(awaitItem().isKnockEnabled).isFalse()
|
||||
assertThat(awaitItem().isKnockEnabled).isTrue()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user