feat: every other member's row offers every action (member-row-actions, Phase 3)

The overflow menu replaces the chevron on every row but the viewer's
own, whoever is looking. It lists every action that fits the member's
role, open or not, in a fixed order. One that is not open is marked --
the quieter role colour, an info icon, and an "Unavailable" state -- and
opens the screen that says why instead of acting. It is not disabled,
which would leave the explanation unreachable.

Your own row is unchanged: the menu when stepping down is open, the
chevron otherwise. The row says "View profile" to assistive technology
now that the chevron that said it is gone from most rows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kgothatso NgakoandClaude Opus 5.5 committed 2026-11-20 09:32:51 +02:00
1 parent 7c39c7b90c
commit 3447fa11fa
3 files changed
+153 -28

No files matched your search

@@ -69,6 +69,9 @@ import mobi.giza.compose.database.model.intermdiate.LocalParticipant
import mobi.giza.compose.repository.ChatRepository
import mobi.giza.compose.repository.NostrRepository
import mobi.giza.compose.ui.composable.navigation.routes.ProfilePreviewRoute
import mobi.giza.compose.ui.composable.navigation.routes.MemberActionUnavailableRoute
import androidx.compose.ui.semantics.onClick
import androidx.compose.ui.semantics.semantics
import mobi.giza.compose.ui.composable.navigation.routes.Route
import mobi.giza.compose.ui.composable.navigation.routes.CreateSharedKeyRoute
import mobi.giza.compose.ui.composable.navigation.routes.ProposalListRoute
@@ -109,6 +112,7 @@ import mobi.giza.compose.resources.make_them_admins
import mobi.giza.compose.resources.s_took_part_in_the_key_ceremony_but_are_not_admins
import mobi.giza.compose.resources.founding_members_are_not_admins
import mobi.giza.compose.resources.admin
import mobi.giza.compose.resources.view_profile
import mobi.giza.compose.resources.run_by_members
import mobi.giza.compose.resources.parent_group
import mobi.giza.compose.resources.a_subgroup
@@ -249,6 +253,7 @@ fun ChatRoomDetailScreen(
val adminOfferSent = stringResource(Res.string.admin_offer_sent)
val promotionAccepted = stringResource(Res.string.promotion_accepted)
val adminLabel = stringResource(Res.string.admin)
val viewProfile = stringResource(Res.string.view_profile)
val shareLabel = stringResource(Res.string.holds_a_share)
val rotationRequested = stringResource(Res.string.share_rotation_requested)
val sharesActionSent = stringResource(Res.string.shares_action_sent)
@@ -1072,15 +1077,22 @@ fun ChatRoomDetailScreen(
// keyed by the public key, which is the one thing
// every row here has, and it shows the cached
// profile at once while the relays refresh it.
Card(
onClick = {
onNavigateToRoute.invoke(
ProfilePreviewRoute(
activeUserPublicKey = activeUserPublicKey,
profilePublicKey = localParticipant.participant.participantPublicKey
)
val openProfile = {
onNavigateToRoute.invoke(
ProfilePreviewRoute(
activeUserPublicKey = activeUserPublicKey,
profilePublicKey = localParticipant.participant.participantPublicKey
)
}
)
}
Card(
// The chevron that said so is gone from every other
// member's row; the label keeps saying it to anyone
// who cannot see the row. docs/member-row-actions.md, D7.
modifier = Modifier.semantics {
onClick(label = viewProfile) { openProfile(); true }
},
onClick = openProfile,
) {
ListItem(
leadingContent = {
@@ -1091,17 +1103,29 @@ fun ChatRoomDetailScreen(
},
trailingContent = {
val memberPublicKey = localParticipant.participant.participantPublicKey
val actions = chatRoomDetailUIState.memberActions[memberPublicKey].orEmpty()
.filter { it.isAvailable }
.map { it.action }
.toSet()
if (actions.isNotEmpty()) {
// What this device may do to this member, decided by the
// view model from the group's state. Every one is a commit
// through the publish gate, applied when a relay accepts
// it, which is why the row stays as it is until then. See
// docs/member-admin-promotion.md, Phase 11.
MemberActionsMenu(actions = actions) { action ->
val options = chatRoomDetailUIState.memberActions[memberPublicKey].orEmpty()
if (options.isNotEmpty()) {
// Every action that fits this member, open or not, decided by
// the view model from the group's state: every other member's
// row has the menu whoever is looking, and this device's own
// only when stepping down is open. An open action is a commit
// through the publish gate, applied when a relay accepts it,
// which is why the row stays as it is until then; one that is
// not opens the screen that says why. See
// docs/member-row-actions.md, D1 to D3.
MemberActionsMenu(
options = options,
onExplain = { action ->
onNavigateToRoute.invoke(
MemberActionUnavailableRoute(
activeUserPublicKey = activeUserPublicKey,
chatRoomId = chatRoomId,
memberPublicKey = memberPublicKey,
action = action,
)
)
},
) { action ->
if (action == MemberAction.REMOVE_FROM_GROUP) {
chatRoomDetailViewModel.removeMember(
localChatRoom = chatRoomDetailUIState.localChatRoom,
@@ -1123,9 +1147,10 @@ fun ChatRoomDetailScreen(
}
}
} else {
// This device's own row, with nothing open on it.
Icon(
Icons.Default.ChevronRight,
contentDescription = "View profile"
contentDescription = viewProfile
)
}
},
@@ -9,6 +9,7 @@ import androidx.compose.foundation.selection.selectable
import androidx.compose.foundation.selection.selectableGroup
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.MoreVert
import androidx.compose.material.icons.outlined.Info
import androidx.compose.material.icons.filled.Verified
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.DropdownMenu
@@ -16,6 +17,7 @@ import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.MenuDefaults
import androidx.compose.material3.RadioButton
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
@@ -28,6 +30,8 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.stateDescription
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import mobi.giza.compose.resources.Res
import mobi.giza.compose.resources.cancel
@@ -55,36 +59,56 @@ import mobi.giza.compose.resources.step_down_and_leave
import mobi.giza.compose.resources.step_down_and_leave_body
import mobi.giza.compose.resources.step_down_body
import mobi.giza.compose.resources.step_down_title
import mobi.giza.compose.resources.unavailable
import mobi.giza.compose.resources.why_this_is_unavailable
import mobi.giza.compose.ui.theme.spacing
import mobi.giza.compose.ui.composable.widgets.Decorative
import mobi.giza.compose.ui.view.state.AdminLeave
import mobi.giza.compose.ui.view.state.GovernanceStatus
import mobi.giza.compose.ui.view.state.MemberAction
import mobi.giza.compose.ui.view.state.MemberActionOption
import org.jetbrains.compose.resources.stringResource
/**
* The member row's overflow menu: the actions [actions] allows, and nothing else.
* The view model decides them; this only lays them out. A 48dp `IconButton`, as
* every target is. See docs/member-admin-promotion.md, Phase 11.
* The member row's overflow menu: every action [options] lists for this member,
* open or not, in a fixed order so an item never moves when it opens. An open one
* goes to [onAction]; one that is not is marked -- in the menu's quieter role
* colour, with an info icon and a state a screen reader says -- and goes to
* [onExplain], which opens the screen that says why. Not `enabled = false`: a
* disabled item takes no click, and the explanation could never be reached.
* A 48dp `IconButton`, as every target is. See docs/member-row-actions.md, D3.
*/
@Composable
internal fun MemberActionsMenu(
actions: Set<MemberAction>,
options: List<MemberActionOption>,
onExplain: (MemberAction) -> Unit,
onAction: (MemberAction) -> Unit,
) {
var expanded by remember { mutableStateOf(false) }
val unavailable = stringResource(Res.string.unavailable)
Box {
IconButton(onClick = { expanded = true }) {
Icon(Icons.Default.MoreVert, contentDescription = stringResource(Res.string.member_actions))
}
DropdownMenu(expanded = expanded, onDismissRequest = { expanded = false }) {
// In a fixed order, whatever order the set holds them in.
MemberAction.entries.filter { it in actions }.forEach { action ->
options.sortedBy { it.action.ordinal }.forEach { option ->
DropdownMenuItem(
text = { Text(stringResource(action.label())) },
text = { Text(stringResource(option.action.label())) },
modifier = if (option.isAvailable) Modifier else Modifier.semantics { stateDescription = unavailable },
colors = if (option.isAvailable) {
MenuDefaults.itemColors()
} else {
MenuDefaults.itemColors(
textColor = MaterialTheme.colorScheme.onSurfaceVariant,
trailingIconColor = MaterialTheme.colorScheme.onSurfaceVariant,
)
},
trailingIcon = if (option.isAvailable) null else {
{ Icon(Icons.Outlined.Info, contentDescription = stringResource(Res.string.why_this_is_unavailable)) }
},
onClick = {
expanded = false
onAction(action)
if (option.isAvailable) onAction(option.action) else onExplain(option.action)
},
)
}
@@ -3,7 +3,11 @@ package mobi.giza.compose.ui.composable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.AccessibilityAction
import androidx.compose.ui.semantics.SemanticsActions
import androidx.compose.ui.semantics.getOrNull
import androidx.compose.ui.test.ComposeUiTest
import androidx.compose.ui.test.SemanticsMatcher
import androidx.compose.ui.test.ExperimentalTestApi
import androidx.compose.ui.test.assertCountEquals
import androidx.compose.ui.test.onAllNodesWithContentDescription
@@ -18,12 +22,14 @@ import mobi.giza.compose.repository.ChatRepository
import mobi.giza.compose.repository.NostrRepository
import mobi.giza.compose.ui.composable.GroupSignedWorkFixtures.activeUserPublicKey
import mobi.giza.compose.ui.composable.GroupSignedWorkFixtures.chatRoomId
import mobi.giza.compose.ui.composable.navigation.routes.MemberActionUnavailableRoute
import mobi.giza.compose.ui.composable.navigation.routes.ProfilePreviewRoute
import mobi.giza.compose.ui.composable.navigation.routes.Route
import mobi.giza.compose.ui.composable.widgets.ProvideSnackbarHost
import mobi.giza.compose.ui.theme.GizaTheme
import mobi.giza.compose.ui.view.state.ChatRoomDetailUIState
import mobi.giza.compose.ui.view.state.MemberAction
import mobi.giza.compose.ui.view.state.MemberActionBlocker
import mobi.giza.compose.ui.view.state.MemberActionOption
import kotlin.test.Test
import kotlin.test.assertEquals
@@ -94,6 +100,76 @@ class ChatRoomMemberRowJvmTest {
}
}
/**
* A member who is not an admin sees the menu on every other row, every item
* marked, and an item opens the screen that says why -- not a dialog, and not
* the change. docs/member-row-actions.md, Phase 3.
*/
@Test
fun `a member who is not an admin sees every action, and an unavailable one explains itself`() {
var opened: Route? = null
val notAnAdmin = listOf(MemberActionBlocker.NotAnAdmin(setOf(named)))
render(
onNavigateToRoute = { opened = it },
state = state().copy(
memberActions = mapOf(
named to listOf(
MemberActionOption(MemberAction.REMOVE_AS_ADMIN, notAnAdmin + MemberActionBlocker.OnlyAdmin),
MemberActionOption(MemberAction.REMOVE_FROM_GROUP, notAnAdmin + MemberActionBlocker.OnlyAdmin),
),
stillLoading to listOf(
MemberActionOption(MemberAction.MAKE_ADMIN, notAnAdmin),
MemberActionOption(MemberAction.REMOVE_FROM_GROUP, notAnAdmin),
),
),
),
) {
// Every other member's row, in place of the chevron.
onAllNodesWithContentDescription("Member actions").assertCountEquals(2)
onAllNodesWithContentDescription("View profile").assertCountEquals(0)
onAllNodesWithContentDescription("Member actions")[1].performClick()
onAllNodesWithContentDescription("Why this is unavailable").assertCountEquals(2)
onNodeWithText("Make admin").performClick()
// No confirmation: nothing is about to change.
onNodeWithText("an admin?", substring = true).assertDoesNotExist()
}
assertEquals(MemberActionUnavailableRoute(activeUserPublicKey, chatRoomId, stillLoading, MemberAction.MAKE_ADMIN), opened)
}
@Test
fun `your own row keeps the chevron unless stepping down is open`() {
val me = member(activeUserPublicKey, Profile(publicKey = activeUserPublicKey, displayName = "Me", nostrEventId = "f".repeat(64)))
val withMe = state().let { it.copy(localChatRoom = it.localChatRoom.copy(localParticipants = listOf(me) + it.localChatRoom.localParticipants)) }
render(onNavigateToRoute = {}, state = withMe) {
onAllNodesWithContentDescription("View profile").assertCountEquals(3)
}
render(onNavigateToRoute = {}, state = withMe.copy(memberActions = mapOf(activeUserPublicKey to listOf(MemberActionOption(MemberAction.STEP_DOWN))))) {
onAllNodesWithContentDescription("Member actions").assertCountEquals(1)
onNodeWithContentDescription("Member actions").performClick()
onNodeWithText("Step down as admin").assertExists()
onNodeWithContentDescription("Why this is unavailable").assertDoesNotExist()
}
}
/** The chevron's description, kept on the row itself now that the chevron is gone. D7. */
@Test
fun `a row says it opens the profile, without the chevron`() {
val viewProfile = SemanticsMatcher("clicks to view the profile") {
val onClick: AccessibilityAction<() -> Boolean>? = it.config.getOrNull(SemanticsActions.OnClick)
onClick?.label == "View profile"
}
render(
onNavigateToRoute = {},
state = state().copy(memberActions = mapOf(named to listOf(MemberActionOption(MemberAction.MAKE_ADMIN)))),
) {
onAllNodes(viewProfile).assertCountEquals(2)
}
}
@Test
fun `an admin's row says so, and a share holder's says that apart`() {
render(