quality: rename enum after PR review
This commit is contained in:
@@ -54,8 +54,8 @@ class RolesAndPermissionsPresenter(
|
||||
derivedStateOf {
|
||||
val currentRole = roomInfo.roleOf(room.sessionId)
|
||||
when (currentRole) {
|
||||
is RoomMember.Role.Admin -> persistentListOf(DemoteActions.ToModerator, DemoteActions.ToMember)
|
||||
is RoomMember.Role.Moderator -> persistentListOf(DemoteActions.ToMember)
|
||||
is RoomMember.Role.Admin -> persistentListOf(SelfDemoteAction.ToModerator, SelfDemoteAction.ToMember)
|
||||
is RoomMember.Role.Moderator -> persistentListOf(SelfDemoteAction.ToMember)
|
||||
else -> persistentListOf()
|
||||
}
|
||||
}
|
||||
@@ -88,7 +88,7 @@ class RolesAndPermissionsPresenter(
|
||||
roomSupportsOwnerRole = roomInfo.privilegedCreatorRole,
|
||||
adminCount = adminCount,
|
||||
moderatorCount = moderatorCount,
|
||||
availableDemoteActions = availableDemoteActions,
|
||||
availableSelfDemoteActions = availableDemoteActions,
|
||||
changeOwnRoleAction = changeOwnRoleAction.value,
|
||||
resetPermissionsAction = resetPermissionsAction.value,
|
||||
eventSink = ::handleEvent,
|
||||
|
||||
@@ -17,15 +17,15 @@ data class RolesAndPermissionsState(
|
||||
val roomSupportsOwnerRole: Boolean,
|
||||
val adminCount: Int?,
|
||||
val moderatorCount: Int?,
|
||||
val availableDemoteActions: ImmutableList<DemoteActions>,
|
||||
val availableSelfDemoteActions: ImmutableList<SelfDemoteAction>,
|
||||
val changeOwnRoleAction: AsyncAction<Unit>,
|
||||
val resetPermissionsAction: AsyncAction<Unit>,
|
||||
val eventSink: (RolesAndPermissionsEvents) -> Unit,
|
||||
) {
|
||||
val canDemoteSelf = availableDemoteActions.isNotEmpty()
|
||||
val canSelfDemote = availableSelfDemoteActions.isNotEmpty()
|
||||
}
|
||||
|
||||
enum class DemoteActions(val role: RoomMember.Role, val titleRes: Int) {
|
||||
enum class SelfDemoteAction(val role: RoomMember.Role, val titleRes: Int) {
|
||||
ToModerator(RoomMember.Role.Moderator, R.string.screen_room_roles_and_permissions_change_role_demote_to_moderator),
|
||||
ToMember(RoomMember.Role.User, R.string.screen_room_roles_and_permissions_change_role_demote_to_member)
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ class RolesAndPermissionsStateProvider : PreviewParameterProvider<RolesAndPermis
|
||||
moderatorCount = 2,
|
||||
resetPermissionsAction = AsyncAction.Failure(IllegalStateException("Failed to reset permissions")),
|
||||
),
|
||||
aRolesAndPermissionsState(availableDemoteActions = emptyList()),
|
||||
aRolesAndPermissionsState(availableSelfDemoteActions = emptyList()),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -55,14 +55,14 @@ internal fun aRolesAndPermissionsState(
|
||||
roomSupportsOwners: Boolean = true,
|
||||
adminCount: Int = 0,
|
||||
moderatorCount: Int = 0,
|
||||
availableDemoteActions: List<DemoteActions> = listOf(DemoteActions.ToModerator, DemoteActions.ToMember),
|
||||
availableSelfDemoteActions: List<SelfDemoteAction> = listOf(SelfDemoteAction.ToModerator, SelfDemoteAction.ToMember),
|
||||
changeOwnRoleAction: AsyncAction<Unit> = AsyncAction.Uninitialized,
|
||||
resetPermissionsAction: AsyncAction<Unit> = AsyncAction.Uninitialized,
|
||||
eventSink: (RolesAndPermissionsEvents) -> Unit = {},
|
||||
) = RolesAndPermissionsState(
|
||||
roomSupportsOwnerRole = roomSupportsOwners,
|
||||
adminCount = adminCount,
|
||||
availableDemoteActions = availableDemoteActions.toImmutableList(),
|
||||
availableSelfDemoteActions = availableSelfDemoteActions.toImmutableList(),
|
||||
moderatorCount = moderatorCount,
|
||||
changeOwnRoleAction = changeOwnRoleAction,
|
||||
resetPermissionsAction = resetPermissionsAction,
|
||||
|
||||
@@ -76,7 +76,7 @@ fun RolesAndPermissionsView(
|
||||
},
|
||||
onClick = { rolesAndPermissionsNavigator.openModeratorList() },
|
||||
)
|
||||
if (state.canDemoteSelf) {
|
||||
if (state.canSelfDemote) {
|
||||
ListItem(
|
||||
headlineContent = { Text(stringResource(R.string.screen_room_roles_and_permissions_change_my_role)) },
|
||||
onClick = { state.eventSink(RolesAndPermissionsEvents.ChangeOwnRole) },
|
||||
@@ -117,7 +117,7 @@ fun RolesAndPermissionsView(
|
||||
when (state.changeOwnRoleAction) {
|
||||
is AsyncAction.Confirming -> {
|
||||
ChangeOwnRoleBottomSheet(
|
||||
availableDemoteActions = state.availableDemoteActions,
|
||||
availableDemoteActions = state.availableSelfDemoteActions,
|
||||
eventSink = state.eventSink,
|
||||
)
|
||||
}
|
||||
@@ -137,7 +137,7 @@ fun RolesAndPermissionsView(
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
private fun ChangeOwnRoleBottomSheet(
|
||||
availableDemoteActions: ImmutableList<DemoteActions>,
|
||||
availableDemoteActions: ImmutableList<SelfDemoteAction>,
|
||||
eventSink: (RolesAndPermissionsEvents) -> Unit,
|
||||
) {
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
|
||||
Reference in New Issue
Block a user