Improve code around confirmation.
This commit is contained in:
committed by
Benoit Marty
parent
0110cf018a
commit
57708bd462
@@ -136,13 +136,18 @@ class ChangeRolesPresenter(
|
||||
val isModifyingAdmins = role == RoomMember.Role.Admin
|
||||
val isConfirming = saveState.value.isConfirming()
|
||||
val modifyingOwners = role is RoomMember.Role.Owner
|
||||
|
||||
val needsConfirmation = (modifyingOwners || currentUserIsAdmin && isModifyingAdmins) && hasPendingChanges && !isConfirming
|
||||
|
||||
val confirmationValue = if (hasPendingChanges && !isConfirming) {
|
||||
when {
|
||||
modifyingOwners -> ConfirmingModifyingOwners
|
||||
currentUserIsAdmin && isModifyingAdmins -> ConfirmingModifyingAdmins
|
||||
else -> null
|
||||
}
|
||||
} else {
|
||||
null
|
||||
}
|
||||
when {
|
||||
needsConfirmation -> {
|
||||
// Confirm modifying users
|
||||
saveState.value = AsyncAction.ConfirmingNoParams
|
||||
confirmationValue != null -> {
|
||||
saveState.value = confirmationValue
|
||||
}
|
||||
!saveState.value.isLoading() -> {
|
||||
roomCoroutineScope.save(usersWithRole.value, selectedUsers, saveState)
|
||||
|
||||
@@ -178,29 +178,23 @@ fun ChangeRolesView(
|
||||
onDismiss = { state.eventSink(ChangeRolesEvent.CloseDialog) }
|
||||
)
|
||||
}
|
||||
else -> {
|
||||
when (state.role) {
|
||||
is RoomMember.Role.Owner -> {
|
||||
ConfirmationDialog(
|
||||
title = stringResource(R.string.screen_room_change_role_confirm_change_owners_title),
|
||||
content = stringResource(R.string.screen_room_change_role_confirm_change_owners_description),
|
||||
submitText = stringResource(CommonStrings.action_continue),
|
||||
onSubmitClick = { state.eventSink(ChangeRolesEvent.Save) },
|
||||
onDismiss = { state.eventSink(ChangeRolesEvent.CloseDialog) },
|
||||
destructiveSubmit = true,
|
||||
)
|
||||
}
|
||||
is RoomMember.Role.Admin -> {
|
||||
ConfirmationDialog(
|
||||
title = stringResource(R.string.screen_room_change_role_confirm_add_admin_title),
|
||||
content = stringResource(R.string.screen_room_change_role_confirm_add_admin_description),
|
||||
onSubmitClick = { state.eventSink(ChangeRolesEvent.Save) },
|
||||
onDismiss = { state.eventSink(ChangeRolesEvent.CloseDialog) }
|
||||
)
|
||||
}
|
||||
// No confirmation needed for Moderator or User roles
|
||||
else -> Unit
|
||||
}
|
||||
is ConfirmingModifyingOwners -> {
|
||||
ConfirmationDialog(
|
||||
title = stringResource(R.string.screen_room_change_role_confirm_change_owners_title),
|
||||
content = stringResource(R.string.screen_room_change_role_confirm_change_owners_description),
|
||||
submitText = stringResource(CommonStrings.action_continue),
|
||||
onSubmitClick = { state.eventSink(ChangeRolesEvent.Save) },
|
||||
onDismiss = { state.eventSink(ChangeRolesEvent.CloseDialog) },
|
||||
destructiveSubmit = true,
|
||||
)
|
||||
}
|
||||
is ConfirmingModifyingAdmins -> {
|
||||
ConfirmationDialog(
|
||||
title = stringResource(R.string.screen_room_change_role_confirm_add_admin_title),
|
||||
content = stringResource(R.string.screen_room_change_role_confirm_add_admin_description),
|
||||
onSubmitClick = { state.eventSink(ChangeRolesEvent.Save) },
|
||||
onDismiss = { state.eventSink(ChangeRolesEvent.CloseDialog) }
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
* Copyright (c) 2025 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.rolesandpermissions.impl.roles
|
||||
|
||||
import io.element.android.libraries.architecture.AsyncAction
|
||||
|
||||
data object ConfirmingModifyingAdmins : AsyncAction.Confirming
|
||||
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
* Copyright (c) 2025 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.rolesandpermissions.impl.roles
|
||||
|
||||
import io.element.android.libraries.architecture.AsyncAction
|
||||
|
||||
data object ConfirmingModifyingOwners : AsyncAction.Confirming
|
||||
@@ -358,7 +358,7 @@ class ChangeRolesPresenterTest {
|
||||
initialState.eventSink(ChangeRolesEvent.UserSelectionToggled(MatrixUser(A_USER_ID_2)))
|
||||
awaitItem().eventSink(ChangeRolesEvent.Save)
|
||||
val confirmingState = awaitItem()
|
||||
assertThat(confirmingState.savingState).isEqualTo(AsyncAction.ConfirmingNoParams)
|
||||
assertThat(confirmingState.savingState).isEqualTo(ConfirmingModifyingAdmins)
|
||||
confirmingState.eventSink(ChangeRolesEvent.Save)
|
||||
assertThat(awaitItem().savingState).isInstanceOf(AsyncAction.Loading::class.java)
|
||||
assertThat(awaitItem().savingState).isEqualTo(AsyncAction.Success(true))
|
||||
@@ -383,7 +383,7 @@ class ChangeRolesPresenterTest {
|
||||
|
||||
awaitItem().eventSink(ChangeRolesEvent.Save)
|
||||
val confirmingState = awaitItem()
|
||||
assertThat(confirmingState.savingState).isEqualTo(AsyncAction.ConfirmingNoParams)
|
||||
assertThat(confirmingState.savingState).isEqualTo(ConfirmingModifyingAdmins)
|
||||
|
||||
confirmingState.eventSink(ChangeRolesEvent.CloseDialog)
|
||||
assertThat(awaitItem().savingState).isEqualTo(AsyncAction.Uninitialized)
|
||||
|
||||
Reference in New Issue
Block a user