Merge branch 'claude/group-member-row-actions-1016b2' into giza
This commit is contained in:
commit
b7de119eb6
24 files changed
+1997
-62
No files matched your search
@@ -553,4 +553,38 @@
|
||||
<string name="not_enough_people_for_a_group_yet">Not enough people for a group yet.</string>
|
||||
<string name="a_group_needs_at_least_two_other_people">A group needs at least two other people, and everyone in it is added when it's made. To talk with one person, start a chat with them instead.</string>
|
||||
<string name="run_by_alone">Run by %1$s alone. Changes to this group don't need anyone else's approval.</string>
|
||||
<!-- Why a member row's action is not open: docs/member-row-actions.md, D6. -->
|
||||
<string name="member_action_no_admins_title">This room has no admins</string>
|
||||
<string name="member_action_no_admins_body">Its members run the group from the group's admin room. Make the change there.</string>
|
||||
<string name="open_the_admin_room">Open the admin room</string>
|
||||
<string name="member_action_legacy_title">This group uses an older format</string>
|
||||
<string name="member_action_legacy_body">Giza can't change who runs a group made in the older format. A new group can.</string>
|
||||
<string name="member_action_disbanded_title">This group was disbanded</string>
|
||||
<string name="member_action_disbanded_body">Nothing can change a group once it has been disbanded.</string>
|
||||
<string name="member_action_you_left_title">You've left this group</string>
|
||||
<string name="member_action_you_left_body">Only members of a group can change it.</string>
|
||||
<string name="member_action_not_an_admin_title">Only admins can do this</string>
|
||||
<string name="member_action_not_an_admin_body">Ask one of the group's admins: %1$s.</string>
|
||||
<string name="member_action_signatures_title">This group was made before signed changes</string>
|
||||
<string name="member_action_signatures_body">Who runs a group with a shared key changes only with the group's signature. This group was made before Giza asked for one, so its admins stay as they are. A new group can change them.</string>
|
||||
<string name="member_action_share_rotation_title">Not in this version of Giza yet</string>
|
||||
<string name="member_action_share_rotation_body">Changing the admins of a group with a shared key moves a share of the key, and this version of Giza can't do that yet.</string>
|
||||
<string name="member_action_not_in_group_title">%1$s isn't fully in the group</string>
|
||||
<string name="member_action_not_in_group_body">They're still being added, or they're already being removed. Try again once that has happened.</string>
|
||||
<string name="member_action_only_admin_title">%1$s is the only admin</string>
|
||||
<string name="member_action_only_admin_body">A group always needs an admin. Make someone else an admin first.</string>
|
||||
<string name="member_action_below_floor_title">A group with a shared key needs at least %1$s admins</string>
|
||||
<string name="member_action_below_floor_body">Make someone else an admin first, then try again.</string>
|
||||
<string name="member_action_change_pending_title">An earlier change is still on its way</string>
|
||||
<string name="member_action_change_pending_body">A relay hasn't accepted the last change to this group yet. This clears by itself.</string>
|
||||
<string name="member_action_offer_pending_title">%1$s has already been asked</string>
|
||||
<string name="member_action_offer_pending_body">They've been offered admin and haven't answered yet.</string>
|
||||
<string name="also_in_the_way">Also in the way</string>
|
||||
<string name="you_can_do_this_now">You can do this now</string>
|
||||
<string name="you_can_do_this_now_body">Nothing stands in the way any more. Go back to the group to do it.</string>
|
||||
<string name="back_to_the_group">Back to the group</string>
|
||||
<string name="this_no_longer_applies">This no longer applies. The group has changed since you opened it.</string>
|
||||
<string name="why_this_is_unavailable">Why this is unavailable</string>
|
||||
<string name="unavailable">Unavailable</string>
|
||||
<string name="view_profile">View profile</string>
|
||||
</resources>
|
||||
+39
@@ -14,6 +14,9 @@ import mobi.giza.compose.managers.AdminGovernance
|
||||
import mobi.giza.compose.managers.GovernanceGate
|
||||
import mobi.giza.compose.managers.PromotionManager
|
||||
import mobi.giza.compose.managers.GovernanceFollowThrough
|
||||
import mobi.giza.compose.managers.MemberActionContext
|
||||
import mobi.giza.compose.managers.MemberActionPolicy
|
||||
import mobi.giza.compose.managers.MemberActionRoom
|
||||
import mobi.giza.compose.managers.MarmotInboundManager
|
||||
import mobi.giza.compose.managers.AdminFlags
|
||||
import mobi.giza.compose.managers.FoundingAdmins
|
||||
@@ -57,6 +60,7 @@ import mobi.giza.compose.identity.Identity
|
||||
import mobi.giza.compose.identity.toKeyPair
|
||||
import mobi.giza.compose.managers.ShareRefreshManager
|
||||
import mobi.giza.compose.ui.view.state.GovernanceStatus
|
||||
import mobi.giza.compose.ui.view.state.MemberActionOption
|
||||
import mobi.giza.compose.managers.RotationHold
|
||||
import mobi.giza.compose.ui.view.state.SharesSummary
|
||||
import mobi.giza.compose.ui.view.state.RotationPreview
|
||||
@@ -720,6 +724,41 @@ class DatabaseChatRepository(
|
||||
return GovernanceGate.minimumAdmins(group)?.let { GovernanceStatus.Governed(it) }
|
||||
}
|
||||
|
||||
override suspend fun memberActionOptions(localChatRoom: LocalChatRoom): Map<HexKey, List<MemberActionOption>> {
|
||||
val chatRoom = localChatRoom.chatRoom
|
||||
val me = chatRoom.userPublicKey
|
||||
val rows = localChatRoom.localParticipants.map { it.participant.participantPublicKey }
|
||||
val hasLeft = chatRoom.leftGroupAt != null
|
||||
// Off the current profile there is no admin policy to read: the room's kind
|
||||
// is the whole answer, and the participants' flags say which role to name.
|
||||
val flaggedAdmins = localChatRoom.localParticipants
|
||||
.filter { it.participant.adminAt != null }
|
||||
.map { it.participant.participantPublicKey }
|
||||
.toSet()
|
||||
val context = when {
|
||||
chatRoom.mlsGroupState == null ->
|
||||
MemberActionContext(MemberActionRoom.NIP17, me, admins = flaggedAdmins, members = emptySet(), hasLeft = hasLeft)
|
||||
chatRoom.marmotProfile() != MarmotProfile.CURRENT ->
|
||||
MemberActionContext(MemberActionRoom.LEGACY, me, admins = flaggedAdmins, members = emptySet(), hasLeft = hasLeft)
|
||||
else -> {
|
||||
// A row whose state this build cannot read has no rules to read either.
|
||||
val group = runCatching { chatRoom.toMlsGroup() }.getOrNull() ?: return emptyMap()
|
||||
val context = AdminGovernance.context(group, me, AdminGovernance.adminFloor(database, chatRoom.id, group))
|
||||
val engine = database.marmotEngine
|
||||
context.copy(
|
||||
hasLeft = hasLeft,
|
||||
// Work in flight, which clears by itself: the gate holding an earlier
|
||||
// commit until a relay accepts it, and offers nobody has answered.
|
||||
// docs/member-row-actions.md, Phase 5.
|
||||
changePending = engine.groupFor(localChatRoom.routingId) != null &&
|
||||
!engine.gate.canPrepareLocalCommit(localChatRoom.routingId),
|
||||
offeredAdmin = if (context.isKeyed) PromotionManager.unansweredOfferTargets(database, chatRoom.id) else emptySet(),
|
||||
)
|
||||
}
|
||||
}
|
||||
return MemberActionPolicy.options(context, rows)
|
||||
}
|
||||
|
||||
override suspend fun promoteMember(localChatRoom: LocalChatRoom, memberPublicKey: HexKey) {
|
||||
database.marmotOutboundDao().promote(localChatRoom, memberPublicKey)
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package mobi.giza.compose.managers
|
||||
|
||||
import com.vitorpamplona.marmot.groups.MarmotGroupPermissions
|
||||
import com.vitorpamplona.marmot.groups.currentAdminIdentities
|
||||
import com.vitorpamplona.marmot.groups.currentGroupState
|
||||
import com.vitorpamplona.mls.group.MlsGroup
|
||||
import com.vitorpamplona.mls.tree.Credential
|
||||
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
@@ -128,27 +129,34 @@ object AdminGovernance {
|
||||
}
|
||||
|
||||
/**
|
||||
* What [me] may do to each member of [group], for the member rows' menus. Empty
|
||||
* when [me] does not govern the room. Removal stays offered in a keyed room,
|
||||
* where it always was, unless it would take the room below [floor] admins
|
||||
* ([adminFloor]); promotion and demotion are not, for [isKeyedRoom]'s reason.
|
||||
* What [MemberActionPolicy] reads, from [group]'s state: its admins, its
|
||||
* members, whether it is keyed and needs the group's signature, and [floor].
|
||||
* What only the database knows -- having left, whose devices a keyed room
|
||||
* waits on, work in flight -- is the caller's to add.
|
||||
*/
|
||||
fun memberActions(group: MlsGroup, me: HexKey, floor: Int = 1): Map<HexKey, Set<MemberAction>> {
|
||||
if (!MarmotGroupPermissions.canManage(group.currentAdminIdentities(), me)) return emptyMap()
|
||||
return members(group).associateWith { member ->
|
||||
buildSet {
|
||||
if (member == me) {
|
||||
if (canDemote(group, me, me) || canAskToStepDown(group, me, floor)) add(MemberAction.STEP_DOWN)
|
||||
} else {
|
||||
if (canPromote(group, me, member)) add(MemberAction.MAKE_ADMIN)
|
||||
if (canDemote(group, me, member) && keepsFloor(group, member, floor)) add(MemberAction.REMOVE_AS_ADMIN)
|
||||
if (MarmotGroupPermissions.canRemove(group.currentAdminIdentities(), me, member) && keepsFloor(group, member, floor)) {
|
||||
add(MemberAction.REMOVE_FROM_GROUP)
|
||||
}
|
||||
}
|
||||
}
|
||||
}.filterValues { it.isNotEmpty() }
|
||||
}
|
||||
fun context(group: MlsGroup, me: HexKey, floor: Int = 1): MemberActionContext = MemberActionContext(
|
||||
room = MemberActionRoom.CURRENT,
|
||||
me = me,
|
||||
admins = group.currentAdminIdentities().toSet(),
|
||||
members = members(group),
|
||||
isDisbanded = group.currentGroupState().isDisbanded,
|
||||
isKeyed = isKeyedRoom(group),
|
||||
governed = GovernanceGate.isGoverned(group),
|
||||
shareRefresh = ExperimentalFeatures.shareRefresh,
|
||||
floor = floor,
|
||||
)
|
||||
|
||||
/**
|
||||
* What [me] may do now to each member of [group]: [MemberActionPolicy]'s
|
||||
* options that are open, and members with none left out. Empty when [me] does
|
||||
* not govern the room. Removal stays open in a keyed room, where it always was,
|
||||
* unless it would take the room below [floor] admins ([adminFloor]); promotion
|
||||
* and demotion are not, for [isKeyedRoom]'s reason.
|
||||
*/
|
||||
fun memberActions(group: MlsGroup, me: HexKey, floor: Int = 1): Map<HexKey, Set<MemberAction>> =
|
||||
MemberActionPolicy.options(context(group, me, floor), members(group))
|
||||
.mapValues { (_, options) -> options.filter { it.isAvailable }.map { it.action }.toSet() }
|
||||
.filterValues { it.isNotEmpty() }
|
||||
|
||||
/** How **Leave group** goes for [me] in [group]: null when [me] is not an admin. */
|
||||
fun adminLeave(group: MlsGroup, me: HexKey): AdminLeave? = when {
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
package mobi.giza.compose.managers
|
||||
|
||||
import com.vitorpamplona.marmot.groups.MarmotGroupPermissions
|
||||
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
import mobi.giza.compose.ui.view.state.MemberAction
|
||||
import mobi.giza.compose.ui.view.state.MemberActionBlocker
|
||||
import mobi.giza.compose.ui.view.state.MemberActionOption
|
||||
|
||||
/**
|
||||
* What kind of room a member row is in, as far as its admins go.
|
||||
*/
|
||||
enum class MemberActionRoom {
|
||||
/** A robust group's NIP-17 room, which has no admins of its own. */
|
||||
NIP17,
|
||||
|
||||
/** A Marmot room on the legacy profile, which the app does not govern. */
|
||||
LEGACY,
|
||||
|
||||
/** A Marmot room on the current profile, whose admin policy is the group's state. */
|
||||
CURRENT,
|
||||
}
|
||||
|
||||
/**
|
||||
* Everything [MemberActionPolicy] reads, as plain values, so every reason can be
|
||||
* decided -- and tested -- without an MLS group. [AdminGovernance.context] builds
|
||||
* one from a group; `ChatRepository.memberActionOptions` adds what only the
|
||||
* database knows.
|
||||
*/
|
||||
data class MemberActionContext(
|
||||
val room: MemberActionRoom,
|
||||
val me: HexKey,
|
||||
/** The group's admins; off the current profile, the participants' `adminAt`. */
|
||||
val admins: Set<HexKey>,
|
||||
/** Who holds a leaf now; empty off the current profile. */
|
||||
val members: Set<HexKey>,
|
||||
val isDisbanded: Boolean = false,
|
||||
val hasLeft: Boolean = false,
|
||||
val isKeyed: Boolean = false,
|
||||
/** Whether a keyed room's changes need the group's signature; one made before that never will. */
|
||||
val governed: Boolean = false,
|
||||
/** `ExperimentalFeatures.shareRefresh`, without which a keyed room's admins cannot change. */
|
||||
val shareRefresh: Boolean = false,
|
||||
/** [AdminGovernance.adminFloor]: the fewest admins the room may be left with. */
|
||||
val floor: Int = 1,
|
||||
/** An earlier change is still waiting for a relay; docs/member-row-actions.md, Phase 5. */
|
||||
val changePending: Boolean = false,
|
||||
/** Members this account has offered admin and who have not answered. */
|
||||
val offeredAdmin: Set<HexKey> = emptySet(),
|
||||
)
|
||||
|
||||
/**
|
||||
* What a member row's menu offers, and why each item is or is not open. The rules
|
||||
* are [MarmotGroupPermissions]', which every peer enforces on a commit, and
|
||||
* [AdminGovernance]'s two additions to them -- the keyed room and the floor -- so
|
||||
* the menu, the explanation screen and the commit cannot disagree.
|
||||
* [AdminGovernance.memberActions] is this, filtered to what is open.
|
||||
* docs/member-row-actions.md, D2 and D4.
|
||||
*/
|
||||
object MemberActionPolicy {
|
||||
|
||||
/**
|
||||
* The options for each of [rows]. Every other member gets the action that fits
|
||||
* their role -- **Make admin** or **Remove as admin** -- and **Remove from
|
||||
* group**, open or not. [MemberActionContext.me] gets **Step down as admin**
|
||||
* only, and only when it is open: the viewer's own row lists nothing it cannot
|
||||
* do (D1).
|
||||
*/
|
||||
fun options(context: MemberActionContext, rows: Collection<HexKey>): Map<HexKey, List<MemberActionOption>> =
|
||||
rows.distinct().mapNotNull { member ->
|
||||
if (member == context.me) {
|
||||
stepDown(context)?.let { member to listOf(it) }
|
||||
} else {
|
||||
member to forMember(context, member)
|
||||
}
|
||||
}.toMap()
|
||||
|
||||
private fun stepDown(context: MemberActionContext): MemberActionOption? {
|
||||
val me = context.me
|
||||
val open = context.room == MemberActionRoom.CURRENT &&
|
||||
!context.isDisbanded &&
|
||||
!context.hasLeft &&
|
||||
if (context.isKeyed) {
|
||||
// [AdminGovernance.canAskToStepDown]: a request another admin's device
|
||||
// proposes, because a rotation's proposer has to keep a share. So the
|
||||
// room's rules, the floor, and another admin with a leaf to ask.
|
||||
context.governed && context.shareRefresh &&
|
||||
me in context.admins &&
|
||||
keepsFloor(context, me) &&
|
||||
context.admins.any { it != me && it in context.members }
|
||||
} else {
|
||||
MarmotGroupPermissions.canDemote(context.admins, context.members, me, me)
|
||||
}
|
||||
return if (open) MemberActionOption(MemberAction.STEP_DOWN) else null
|
||||
}
|
||||
|
||||
private fun forMember(context: MemberActionContext, member: HexKey): List<MemberActionOption> {
|
||||
val isAdmin = member in context.admins
|
||||
val roleAction = if (isAdmin) MemberAction.REMOVE_AS_ADMIN else MemberAction.MAKE_ADMIN
|
||||
val room = roomBlockers(context)
|
||||
// Off the current profile the room is the whole answer: there are no rules to read.
|
||||
if (context.room != MemberActionRoom.CURRENT) {
|
||||
return listOf(MemberActionOption(roleAction, room), MemberActionOption(MemberAction.REMOVE_FROM_GROUP, room))
|
||||
}
|
||||
|
||||
val actor = listOfNotNull(
|
||||
MemberActionBlocker.NotAnAdmin(context.admins).takeUnless { MarmotGroupPermissions.canManage(context.admins, context.me) },
|
||||
)
|
||||
val keyed = if (context.isKeyed) {
|
||||
listOfNotNull(
|
||||
MemberActionBlocker.SignaturesNotRequired.takeUnless { context.governed },
|
||||
MemberActionBlocker.ShareRotationUnavailable.takeUnless { context.shareRefresh },
|
||||
)
|
||||
} else {
|
||||
emptyList()
|
||||
}
|
||||
val inGroup = member in context.members
|
||||
// The only admin is the floor of one said plainly; a higher floor names its number.
|
||||
val floor = when {
|
||||
isAdmin && context.admins.none { it != member && it in context.members } -> MemberActionBlocker.OnlyAdmin
|
||||
!keepsFloor(context, member) -> MemberActionBlocker.BelowFloor(context.floor)
|
||||
else -> null
|
||||
}
|
||||
val pending = listOfNotNull(MemberActionBlocker.ChangePending.takeIf { context.changePending })
|
||||
|
||||
val role = if (isAdmin) {
|
||||
room + actor + keyed + listOfNotNull(floor) + pending
|
||||
} else {
|
||||
room + actor + keyed + listOfNotNull(
|
||||
MemberActionBlocker.NotInGroupYet.takeUnless { inGroup },
|
||||
) + pending + listOfNotNull(
|
||||
MemberActionBlocker.OfferPending.takeIf { member in context.offeredAdmin },
|
||||
)
|
||||
}
|
||||
val removal = room + actor + listOfNotNull(
|
||||
MemberActionBlocker.NotInGroupYet.takeUnless { inGroup },
|
||||
floor,
|
||||
) + pending
|
||||
|
||||
return listOf(MemberActionOption(roleAction, role), MemberActionOption(MemberAction.REMOVE_FROM_GROUP, removal))
|
||||
}
|
||||
|
||||
private fun roomBlockers(context: MemberActionContext): List<MemberActionBlocker> = listOfNotNull(
|
||||
MemberActionBlocker.NoAdminsInThisRoom.takeIf { context.room == MemberActionRoom.NIP17 },
|
||||
MemberActionBlocker.LegacyRoom.takeIf { context.room == MemberActionRoom.LEGACY },
|
||||
MemberActionBlocker.Disbanded.takeIf { context.isDisbanded },
|
||||
MemberActionBlocker.YouLeft.takeIf { context.hasLeft },
|
||||
)
|
||||
|
||||
/** [AdminGovernance.keepsFloor], over the context's sets. */
|
||||
private fun keepsFloor(context: MemberActionContext, target: HexKey): Boolean {
|
||||
val activeAdmins = context.admins intersect context.members
|
||||
return target !in activeAdmins || activeAdmins.size - 1 >= context.floor
|
||||
}
|
||||
}
|
||||
@@ -149,6 +149,23 @@ object PromotionManager {
|
||||
return Offer(offer.id, offer.publicKey)
|
||||
}
|
||||
|
||||
/**
|
||||
* Who in [chatRoomId] has been offered admin, by anyone, and has not answered:
|
||||
* a second offer would only ask them twice. docs/member-row-actions.md, Phase 5.
|
||||
*/
|
||||
suspend fun unansweredOfferTargets(database: GizaDatabase, chatRoomId: String): Set<HexKey> {
|
||||
val events = database.marmotInnerEventDao().getByChatRoomAndKinds(chatRoomId, listOf(PromotionEvents.OFFER, PromotionEvents.ACCEPT))
|
||||
val answered = events.filter { it.kind == PromotionEvents.ACCEPT }
|
||||
.mapNotNull { accept -> PromotionEvents.value(accept.tags, PromotionEvents.OFFER_TAG)?.let { it to accept.publicKey } }
|
||||
.toSet()
|
||||
return events.filter { it.kind == PromotionEvents.OFFER }
|
||||
.mapNotNull { offer ->
|
||||
val target = PromotionEvents.value(offer.tags, PromotionEvents.TARGET_TAG) ?: return@mapNotNull null
|
||||
target.takeIf { (offer.id to target) !in answered }
|
||||
}
|
||||
.toSet()
|
||||
}
|
||||
|
||||
// ---- 2. the acceptance ---------------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,7 +24,9 @@ import mobi.giza.compose.managers.MarmotGroupCreation
|
||||
import mobi.giza.compose.managers.SubgroupManager
|
||||
import mobi.giza.compose.nostr.MarmotProfile
|
||||
import mobi.giza.compose.managers.PromotionManager
|
||||
import mobi.giza.compose.managers.MemberActionPolicy
|
||||
import mobi.giza.compose.ui.view.state.GovernanceStatus
|
||||
import mobi.giza.compose.ui.view.state.MemberActionOption
|
||||
import mobi.giza.compose.ui.view.state.SharesSummary
|
||||
import mobi.giza.compose.ui.view.state.RotationPreview
|
||||
|
||||
@@ -318,6 +320,16 @@ interface ChatRepository {
|
||||
*/
|
||||
suspend fun governanceStatus(chatRoomId: String): GovernanceStatus?
|
||||
|
||||
/**
|
||||
* What each member row of [localChatRoom] offers, and why an item is not open:
|
||||
* [MemberActionPolicy] over the room's state and what only the database knows.
|
||||
* Every room and every viewer gets an answer -- a member who is not an admin is
|
||||
* told why, not shown nothing. The detail screen and the screen that explains a
|
||||
* closed action both read it here, so they cannot disagree.
|
||||
* docs/member-row-actions.md, Phase 2.
|
||||
*/
|
||||
suspend fun memberActionOptions(localChatRoom: LocalChatRoom): Map<HexKey, List<MemberActionOption>>
|
||||
|
||||
|
||||
/**
|
||||
* Removes [memberPublicKey] from a current-profile room this device administers:
|
||||
@@ -624,6 +636,7 @@ interface ChatRepository {
|
||||
|
||||
override suspend fun governanceStatus(chatRoomId: String): GovernanceStatus? = null
|
||||
|
||||
override suspend fun memberActionOptions(localChatRoom: LocalChatRoom): Map<HexKey, List<MemberActionOption>> = emptyMap()
|
||||
|
||||
override suspend fun promoteMember(localChatRoom: LocalChatRoom, memberPublicKey: HexKey) = Unit
|
||||
|
||||
|
||||
+45
-17
@@ -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)
|
||||
@@ -1073,15 +1078,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 = {
|
||||
@@ -1092,14 +1104,29 @@ fun ChatRoomDetailScreen(
|
||||
},
|
||||
trailingContent = {
|
||||
val memberPublicKey = localParticipant.participant.participantPublicKey
|
||||
val actions = chatRoomDetailUIState.memberActions[memberPublicKey].orEmpty()
|
||||
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,
|
||||
@@ -1121,9 +1148,10 @@ fun ChatRoomDetailScreen(
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// This device's own row, with nothing open on it.
|
||||
Icon(
|
||||
Icons.Default.ChevronRight,
|
||||
contentDescription = "View profile"
|
||||
contentDescription = viewProfile
|
||||
)
|
||||
}
|
||||
},
|
||||
|
||||
+313
@@ -0,0 +1,313 @@
|
||||
package mobi.giza.compose.ui.composable
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.AdminPanelSettings
|
||||
import androidx.compose.material.icons.filled.CheckCircle
|
||||
import androidx.compose.material.icons.filled.Groups
|
||||
import androidx.compose.material.icons.filled.Info
|
||||
import androidx.compose.material.icons.filled.Key
|
||||
import androidx.compose.material.icons.filled.Lock
|
||||
import androidx.compose.material.icons.filled.Person
|
||||
import androidx.compose.material.icons.filled.Schedule
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.SnackbarHost
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
import mobi.giza.compose.resources.Res
|
||||
import mobi.giza.compose.resources.also_in_the_way
|
||||
import mobi.giza.compose.resources.back_to_the_group
|
||||
import mobi.giza.compose.resources.make_admin
|
||||
import mobi.giza.compose.resources.member_action_below_floor_body
|
||||
import mobi.giza.compose.resources.member_action_below_floor_title
|
||||
import mobi.giza.compose.resources.member_action_change_pending_body
|
||||
import mobi.giza.compose.resources.member_action_change_pending_title
|
||||
import mobi.giza.compose.resources.member_action_disbanded_body
|
||||
import mobi.giza.compose.resources.member_action_disbanded_title
|
||||
import mobi.giza.compose.resources.member_action_legacy_body
|
||||
import mobi.giza.compose.resources.member_action_legacy_title
|
||||
import mobi.giza.compose.resources.member_action_no_admins_body
|
||||
import mobi.giza.compose.resources.member_action_no_admins_title
|
||||
import mobi.giza.compose.resources.member_action_not_an_admin_body
|
||||
import mobi.giza.compose.resources.member_action_not_an_admin_title
|
||||
import mobi.giza.compose.resources.member_action_not_in_group_body
|
||||
import mobi.giza.compose.resources.member_action_not_in_group_title
|
||||
import mobi.giza.compose.resources.member_action_offer_pending_body
|
||||
import mobi.giza.compose.resources.member_action_offer_pending_title
|
||||
import mobi.giza.compose.resources.member_action_only_admin_body
|
||||
import mobi.giza.compose.resources.member_action_only_admin_title
|
||||
import mobi.giza.compose.resources.member_action_share_rotation_body
|
||||
import mobi.giza.compose.resources.member_action_share_rotation_title
|
||||
import mobi.giza.compose.resources.member_action_signatures_body
|
||||
import mobi.giza.compose.resources.member_action_signatures_title
|
||||
import mobi.giza.compose.resources.member_action_you_left_body
|
||||
import mobi.giza.compose.resources.member_action_you_left_title
|
||||
import mobi.giza.compose.resources.open_the_admin_room
|
||||
import mobi.giza.compose.resources.remove_as_admin
|
||||
import mobi.giza.compose.resources.remove_from_group
|
||||
import mobi.giza.compose.resources.step_down_as_admin
|
||||
import mobi.giza.compose.resources.this_no_longer_applies
|
||||
import mobi.giza.compose.resources.you_can_do_this_now
|
||||
import mobi.giza.compose.resources.you_can_do_this_now_body
|
||||
import mobi.giza.compose.repository.ChatRepository
|
||||
import mobi.giza.compose.repository.NostrRepository
|
||||
import mobi.giza.compose.ui.composable.navigation.routes.ChatRoomDetailRoute
|
||||
import mobi.giza.compose.ui.composable.navigation.routes.Route
|
||||
import mobi.giza.compose.ui.composable.widgets.Decorative
|
||||
import mobi.giza.compose.ui.composable.widgets.EmptyState
|
||||
import mobi.giza.compose.ui.composable.widgets.ErrorState
|
||||
import mobi.giza.compose.ui.composable.widgets.LoadingDataIndicator
|
||||
import mobi.giza.compose.ui.composable.widgets.LocalSnackbarHostState
|
||||
import mobi.giza.compose.ui.composable.widgets.NavigateBackButton
|
||||
import mobi.giza.compose.ui.composable.widgets.ScreenStateTransition
|
||||
import mobi.giza.compose.ui.theme.readableContent
|
||||
import mobi.giza.compose.ui.theme.spacing
|
||||
import mobi.giza.compose.ui.view.model.MemberActionUnavailableViewModel
|
||||
import mobi.giza.compose.ui.view.state.MemberAction
|
||||
import mobi.giza.compose.ui.view.state.MemberActionBlocker
|
||||
import mobi.giza.compose.ui.view.state.MemberActionUnavailableUIState
|
||||
import org.jetbrains.compose.resources.StringResource
|
||||
import org.jetbrains.compose.resources.stringResource
|
||||
|
||||
/**
|
||||
* Why a member row's action cannot be taken now, and what would change that.
|
||||
*
|
||||
* Pushed from the row's menu when the item chosen is not open. It leads with the
|
||||
* first thing in the way -- the room before the viewer, the viewer before the
|
||||
* member -- and lists anything else under it, so a member of a disbanded group
|
||||
* hears that the group is gone before hearing they are not an admin. At most one
|
||||
* action, where there is one that helps; never the action itself, whose
|
||||
* confirmation and wording live on the group's page. See
|
||||
* docs/member-row-actions.md, D5 and D6.
|
||||
*/
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun MemberActionUnavailableScreen(
|
||||
activeUserPublicKey: HexKey,
|
||||
chatRoomId: String,
|
||||
memberPublicKey: HexKey,
|
||||
/** Null for a route naming an action this build does not know: it no longer applies. */
|
||||
action: MemberAction?,
|
||||
initialUIState: MemberActionUnavailableUIState = MemberActionUnavailableUIState.Loading,
|
||||
nostrRepository: NostrRepository,
|
||||
chatRepository: ChatRepository,
|
||||
onNavigateToRoute: (Route) -> Unit,
|
||||
onNavigateBack: () -> Unit,
|
||||
) {
|
||||
val viewModel: MemberActionUnavailableViewModel = viewModel(
|
||||
factory = MemberActionUnavailableViewModel.factory(
|
||||
activeUserPublicKey = activeUserPublicKey,
|
||||
chatRoomId = chatRoomId,
|
||||
memberPublicKey = memberPublicKey,
|
||||
action = action,
|
||||
initialUIState = initialUIState,
|
||||
nostrRepository = nostrRepository,
|
||||
chatRepository = chatRepository,
|
||||
),
|
||||
)
|
||||
|
||||
Scaffold(
|
||||
snackbarHost = { SnackbarHost(LocalSnackbarHostState.current) },
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = { action?.let { Text(stringResource(it.label())) } },
|
||||
navigationIcon = { NavigateBackButton(onNavigateBack) },
|
||||
)
|
||||
},
|
||||
) { innerPadding ->
|
||||
// The bar is constant, so the transition wraps the content alone, and none of
|
||||
// the branches needs a scope the transition would take away.
|
||||
ScreenStateTransition(viewModel.uiState) { uiState ->
|
||||
when (val state = uiState) {
|
||||
MemberActionUnavailableUIState.Loading -> LoadingDataIndicator(
|
||||
modifier = Modifier.padding(innerPadding).readableContent().fillMaxWidth(),
|
||||
)
|
||||
|
||||
MemberActionUnavailableUIState.Error -> ErrorState(
|
||||
modifier = Modifier.padding(innerPadding).readableContent(),
|
||||
onRetry = { viewModel.reload() },
|
||||
)
|
||||
|
||||
MemberActionUnavailableUIState.NoLongerApplies -> EmptyState(
|
||||
modifier = Modifier.padding(innerPadding).readableContent(),
|
||||
message = stringResource(Res.string.this_no_longer_applies),
|
||||
icon = Icons.Default.Info,
|
||||
action = {
|
||||
TextButton(onClick = onNavigateBack) { Text(stringResource(Res.string.back_to_the_group)) }
|
||||
},
|
||||
)
|
||||
|
||||
is MemberActionUnavailableUIState.Blocked -> Column(
|
||||
modifier = Modifier.padding(innerPadding).readableContent().fillMaxSize()
|
||||
.verticalScroll(rememberScrollState())
|
||||
.padding(MaterialTheme.spacing.screenMargin),
|
||||
verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.sectionGap),
|
||||
) {
|
||||
val lead = state.blockers.first()
|
||||
Blocker(
|
||||
blocker = lead,
|
||||
memberName = state.memberName,
|
||||
names = state.names,
|
||||
titleStyle = MaterialTheme.typography.headlineSmall,
|
||||
)
|
||||
|
||||
// The one reason with something to do about it from here.
|
||||
if (lead == MemberActionBlocker.NoAdminsInThisRoom && state.adminRoomId != null) {
|
||||
Button(
|
||||
onClick = {
|
||||
onNavigateToRoute(
|
||||
ChatRoomDetailRoute(
|
||||
activeUserPublicKey = activeUserPublicKey,
|
||||
chatRoomId = state.adminRoomId,
|
||||
relayHint = null,
|
||||
)
|
||||
)
|
||||
},
|
||||
) {
|
||||
Text(stringResource(Res.string.open_the_admin_room))
|
||||
}
|
||||
}
|
||||
|
||||
val rest = state.blockers.drop(1)
|
||||
if (rest.isNotEmpty()) {
|
||||
Column(verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.itemGap)) {
|
||||
Text(
|
||||
text = stringResource(Res.string.also_in_the_way),
|
||||
style = MaterialTheme.typography.titleSmall,
|
||||
)
|
||||
rest.forEach { blocker ->
|
||||
Blocker(
|
||||
blocker = blocker,
|
||||
memberName = state.memberName,
|
||||
names = state.names,
|
||||
titleStyle = MaterialTheme.typography.titleMedium,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is MemberActionUnavailableUIState.NowAvailable -> Column(
|
||||
modifier = Modifier.padding(innerPadding).readableContent().fillMaxSize()
|
||||
.padding(MaterialTheme.spacing.screenMargin),
|
||||
verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.sectionGap),
|
||||
) {
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.relatedGap)) {
|
||||
Icon(Icons.Default.CheckCircle, contentDescription = Decorative, tint = MaterialTheme.colorScheme.primary)
|
||||
Text(
|
||||
text = stringResource(Res.string.you_can_do_this_now),
|
||||
style = MaterialTheme.typography.headlineSmall,
|
||||
)
|
||||
}
|
||||
Text(
|
||||
text = stringResource(Res.string.you_can_do_this_now_body),
|
||||
style = MaterialTheme.typography.bodyLarge,
|
||||
)
|
||||
Button(onClick = onNavigateBack) { Text(stringResource(Res.string.back_to_the_group)) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LaunchedEffect(true) {
|
||||
if (initialUIState == MemberActionUnavailableUIState.Loading) viewModel.initiate()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* One thing in the way: what it is, and what would change it. The icon names the
|
||||
* kind of reason -- the room, the viewer, the room's rules, the member, work in
|
||||
* flight -- and the title beside it says the same, so it is decorative.
|
||||
*/
|
||||
@Composable
|
||||
private fun Blocker(
|
||||
blocker: MemberActionBlocker,
|
||||
memberName: String,
|
||||
names: Map<HexKey, String>,
|
||||
titleStyle: TextStyle,
|
||||
) {
|
||||
Column(verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.relatedGap)) {
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.relatedGap)) {
|
||||
Icon(blocker.icon(), contentDescription = Decorative, tint = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
Text(text = blocker.title(memberName), style = titleStyle)
|
||||
}
|
||||
Text(text = blocker.body(names), style = MaterialTheme.typography.bodyLarge)
|
||||
}
|
||||
}
|
||||
|
||||
private fun Set<HexKey>.namedBy(names: Map<HexKey, String>): String =
|
||||
map { names[it] ?: it.take(12) }.sorted().joinToString(", ")
|
||||
|
||||
private fun MemberActionBlocker.icon(): ImageVector = when (this) {
|
||||
MemberActionBlocker.NoAdminsInThisRoom,
|
||||
MemberActionBlocker.LegacyRoom,
|
||||
MemberActionBlocker.Disbanded,
|
||||
MemberActionBlocker.YouLeft -> Icons.Default.Groups
|
||||
is MemberActionBlocker.NotAnAdmin -> Icons.Default.Lock
|
||||
MemberActionBlocker.SignaturesNotRequired,
|
||||
MemberActionBlocker.ShareRotationUnavailable -> Icons.Default.Key
|
||||
MemberActionBlocker.NotInGroupYet -> Icons.Default.Person
|
||||
MemberActionBlocker.OnlyAdmin,
|
||||
is MemberActionBlocker.BelowFloor -> Icons.Default.AdminPanelSettings
|
||||
MemberActionBlocker.ChangePending,
|
||||
MemberActionBlocker.OfferPending -> Icons.Default.Schedule
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun MemberActionBlocker.title(memberName: String): String = when (this) {
|
||||
MemberActionBlocker.NoAdminsInThisRoom -> stringResource(Res.string.member_action_no_admins_title)
|
||||
MemberActionBlocker.LegacyRoom -> stringResource(Res.string.member_action_legacy_title)
|
||||
MemberActionBlocker.Disbanded -> stringResource(Res.string.member_action_disbanded_title)
|
||||
MemberActionBlocker.YouLeft -> stringResource(Res.string.member_action_you_left_title)
|
||||
is MemberActionBlocker.NotAnAdmin -> stringResource(Res.string.member_action_not_an_admin_title)
|
||||
MemberActionBlocker.SignaturesNotRequired -> stringResource(Res.string.member_action_signatures_title)
|
||||
MemberActionBlocker.ShareRotationUnavailable -> stringResource(Res.string.member_action_share_rotation_title)
|
||||
MemberActionBlocker.NotInGroupYet -> stringResource(Res.string.member_action_not_in_group_title, memberName)
|
||||
MemberActionBlocker.OnlyAdmin -> stringResource(Res.string.member_action_only_admin_title, memberName)
|
||||
is MemberActionBlocker.BelowFloor -> stringResource(Res.string.member_action_below_floor_title, floor.toString())
|
||||
MemberActionBlocker.ChangePending -> stringResource(Res.string.member_action_change_pending_title)
|
||||
MemberActionBlocker.OfferPending -> stringResource(Res.string.member_action_offer_pending_title, memberName)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun MemberActionBlocker.body(names: Map<HexKey, String>): String = when (this) {
|
||||
MemberActionBlocker.NoAdminsInThisRoom -> stringResource(Res.string.member_action_no_admins_body)
|
||||
MemberActionBlocker.LegacyRoom -> stringResource(Res.string.member_action_legacy_body)
|
||||
MemberActionBlocker.Disbanded -> stringResource(Res.string.member_action_disbanded_body)
|
||||
MemberActionBlocker.YouLeft -> stringResource(Res.string.member_action_you_left_body)
|
||||
is MemberActionBlocker.NotAnAdmin -> stringResource(Res.string.member_action_not_an_admin_body, admins.namedBy(names))
|
||||
MemberActionBlocker.SignaturesNotRequired -> stringResource(Res.string.member_action_signatures_body)
|
||||
MemberActionBlocker.ShareRotationUnavailable -> stringResource(Res.string.member_action_share_rotation_body)
|
||||
MemberActionBlocker.NotInGroupYet -> stringResource(Res.string.member_action_not_in_group_body)
|
||||
MemberActionBlocker.OnlyAdmin -> stringResource(Res.string.member_action_only_admin_body)
|
||||
is MemberActionBlocker.BelowFloor -> stringResource(Res.string.member_action_below_floor_body)
|
||||
MemberActionBlocker.ChangePending -> stringResource(Res.string.member_action_change_pending_body)
|
||||
MemberActionBlocker.OfferPending -> stringResource(Res.string.member_action_offer_pending_body)
|
||||
}
|
||||
|
||||
/** The menu's word for [this], which is also this screen's title. */
|
||||
internal fun MemberAction.label(): StringResource = when (this) {
|
||||
MemberAction.MAKE_ADMIN -> Res.string.make_admin
|
||||
MemberAction.REMOVE_AS_ADMIN -> Res.string.remove_as_admin
|
||||
MemberAction.STEP_DOWN -> Res.string.step_down_as_admin
|
||||
MemberAction.REMOVE_FROM_GROUP -> Res.string.remove_from_group
|
||||
}
|
||||
+32
-17
@@ -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
|
||||
@@ -47,44 +51,62 @@ import mobi.giza.compose.resources.leave_as_admin_title
|
||||
import mobi.giza.compose.resources.remove_as_admin
|
||||
import mobi.giza.compose.resources.remove_as_admin_body
|
||||
import mobi.giza.compose.resources.remove_as_admin_title
|
||||
import mobi.giza.compose.resources.remove_from_group
|
||||
import mobi.giza.compose.resources.step_down
|
||||
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_as_admin
|
||||
import mobi.giza.compose.resources.step_down_body
|
||||
import mobi.giza.compose.resources.step_down_body_keyed
|
||||
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)
|
||||
},
|
||||
)
|
||||
}
|
||||
@@ -92,13 +114,6 @@ internal fun MemberActionsMenu(
|
||||
}
|
||||
}
|
||||
|
||||
private fun MemberAction.label() = when (this) {
|
||||
MemberAction.MAKE_ADMIN -> Res.string.make_admin
|
||||
MemberAction.REMOVE_AS_ADMIN -> Res.string.remove_as_admin
|
||||
MemberAction.STEP_DOWN -> Res.string.step_down_as_admin
|
||||
MemberAction.REMOVE_FROM_GROUP -> Res.string.remove_from_group
|
||||
}
|
||||
|
||||
/**
|
||||
* Asks before a change to who administers the room. Promotion says what it gives
|
||||
* away -- the power to remove the person granting it, and to disband the group --
|
||||
|
||||
+18
@@ -76,6 +76,8 @@ import mobi.giza.compose.ui.composable.navigation.routes.CreateSharedKeyRoute
|
||||
import mobi.giza.compose.ui.composable.navigation.routes.DkgRitualRoute
|
||||
import mobi.giza.compose.ui.composable.navigation.routes.HomeRoute
|
||||
import mobi.giza.compose.ui.composable.navigation.routes.ImplementationPendingRoute
|
||||
import mobi.giza.compose.ui.composable.navigation.routes.MemberActionUnavailableRoute
|
||||
import mobi.giza.compose.ui.composable.MemberActionUnavailableScreen
|
||||
import mobi.giza.compose.ui.composable.navigation.routes.KeyPackageManagementRoute
|
||||
import mobi.giza.compose.ui.composable.navigation.routes.KeyRecoveryRoute
|
||||
import mobi.giza.compose.ui.composable.navigation.routes.LandingRoute
|
||||
@@ -1206,6 +1208,22 @@ fun GizaNavHost(
|
||||
},
|
||||
)
|
||||
}
|
||||
composable<MemberActionUnavailableRoute> { backStackEntry ->
|
||||
val route = backStackEntry.toRoute<MemberActionUnavailableRoute>()
|
||||
|
||||
MemberActionUnavailableScreen(
|
||||
activeUserPublicKey = route.activeUserPublicKey,
|
||||
chatRoomId = route.chatRoomId,
|
||||
memberPublicKey = route.memberPublicKey,
|
||||
action = route.memberAction,
|
||||
nostrRepository = databaseNostrRepository,
|
||||
chatRepository = databaseChatRepository,
|
||||
onNavigateToRoute = { actionRoute -> navController.navigate(route = actionRoute) },
|
||||
onNavigateBack = {
|
||||
navController.popBackStack()
|
||||
},
|
||||
)
|
||||
}
|
||||
composable<ImplementationPendingRoute> { backStackEntry ->
|
||||
val route: ImplementationPendingRoute = backStackEntry.toRoute()
|
||||
|
||||
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package mobi.giza.compose.ui.composable.navigation.routes
|
||||
|
||||
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
import kotlinx.serialization.Serializable
|
||||
import mobi.giza.compose.ui.view.state.MemberAction
|
||||
|
||||
/**
|
||||
* Why [memberAction] on [memberPublicKey] is not open in [chatRoomId] now. Carries
|
||||
* what was asked, not the answer: the screen works the reasons out again, so they
|
||||
* cannot be stale and cannot be anything but the rules'. See
|
||||
* docs/member-row-actions.md, D5.
|
||||
*
|
||||
* The action travels by its name: the multiplatform navigation-compose has no
|
||||
* `NavType` for an enum, and a route whose argument it cannot type fails the
|
||||
* moment it is navigated to. A name no build knows reads as null, which the
|
||||
* screen says no longer applies.
|
||||
*/
|
||||
@Serializable
|
||||
data class MemberActionUnavailableRoute(
|
||||
val activeUserPublicKey: String,
|
||||
val chatRoomId: String,
|
||||
val memberPublicKey: HexKey,
|
||||
val action: String,
|
||||
) : Route() {
|
||||
constructor(activeUserPublicKey: String, chatRoomId: String, memberPublicKey: HexKey, action: MemberAction) :
|
||||
this(activeUserPublicKey, chatRoomId, memberPublicKey, action.name)
|
||||
|
||||
val memberAction: MemberAction? get() = MemberAction.entries.firstOrNull { it.name == action }
|
||||
}
|
||||
+5
-1
@@ -150,7 +150,11 @@ class ChatRoomDetailViewModel(
|
||||
} else {
|
||||
emptySet()
|
||||
},
|
||||
memberActions = group?.takeIf { canGovern }?.let { AdminGovernance.memberActions(it, me, chatRepository.adminFloor(chatRoomId)) }.orEmpty(),
|
||||
// For every viewer, not only an admin: what cannot be done says why.
|
||||
// docs/member-row-actions.md, Phase 2.
|
||||
memberActions = runCatching { chatRepository.memberActionOptions(localChatRoom) }
|
||||
.onFailure { if (it is CancellationException) throw it else logger.w(throwable = it) { "Couldn't read $chatRoomId's member actions" } }
|
||||
.getOrElse { emptyMap() },
|
||||
adminLeave = group?.takeIf { roomIsOpen }?.let { AdminGovernance.adminLeave(it, me) },
|
||||
governance = runCatching { chatRepository.governanceStatus(chatRoomId) }
|
||||
.onFailure { if (it is CancellationException) throw it }
|
||||
|
||||
+141
@@ -0,0 +1,141 @@
|
||||
package mobi.giza.compose.ui.view.model
|
||||
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import androidx.lifecycle.viewmodel.initializer
|
||||
import androidx.lifecycle.viewmodel.viewModelFactory
|
||||
import co.touchlab.kermit.Logger
|
||||
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
import kotlinx.coroutines.CancellationException
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.FlowPreview
|
||||
import kotlinx.coroutines.IO
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.debounce
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.merge
|
||||
import kotlinx.coroutines.launch
|
||||
import mobi.giza.compose.repository.ChatRepository
|
||||
import mobi.giza.compose.repository.NostrRepository
|
||||
import mobi.giza.compose.ui.view.state.MemberAction
|
||||
import mobi.giza.compose.ui.view.state.MemberActionBlocker
|
||||
import mobi.giza.compose.ui.view.state.MemberActionUnavailableUIState
|
||||
|
||||
/**
|
||||
* Works out why [action] on [memberPublicKey] is not open, through the same
|
||||
* `ChatRepository.memberActionOptions` the member row read, and keeps working it
|
||||
* out while the screen is open: a change landing, a device catching up or a
|
||||
* rotation finishing can each clear a reason, and the screen should not go on
|
||||
* explaining one that is gone. docs/member-row-actions.md, D5 and Phase 4.
|
||||
*/
|
||||
class MemberActionUnavailableViewModel(
|
||||
val activeUserPublicKey: HexKey,
|
||||
val chatRoomId: String,
|
||||
val memberPublicKey: HexKey,
|
||||
val action: MemberAction?,
|
||||
initialUIState: MemberActionUnavailableUIState,
|
||||
private val nostrRepository: NostrRepository,
|
||||
private val chatRepository: ChatRepository,
|
||||
) : ViewModel() {
|
||||
|
||||
var uiState: MemberActionUnavailableUIState by mutableStateOf(initialUIState)
|
||||
private set
|
||||
|
||||
private val logger = Logger.withTag(TAG)
|
||||
|
||||
private var observer: Job? = null
|
||||
|
||||
/** Once; a recomposition that calls this again must not open a second collect. */
|
||||
fun initiate() {
|
||||
reload()
|
||||
observe()
|
||||
}
|
||||
|
||||
fun reload() {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
uiState = runCatching { load() }
|
||||
.onFailure { if (it is CancellationException) throw it else logger.w(throwable = it) { "Couldn't explain $action in $chatRoomId" } }
|
||||
.getOrElse { MemberActionUnavailableUIState.Error }
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun load(): MemberActionUnavailableUIState {
|
||||
val action = action ?: return MemberActionUnavailableUIState.NoLongerApplies
|
||||
val localChatRoom = chatRepository.getChatRoomByIdentifier(chatRoomId)
|
||||
?: return MemberActionUnavailableUIState.NoLongerApplies
|
||||
val option = chatRepository.memberActionOptions(localChatRoom)[memberPublicKey]
|
||||
?.firstOrNull { it.action == action }
|
||||
?: return MemberActionUnavailableUIState.NoLongerApplies
|
||||
|
||||
val memberName = nameOf(memberPublicKey)
|
||||
if (option.isAvailable) return MemberActionUnavailableUIState.NowAvailable(memberName, action)
|
||||
|
||||
val named = option.blockers.flatMap { blocker ->
|
||||
when (blocker) {
|
||||
is MemberActionBlocker.NotAnAdmin -> blocker.admins
|
||||
else -> emptySet()
|
||||
}
|
||||
}.toSet()
|
||||
return MemberActionUnavailableUIState.Blocked(
|
||||
memberName = memberName,
|
||||
action = action,
|
||||
blockers = option.blockers,
|
||||
names = named.associateWith { nameOf(it) },
|
||||
adminRoomId = if (MemberActionBlocker.NoAdminsInThisRoom in option.blockers) chatRepository.adminRoomOf(chatRoomId) else null,
|
||||
)
|
||||
}
|
||||
|
||||
private suspend fun nameOf(publicKey: HexKey): String =
|
||||
nostrRepository.getProfileWithPublicKey(publicKey)?.humanReadableNameOrPubkey()
|
||||
?: publicKey.take(SHORTENED_PUBLIC_KEY_LENGTH)
|
||||
|
||||
/**
|
||||
* Every room row this account holds, and the inputs of the room's shares: a
|
||||
* commit landing rewrites the room's row, and a rotation or a signing session
|
||||
* writes the others. Either may clear a reason.
|
||||
*/
|
||||
@OptIn(FlowPreview::class)
|
||||
private fun observe() {
|
||||
if (observer != null) return
|
||||
observer = viewModelScope.launch(Dispatchers.IO) {
|
||||
merge(
|
||||
chatRepository.observeChatRoomListByPublicKey(activeUserPublicKey).map { },
|
||||
chatRepository.observeSharesInputs(chatRoomId),
|
||||
)
|
||||
.debounce(SETTLE_MILLIS)
|
||||
.collect { reload() }
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG = "MemberActionUnavailableViewModel"
|
||||
private const val SHORTENED_PUBLIC_KEY_LENGTH = 12
|
||||
private const val SETTLE_MILLIS = 300L
|
||||
|
||||
fun factory(
|
||||
activeUserPublicKey: HexKey,
|
||||
chatRoomId: String,
|
||||
memberPublicKey: HexKey,
|
||||
action: MemberAction?,
|
||||
initialUIState: MemberActionUnavailableUIState = MemberActionUnavailableUIState.Loading,
|
||||
nostrRepository: NostrRepository,
|
||||
chatRepository: ChatRepository,
|
||||
): ViewModelProvider.Factory = viewModelFactory {
|
||||
initializer {
|
||||
MemberActionUnavailableViewModel(
|
||||
activeUserPublicKey = activeUserPublicKey,
|
||||
chatRoomId = chatRoomId,
|
||||
memberPublicKey = memberPublicKey,
|
||||
action = action,
|
||||
initialUIState = initialUIState,
|
||||
nostrRepository = nostrRepository,
|
||||
chatRepository = chatRepository,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+7
-2
@@ -104,8 +104,13 @@ sealed interface ChatRoomDetailUIState {
|
||||
* rotation is behind its flag.
|
||||
*/
|
||||
val shareHolders: Set<HexKey> = emptySet(),
|
||||
/** What this device may do to each member, by public key; absent means nothing. */
|
||||
val memberActions: Map<HexKey, Set<MemberAction>> = emptyMap(),
|
||||
/**
|
||||
* What each member row's menu offers, by public key, open or not, with the
|
||||
* reasons an item is not; absent means no menu. Every other member has an
|
||||
* entry whatever the viewer's role, and this device's own row has one only
|
||||
* when stepping down is open. docs/member-row-actions.md, D1 and D2.
|
||||
*/
|
||||
val memberActions: Map<HexKey, List<MemberActionOption>> = emptyMap(),
|
||||
/** How **Leave group** goes when this device is an admin; null when it is not. */
|
||||
val adminLeave: AdminLeave? = null,
|
||||
/** Where a keyed room stands on needing the group's signature; null for any other room. */
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package mobi.giza.compose.ui.view.state
|
||||
|
||||
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
|
||||
/**
|
||||
* What this device may do to one member of a room, as the member row's menu offers
|
||||
* it. Computed by the view model from the group's state and
|
||||
* `mobi.giza.compose.managers.AdminGovernance`, so the screen never decides an
|
||||
* action itself. See docs/member-admin-promotion.md, Phase 11.
|
||||
* What can be done to one member of a room, as the member row's menu offers it.
|
||||
* Computed by `mobi.giza.compose.managers.MemberActionPolicy` from the group's
|
||||
* state, so the screen never decides an action itself. See
|
||||
* docs/member-admin-promotion.md, Phase 11, and docs/member-row-actions.md.
|
||||
*/
|
||||
enum class MemberAction {
|
||||
MAKE_ADMIN,
|
||||
@@ -14,6 +16,66 @@ enum class MemberAction {
|
||||
REMOVE_FROM_GROUP,
|
||||
}
|
||||
|
||||
/**
|
||||
* One item of a member row's menu: an action that applies to this member, and
|
||||
* what stands in its way. The menu lists it either way; one with [blockers]
|
||||
* opens a screen that explains them instead of acting. docs/member-row-actions.md, D3.
|
||||
*/
|
||||
data class MemberActionOption(
|
||||
val action: MemberAction,
|
||||
/** In the order the explanation leads with them; empty when the action is open. */
|
||||
val blockers: List<MemberActionBlocker> = emptyList(),
|
||||
) {
|
||||
val isAvailable: Boolean get() = blockers.isEmpty()
|
||||
}
|
||||
|
||||
/**
|
||||
* Why an action is not open to this device now. Room-wide reasons come first,
|
||||
* then the viewer's role, then the room's rules, then the member, then work in
|
||||
* flight -- the order `MemberActionPolicy` lists them in. docs/member-row-actions.md, D4 and D6.
|
||||
*/
|
||||
sealed interface MemberActionBlocker {
|
||||
/** A robust group's NIP-17 room: its members administer the room its key made. */
|
||||
data object NoAdminsInThisRoom : MemberActionBlocker
|
||||
|
||||
/** A room on the legacy Marmot profile, whose admins the app does not change. */
|
||||
data object LegacyRoom : MemberActionBlocker
|
||||
|
||||
data object Disbanded : MemberActionBlocker
|
||||
|
||||
/** This device's account has left the room. */
|
||||
data object YouLeft : MemberActionBlocker
|
||||
|
||||
/** The viewer is not an admin; [admins] are who to ask. */
|
||||
data class NotAnAdmin(val admins: Set<HexKey>) : MemberActionBlocker
|
||||
|
||||
/**
|
||||
* A keyed room whose changes do not need the group's signature, which every
|
||||
* change to its admins has to (R2). Every keyed room is born needing it now, so
|
||||
* this is one made before that, and nothing switches it on later: its admins
|
||||
* stay as they are. docs/remove-convenient-groups.md, "After the build".
|
||||
*/
|
||||
data object SignaturesNotRequired : MemberActionBlocker
|
||||
|
||||
/** A keyed room in a build without share rotation, which every admin change moves (R1). */
|
||||
data object ShareRotationUnavailable : MemberActionBlocker
|
||||
|
||||
/** The member holds no leaf in the group: still being added, or already being removed. */
|
||||
data object NotInGroupYet : MemberActionBlocker
|
||||
|
||||
/** The member is the only admin among the members; a group always keeps one. */
|
||||
data object OnlyAdmin : MemberActionBlocker
|
||||
|
||||
/** It would leave a keyed room below its admin floor (R3). */
|
||||
data class BelowFloor(val floor: Int) : MemberActionBlocker
|
||||
|
||||
/** An earlier change to the room is still waiting for a relay to accept it. */
|
||||
data object ChangePending : MemberActionBlocker
|
||||
|
||||
/** The member has already been offered admin, and has not answered. */
|
||||
data object OfferPending : MemberActionBlocker
|
||||
}
|
||||
|
||||
/**
|
||||
* How **Leave group** goes for an admin, who cannot simply leave: the library
|
||||
* refuses an admin's SelfRemove. docs/member-admin-promotion.md, Phase 10.
|
||||
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package mobi.giza.compose.ui.view.state
|
||||
|
||||
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
|
||||
/**
|
||||
* The screen that says why one member row action is not open.
|
||||
* docs/member-row-actions.md, Phase 4.
|
||||
*/
|
||||
sealed interface MemberActionUnavailableUIState {
|
||||
data object Loading : MemberActionUnavailableUIState
|
||||
|
||||
/** The room could not be read; asking again is the retry. */
|
||||
data object Error : MemberActionUnavailableUIState
|
||||
|
||||
/**
|
||||
* The room, the member, or the action's fit with the member's role has gone
|
||||
* since the row was opened: a member made an admin is not "made an admin" again.
|
||||
*/
|
||||
data object NoLongerApplies : MemberActionUnavailableUIState
|
||||
|
||||
data class Blocked(
|
||||
val memberName: String,
|
||||
val action: MemberAction,
|
||||
/** First the one the screen leads with, then the rest. Never empty. */
|
||||
val blockers: List<MemberActionBlocker>,
|
||||
/** What to call everyone a blocker names: admins to ask, devices waited on. */
|
||||
val names: Map<HexKey, String> = emptyMap(),
|
||||
/** The admin room a NIP-17 room's members run the group from, when known. */
|
||||
val adminRoomId: String? = null,
|
||||
) : MemberActionUnavailableUIState
|
||||
|
||||
/** Nothing stands in the way any more: the blocker cleared while the screen was open. */
|
||||
data class NowAvailable(
|
||||
val memberName: String,
|
||||
val action: MemberAction,
|
||||
) : MemberActionUnavailableUIState
|
||||
}
|
||||
+194
@@ -0,0 +1,194 @@
|
||||
package mobi.giza.compose.managers
|
||||
|
||||
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
|
||||
import kotlin.test.assertNull
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
/**
|
||||
* What a member row's menu offers, and why an item is not open, for every reason
|
||||
* docs/member-row-actions.md names. Over plain sets: the agreement with the
|
||||
* group's own rules is `AdminChangesJvmTest`'s and `GovernanceGateJvmTest`'s,
|
||||
* which call [AdminGovernance.memberActions] -- this, filtered to what is open.
|
||||
*/
|
||||
class MemberActionPolicyTest {
|
||||
|
||||
private val me = "a".repeat(64)
|
||||
private val bob = "b".repeat(64)
|
||||
private val carol = "c".repeat(64)
|
||||
private val dana = "d".repeat(64)
|
||||
private val gone = "e".repeat(64)
|
||||
|
||||
/** A convenient room I administer, with Bob and Carol in it. */
|
||||
private fun convenient(
|
||||
admins: Set<String> = setOf(me),
|
||||
members: Set<String> = setOf(me, bob, carol),
|
||||
) = MemberActionContext(room = MemberActionRoom.CURRENT, me = me, admins = admins, members = members)
|
||||
|
||||
/** A keyed room where every change can be made: governed, rotation on, floor three. */
|
||||
private fun keyed(
|
||||
admins: Set<String> = setOf(me, bob, carol, dana),
|
||||
members: Set<String> = setOf(me, bob, carol, dana),
|
||||
) = MemberActionContext(
|
||||
room = MemberActionRoom.CURRENT,
|
||||
me = me,
|
||||
admins = admins,
|
||||
members = members,
|
||||
isKeyed = true,
|
||||
governed = true,
|
||||
shareRefresh = true,
|
||||
floor = 3,
|
||||
)
|
||||
|
||||
private fun MemberActionContext.option(member: String, action: MemberAction): MemberActionOption? =
|
||||
MemberActionPolicy.options(this, members + admins + gone).getValue(member).firstOrNull { it.action == action }
|
||||
|
||||
private fun MemberActionContext.blockers(member: String, action: MemberAction) =
|
||||
requireNotNull(option(member, action)) { "$action was not offered on $member's row" }.blockers
|
||||
|
||||
@Test
|
||||
fun `a member is offered make admin and removal, an admin removal as admin and removal, in that order`() {
|
||||
val options = MemberActionPolicy.options(convenient(admins = setOf(me, carol)), listOf(bob, carol))
|
||||
|
||||
assertEquals(listOf(MemberAction.MAKE_ADMIN, MemberAction.REMOVE_FROM_GROUP), options.getValue(bob).map { it.action })
|
||||
assertEquals(listOf(MemberAction.REMOVE_AS_ADMIN, MemberAction.REMOVE_FROM_GROUP), options.getValue(carol).map { it.action })
|
||||
assertTrue(options.values.flatten().all { it.isAvailable })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `your own row lists step down when it is open, and nothing otherwise`() {
|
||||
val twoAdmins = MemberActionPolicy.options(convenient(admins = setOf(me, bob)), listOf(me))
|
||||
assertEquals(listOf(MemberActionOption(MemberAction.STEP_DOWN)), twoAdmins[me])
|
||||
|
||||
assertNull(MemberActionPolicy.options(convenient(), listOf(me))[me], "the only admin was offered to step down")
|
||||
assertNull(MemberActionPolicy.options(convenient(admins = setOf(bob)), listOf(me))[me], "a member was offered to step down")
|
||||
}
|
||||
|
||||
/**
|
||||
* In a keyed room stepping down is a request another admin's device proposes
|
||||
* (`AdminGovernance.canAskToStepDown`): offered above the floor, with another
|
||||
* admin to ask, in a room whose changes the group signs.
|
||||
*/
|
||||
@Test
|
||||
fun `an admin of a keyed room asks to step down, above the floor and with someone to ask`() {
|
||||
assertEquals(listOf(MemberActionOption(MemberAction.STEP_DOWN)), MemberActionPolicy.options(keyed(), listOf(me))[me])
|
||||
|
||||
val atFloor = keyed(admins = setOf(me, bob, carol))
|
||||
assertNull(MemberActionPolicy.options(atFloor, listOf(me))[me], "stepping down was offered at the floor")
|
||||
|
||||
val alone = keyed(admins = setOf(me)).copy(floor = 1)
|
||||
assertNull(MemberActionPolicy.options(alone, listOf(me))[me], "stepping down was offered with nobody to ask")
|
||||
|
||||
assertNull(MemberActionPolicy.options(keyed().copy(governed = false), listOf(me))[me], "an unsigned keyed room offered it")
|
||||
assertNull(MemberActionPolicy.options(keyed().copy(shareRefresh = false), listOf(me))[me], "a build without rotation offered it")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a NIP-17 room explains that it has no admins, and nothing else`() {
|
||||
val context = MemberActionContext(room = MemberActionRoom.NIP17, me = me, admins = emptySet(), members = emptySet())
|
||||
|
||||
val options = MemberActionPolicy.options(context, listOf(me, bob)).getValue(bob)
|
||||
|
||||
assertEquals(listOf(MemberAction.MAKE_ADMIN, MemberAction.REMOVE_FROM_GROUP), options.map { it.action })
|
||||
assertTrue(options.all { it.blockers == listOf(MemberActionBlocker.NoAdminsInThisRoom) })
|
||||
assertNull(MemberActionPolicy.options(context, listOf(me))[me])
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a legacy room says so, and reads the role from the participants`() {
|
||||
val context = MemberActionContext(room = MemberActionRoom.LEGACY, me = me, admins = setOf(bob), members = emptySet())
|
||||
|
||||
val options = MemberActionPolicy.options(context, listOf(bob)).getValue(bob)
|
||||
|
||||
assertEquals(MemberAction.REMOVE_AS_ADMIN, options.first().action)
|
||||
assertTrue(options.all { it.blockers == listOf(MemberActionBlocker.LegacyRoom) })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a disbanded room, and a room you left, lead with that`() {
|
||||
assertEquals(MemberActionBlocker.Disbanded, convenient().copy(isDisbanded = true).blockers(bob, MemberAction.MAKE_ADMIN).first())
|
||||
assertEquals(MemberActionBlocker.YouLeft, convenient().copy(hasLeft = true).blockers(bob, MemberAction.REMOVE_FROM_GROUP).first())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a member who is not an admin is told who to ask, on every item`() {
|
||||
val context = convenient(admins = setOf(carol))
|
||||
|
||||
assertEquals(listOf(MemberActionBlocker.NotAnAdmin(setOf(carol))), context.blockers(bob, MemberAction.MAKE_ADMIN))
|
||||
assertEquals(listOf(MemberActionBlocker.NotAnAdmin(setOf(carol))), context.blockers(bob, MemberAction.REMOVE_FROM_GROUP))
|
||||
// Carol is the only admin: the role comes first, the depletion after it.
|
||||
assertEquals(
|
||||
listOf(MemberActionBlocker.NotAnAdmin(setOf(carol)), MemberActionBlocker.OnlyAdmin),
|
||||
context.blockers(carol, MemberAction.REMOVE_AS_ADMIN),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `the room's role comes before the viewer's`() {
|
||||
assertEquals(
|
||||
listOf(MemberActionBlocker.Disbanded, MemberActionBlocker.NotAnAdmin(setOf(carol))),
|
||||
convenient(admins = setOf(carol)).copy(isDisbanded = true).blockers(bob, MemberAction.MAKE_ADMIN),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a keyed room made before signed changes keeps its admins`() {
|
||||
val context = keyed(admins = setOf(me, carol, dana)).copy(governed = false)
|
||||
|
||||
assertEquals(listOf(MemberActionBlocker.SignaturesNotRequired), context.blockers(bob, MemberAction.MAKE_ADMIN))
|
||||
assertEquals(listOf(MemberActionBlocker.SignaturesNotRequired), context.blockers(carol, MemberAction.REMOVE_AS_ADMIN).take(1))
|
||||
assertTrue(context.option(bob, MemberAction.REMOVE_FROM_GROUP)!!.isAvailable, "removal needs no signature rule to be offered")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a keyed room in a build without share rotation says so`() {
|
||||
val context = keyed(admins = setOf(me, carol, dana)).copy(shareRefresh = false)
|
||||
|
||||
assertEquals(listOf(MemberActionBlocker.ShareRotationUnavailable), context.blockers(bob, MemberAction.MAKE_ADMIN))
|
||||
assertTrue(context.option(bob, MemberAction.REMOVE_FROM_GROUP)!!.isAvailable)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a convenient room has neither keyed rule`() {
|
||||
val context = convenient().copy(governed = false, shareRefresh = false)
|
||||
|
||||
assertTrue(context.option(bob, MemberAction.MAKE_ADMIN)!!.isAvailable)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `someone without a leaf can be neither made an admin nor removed`() {
|
||||
val context = convenient()
|
||||
|
||||
assertEquals(listOf(MemberActionBlocker.NotInGroupYet), context.blockers(gone, MemberAction.MAKE_ADMIN))
|
||||
assertEquals(listOf(MemberActionBlocker.NotInGroupYet), context.blockers(gone, MemberAction.REMOVE_FROM_GROUP))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `the floor holds on demotion and removal, and is only spoken of below it`() {
|
||||
val atFloor = keyed(admins = setOf(me, bob, carol), members = setOf(me, bob, carol, dana))
|
||||
|
||||
assertEquals(listOf(MemberActionBlocker.BelowFloor(3)), atFloor.blockers(bob, MemberAction.REMOVE_AS_ADMIN))
|
||||
assertEquals(listOf(MemberActionBlocker.BelowFloor(3)), atFloor.blockers(bob, MemberAction.REMOVE_FROM_GROUP))
|
||||
assertTrue(atFloor.option(dana, MemberAction.REMOVE_FROM_GROUP)!!.isAvailable, "a member's removal touches no floor")
|
||||
|
||||
val aboveFloor = keyed()
|
||||
assertTrue(aboveFloor.option(bob, MemberAction.REMOVE_AS_ADMIN)!!.isAvailable)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `work in flight comes last`() {
|
||||
val context = convenient(admins = setOf(carol)).copy(changePending = true, offeredAdmin = setOf(bob))
|
||||
|
||||
assertEquals(
|
||||
listOf(MemberActionBlocker.NotAnAdmin(setOf(carol)), MemberActionBlocker.ChangePending, MemberActionBlocker.OfferPending),
|
||||
context.blockers(bob, MemberAction.MAKE_ADMIN),
|
||||
)
|
||||
assertEquals(
|
||||
listOf(MemberActionBlocker.NotAnAdmin(setOf(carol)), MemberActionBlocker.ChangePending),
|
||||
context.blockers(bob, MemberAction.REMOVE_FROM_GROUP),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -37,6 +37,8 @@ import mobi.giza.compose.nostr.MarmotProfile
|
||||
import mobi.giza.compose.nostr.Relays
|
||||
import mobi.giza.compose.ui.view.state.AdminLeave
|
||||
import mobi.giza.compose.ui.view.state.MemberAction
|
||||
import mobi.giza.compose.ui.view.state.MemberActionBlocker
|
||||
import mobi.giza.compose.ui.view.state.MemberActionOption
|
||||
|
||||
/**
|
||||
* Promoting and demoting in a convenient room, which has no key to sign with and
|
||||
@@ -194,6 +196,23 @@ class AdminChangesJvmTest {
|
||||
assertFailsWith<MarmotCommitPendingException> { chatRepository.promoteMember(room(), member.hex) }
|
||||
}
|
||||
|
||||
/**
|
||||
* The same gate, said before anyone tries: every item waits on the earlier
|
||||
* change, and stops waiting once a relay accepts it. docs/member-row-actions.md,
|
||||
* Phase 5.
|
||||
*/
|
||||
@Test
|
||||
fun `the rows say an earlier change is on its way, until a relay accepts it`() = runBlocking {
|
||||
convenientRoomWithMember()
|
||||
chatRepository.promoteMember(room(), member.hex)
|
||||
|
||||
val waiting = chatRepository.memberActionOptions(room()).getValue(member.hex)
|
||||
assertTrue(waiting.all { it.blockers == listOf(MemberActionBlocker.ChangePending) }, "the rows did not wait on the commit: $waiting")
|
||||
|
||||
okTheLatestCommit()
|
||||
assertTrue(chatRepository.memberActionOptions(room()).getValue(member.hex).all { it.isAvailable })
|
||||
}
|
||||
|
||||
/**
|
||||
* The hole this phase closes. A bare Remove left the admin's key on the list,
|
||||
* so inviting them back made them an admin again with nobody having said so.
|
||||
@@ -233,6 +252,37 @@ class AdminChangesJvmTest {
|
||||
assertEquals(AdminLeave.STEP_DOWN_FIRST, AdminGovernance.adminLeave(appGroup(), user))
|
||||
}
|
||||
|
||||
/**
|
||||
* The rows' options as the screen reads them, through the repository: every
|
||||
* item is listed, and one the group would refuse says why.
|
||||
* docs/member-row-actions.md, Phase 2.
|
||||
*/
|
||||
@Test
|
||||
fun `the rows' options list every action, and say why one is not open`() = runBlocking {
|
||||
convenientRoomWithMember()
|
||||
|
||||
assertEquals(
|
||||
mapOf(member.hex to listOf(MemberActionOption(MemberAction.MAKE_ADMIN), MemberActionOption(MemberAction.REMOVE_FROM_GROUP))),
|
||||
chatRepository.memberActionOptions(room()),
|
||||
"the only admin's own row offered to step down, or a member's row was missing",
|
||||
)
|
||||
|
||||
chatRepository.promoteMember(room(), member.hex)
|
||||
okTheLatestCommit()
|
||||
|
||||
val options = chatRepository.memberActionOptions(room())
|
||||
assertEquals(listOf(MemberActionOption(MemberAction.STEP_DOWN)), options[user])
|
||||
assertEquals(
|
||||
listOf(MemberActionOption(MemberAction.REMOVE_AS_ADMIN), MemberActionOption(MemberAction.REMOVE_FROM_GROUP)),
|
||||
options[member.hex],
|
||||
)
|
||||
|
||||
// Having left, nothing is open, and every item says so first.
|
||||
db.chatRoomDao().upsert(room().chatRoom.copy(leftGroupAt = kotlin.time.Clock.System.now()))
|
||||
val afterLeaving = chatRepository.memberActionOptions(room()).getValue(member.hex)
|
||||
assertTrue(afterLeaving.all { it.blockers.firstOrNull() == MemberActionBlocker.YouLeft })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `an admin with another admin beside them steps down, then leaves`() = runBlocking {
|
||||
convenientRoomWithMember()
|
||||
|
||||
@@ -57,6 +57,23 @@ class PromotionOffersJvmTest {
|
||||
assertNull(PromotionManager.pendingOffer(db, roomId, erin), "an accepted offer still asked")
|
||||
}
|
||||
|
||||
/** Who the member rows say has already been asked. docs/member-row-actions.md, Phase 5. */
|
||||
@Test
|
||||
fun `whoever was offered admin and has not answered has already been asked`() = runBlocking {
|
||||
room()
|
||||
assertEquals(emptySet(), PromotionManager.unansweredOfferTargets(db, roomId))
|
||||
|
||||
said('a', alice, PromotionEvents.OFFER, PromotionEvents.offerTags(roomId, erin), 1)
|
||||
assertEquals(setOf(erin), PromotionManager.unansweredOfferTargets(db, roomId))
|
||||
|
||||
// An acceptance by somebody else answers nothing.
|
||||
said('c', alice, PromotionEvents.ACCEPT, PromotionEvents.acceptTags(roomId, "a".repeat(64), "02" + "d".repeat(64)), 2)
|
||||
assertEquals(setOf(erin), PromotionManager.unansweredOfferTargets(db, roomId), "Alice answered Erin's offer")
|
||||
|
||||
said('b', erin, PromotionEvents.ACCEPT, PromotionEvents.acceptTags(roomId, "a".repeat(64), "02" + "c".repeat(64)), 3)
|
||||
assertEquals(emptySet(), PromotionManager.unansweredOfferTargets(db, roomId), "an accepted offer still waited")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `an accepted offer is the offerer's to propose, once`() = runBlocking {
|
||||
room()
|
||||
|
||||
+78
-1
@@ -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,15 @@ 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
|
||||
|
||||
@@ -80,7 +87,7 @@ class ChatRoomMemberRowJvmTest {
|
||||
onNavigateToRoute = {},
|
||||
state = state().copy(
|
||||
adminPublicKeys = setOf(activeUserPublicKey),
|
||||
memberActions = mapOf(named to setOf(MemberAction.MAKE_ADMIN, MemberAction.REMOVE_FROM_GROUP)),
|
||||
memberActions = mapOf(named to listOf(MemberActionOption(MemberAction.MAKE_ADMIN), MemberActionOption(MemberAction.REMOVE_FROM_GROUP))),
|
||||
),
|
||||
) {
|
||||
onAllNodesWithContentDescription("Member actions").assertCountEquals(1)
|
||||
@@ -93,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(
|
||||
|
||||
+195
@@ -0,0 +1,195 @@
|
||||
package mobi.giza.compose.ui.composable
|
||||
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.test.ComposeUiTest
|
||||
import androidx.compose.ui.test.ExperimentalTestApi
|
||||
import androidx.compose.ui.test.onNodeWithContentDescription
|
||||
import androidx.compose.ui.test.onNodeWithText
|
||||
import androidx.compose.ui.test.performClick
|
||||
import androidx.compose.ui.test.runDesktopComposeUiTest
|
||||
import androidx.navigation.NavHostController
|
||||
import androidx.navigation.compose.NavHost
|
||||
import androidx.navigation.compose.composable
|
||||
import androidx.navigation.compose.rememberNavController
|
||||
import androidx.navigation.toRoute
|
||||
import kotlinx.serialization.Serializable
|
||||
import mobi.giza.compose.repository.ChatRepository
|
||||
import mobi.giza.compose.repository.NostrRepository
|
||||
import mobi.giza.compose.ui.composable.navigation.routes.ChatRoomDetailRoute
|
||||
import mobi.giza.compose.ui.composable.navigation.routes.MemberActionUnavailableRoute
|
||||
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.MemberAction
|
||||
import mobi.giza.compose.ui.view.state.MemberActionBlocker
|
||||
import mobi.giza.compose.ui.view.state.MemberActionUnavailableUIState
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
@Serializable
|
||||
internal object MemberActionRouteTestStart
|
||||
|
||||
/**
|
||||
* The screen a member row's closed action opens: what is in the way, what would
|
||||
* change it, and the one thing to do about it where there is one.
|
||||
* docs/member-row-actions.md, Phase 4.
|
||||
*/
|
||||
@OptIn(ExperimentalTestApi::class)
|
||||
class MemberActionUnavailableScreenJvmTest {
|
||||
|
||||
private val activeUserPublicKey = "a".repeat(64)
|
||||
private val chatRoomId = "f".repeat(64)
|
||||
private val nomvula = "b".repeat(64)
|
||||
private val thabo = "c".repeat(64)
|
||||
|
||||
private fun blocked(vararg blockers: MemberActionBlocker, adminRoomId: String? = null) = MemberActionUnavailableUIState.Blocked(
|
||||
memberName = "Nomvula",
|
||||
action = MemberAction.MAKE_ADMIN,
|
||||
blockers = blockers.toList(),
|
||||
names = mapOf(thabo to "Thabo"),
|
||||
adminRoomId = adminRoomId,
|
||||
)
|
||||
|
||||
@Test
|
||||
fun `every reason says what is in the way and what would change it`() {
|
||||
val expected = mapOf(
|
||||
MemberActionBlocker.NoAdminsInThisRoom to "This room has no admins",
|
||||
MemberActionBlocker.LegacyRoom to "This group uses an older format",
|
||||
MemberActionBlocker.Disbanded to "This group was disbanded",
|
||||
MemberActionBlocker.YouLeft to "You've left this group",
|
||||
MemberActionBlocker.NotAnAdmin(setOf(thabo)) to "Only admins can do this",
|
||||
MemberActionBlocker.SignaturesNotRequired to "This group was made before signed changes",
|
||||
MemberActionBlocker.ShareRotationUnavailable to "Not in this version of Giza yet",
|
||||
MemberActionBlocker.NotInGroupYet to "Nomvula isn't fully in the group",
|
||||
MemberActionBlocker.OnlyAdmin to "Nomvula is the only admin",
|
||||
MemberActionBlocker.BelowFloor(3) to "A group with a shared key needs at least 3 admins",
|
||||
MemberActionBlocker.ChangePending to "An earlier change is still on its way",
|
||||
MemberActionBlocker.OfferPending to "Nomvula has already been asked",
|
||||
)
|
||||
expected.forEach { (blocker, title) ->
|
||||
render(blocked(blocker)) {
|
||||
onNodeWithText(title).assertExists()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a member who is not an admin is told who to ask, by name`() {
|
||||
render(blocked(MemberActionBlocker.NotAnAdmin(setOf(thabo)))) {
|
||||
onNodeWithText("Ask one of the group's admins: Thabo.").assertExists()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `the first reason leads, and the rest are under it`() {
|
||||
render(blocked(MemberActionBlocker.Disbanded, MemberActionBlocker.NotAnAdmin(setOf(thabo)))) {
|
||||
onNodeWithText("This group was disbanded").assertExists()
|
||||
onNodeWithText("Also in the way").assertExists()
|
||||
onNodeWithText("Only admins can do this").assertExists()
|
||||
}
|
||||
render(blocked(MemberActionBlocker.Disbanded)) {
|
||||
onNodeWithText("Also in the way").assertDoesNotExist()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a room with no admins opens the admin room, when it knows which`() {
|
||||
var opened: Route? = null
|
||||
render(blocked(MemberActionBlocker.NoAdminsInThisRoom, adminRoomId = "9".repeat(64)), onNavigateToRoute = { opened = it }) {
|
||||
onNodeWithText("Open the admin room").performClick()
|
||||
}
|
||||
assertEquals(ChatRoomDetailRoute(activeUserPublicKey, "9".repeat(64), null), opened)
|
||||
|
||||
render(blocked(MemberActionBlocker.NoAdminsInThisRoom)) {
|
||||
onNodeWithText("Open the admin room").assertDoesNotExist()
|
||||
}
|
||||
render(blocked(MemberActionBlocker.Disbanded, adminRoomId = "9".repeat(64))) {
|
||||
onNodeWithText("Open the admin room").assertDoesNotExist()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a reason that cleared says so, and goes back to the group`() {
|
||||
var wentBack = false
|
||||
render(MemberActionUnavailableUIState.NowAvailable("Nomvula", MemberAction.MAKE_ADMIN), onNavigateBack = { wentBack = true }) {
|
||||
onNodeWithText("You can do this now").assertExists()
|
||||
onNodeWithText("Back to the group").performClick()
|
||||
}
|
||||
assertTrue(wentBack)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `the title is the action, and there is a way back on a desktop`() {
|
||||
var wentBack = false
|
||||
render(blocked(MemberActionBlocker.OnlyAdmin), onNavigateBack = { wentBack = true }) {
|
||||
onNodeWithText("Make admin").assertExists()
|
||||
onNodeWithContentDescription("Back").performClick()
|
||||
}
|
||||
assertTrue(wentBack)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a change since the row was opened says the action no longer applies`() {
|
||||
render(MemberActionUnavailableUIState.NoLongerApplies) {
|
||||
onNodeWithText("This no longer applies", substring = true).assertExists()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The route survives navigation-compose's encoding with each action: an enum in
|
||||
* a type-safe route is the part of D5 a library upgrade could break.
|
||||
*/
|
||||
@Test
|
||||
fun `the route carries every action through navigation`() {
|
||||
MemberAction.entries.forEach { action ->
|
||||
val route = MemberActionUnavailableRoute(activeUserPublicKey, chatRoomId, nomvula, action)
|
||||
var arrived: MemberActionUnavailableRoute? = null
|
||||
runDesktopComposeUiTest {
|
||||
lateinit var controller: NavHostController
|
||||
setContent {
|
||||
controller = rememberNavController()
|
||||
NavHost(navController = controller, startDestination = MemberActionRouteTestStart) {
|
||||
composable<MemberActionRouteTestStart> { Text("start") }
|
||||
composable<MemberActionUnavailableRoute> { entry -> arrived = entry.toRoute() }
|
||||
}
|
||||
}
|
||||
runOnUiThread { controller.navigate(route) }
|
||||
waitForIdle()
|
||||
}
|
||||
assertEquals(route, arrived)
|
||||
}
|
||||
}
|
||||
|
||||
private fun render(
|
||||
state: MemberActionUnavailableUIState,
|
||||
onNavigateToRoute: (Route) -> Unit = {},
|
||||
onNavigateBack: () -> Unit = {},
|
||||
assertions: ComposeUiTest.() -> Unit,
|
||||
) = runDesktopComposeUiTest(width = 400, height = 1600) {
|
||||
setContent {
|
||||
GizaTheme {
|
||||
ProvideSnackbarHost {
|
||||
Box(modifier = Modifier.fillMaxSize()) {
|
||||
MemberActionUnavailableScreen(
|
||||
activeUserPublicKey = activeUserPublicKey,
|
||||
chatRoomId = chatRoomId,
|
||||
memberPublicKey = nomvula,
|
||||
action = MemberAction.MAKE_ADMIN,
|
||||
initialUIState = state,
|
||||
nostrRepository = NostrRepository.NO_OP_NOSTR_REPOSITORY,
|
||||
chatRepository = ChatRepository.NO_OP_CHAT_REPOSITORY,
|
||||
onNavigateToRoute = onNavigateToRoute,
|
||||
onNavigateBack = onNavigateBack,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assertions()
|
||||
}
|
||||
}
|
||||
@@ -37,6 +37,7 @@ the [retired](./retired/) notes now.
|
||||
| [marmot-kmp.md](./marmot-kmp.md) | moving the group layer off quartz's engine and onto marmot-kmp, mls-kmp and crypto-kmp — why staying on quartz 1.15.2 is staying on an engine that left, the 228 import lines and the one rule that places all but two of them, the group state on a device that must still open afterwards, nine phases that put the swap in one commit and the evidence around it, how often this app persists a group once a sent message no longer rewrites it, and the schema change that followed, opened from the version the app ships |
|
||||
| [giza-wallet-removal.md](./giza-wallet-removal.md) | taking every wallet out of Giza, phased and built but for moving off the wallet library (7b). Covers why a Giza member declines a Bennu peer's wallet proposal instead of ignoring or signing it, why the wallet's kinds are retired rather than freed, why a recovery phrase stays as a key backup that has to derive the same npub and id byte for byte, and why the threshold crypto keeps the build tied to the wallet library until the last phase |
|
||||
| [member-admin-promotion.md](./member-admin-promotion.md) | making a member an admin and back, phased and built, promotion with a share and demotion with a refresh under the experimental enrollment, under three rules: every admin holds a share, every commit in a keyed room is a proposal until the group's threshold signature is on it, and a robust group keeps at least three admins. Covers why the commit rides inside the group's signature and the rule inside the group's state, which lets every device refuse an unsigned commit with the libraries as they are, why a member's own leave stays exempt, and why a removed admin comes back as an admin when re-invited today |
|
||||
| [member-row-actions.md](./member-row-actions.md) | every member row but your own offers every action that applies to that member, and an action you can't take now opens a screen saying what stands in the way and what would change it — phased and built. Covers the twelve reasons an action is refused today, why an unavailable item is marked rather than disabled, and why the explanation screen recomputes its reason instead of carrying it |
|
||||
| [giza-rebrand.md](./giza-rebrand.md) | forking Bennu as Giza under `mobi.giza` — what carries the name, what must not be renamed and why, why the desktop data directory changes first, and how the fork keeps merging from Bennu |
|
||||
| [robust-group-admins.md](./robust-group-admins.md) | making every founding member of a robust group an admin of its room, on every device -- phased and built. Covers why the ceremony's participants are the founding set, the Welcome that flags no admins, the joiner's check against the ceremony it took part in, and finishing an invite that partly failed |
|
||||
| [remove-convenient-groups.md](./remove-convenient-groups.md) | every group a member makes is robust -- phased and built. Covers why a one-to-one chat is not a group yet takes no new members, why the three-member floor moves to the member picker rather than down to 2-of-2, the quorum rules that outlive `ChatRoomType`, and why a Bennu peer's convenient group is still joined |
|
||||
|
||||
@@ -684,6 +684,10 @@ with a decided description. `./gradlew :composeApp:m3Audit` stays at its budgets
|
||||
**Tests:** `memberActions` for every row above, in both room kinds, at and above the
|
||||
floor.
|
||||
|
||||
*Since then:* every other member's row has the menu whoever is looking. An action
|
||||
that is not open is listed and explains itself instead of being hidden, and that
|
||||
includes D8's floor. See [member-row-actions.md](./member-row-actions.md).
|
||||
|
||||
## Phase 12 — across devices, and the docs
|
||||
|
||||
**Two days.**
|
||||
|
||||
@@ -0,0 +1,480 @@
|
||||
# Every member row offers every action, and says why one is not open
|
||||
|
||||
A phased plan for the member rows on the group detail screen. Every row but the
|
||||
viewer's own gets the overflow menu that only an admin sees today. The menu lists every
|
||||
action that applies to that member, whether or not the viewer can take it right now.
|
||||
An action that cannot be taken stays in the menu. Choosing it opens a screen that says
|
||||
what stands in the way and what would change that.
|
||||
|
||||
**Built**, one commit per phase on `claude/group-member-row-actions-1016b2`, in the
|
||||
order 1, 2, 4, 3, 5, 6. Phase 4 came before Phase 3 so that no commit has a menu item
|
||||
leading to a route that does not exist yet. The plan was written against `151f15ca`
|
||||
on `giza`, after [member-admin-promotion.md](./member-admin-promotion.md) Phase 11
|
||||
put the menu on the row. **Not run:** nothing here has been on a device. What the
|
||||
build did differently from the plan is listed in the next section.
|
||||
|
||||
## Where the build chose differently
|
||||
|
||||
| plan | built | why |
|
||||
|---|---|---|
|
||||
| D5: the route carries `action: MemberAction` | It carries the action's **name**, a `String`. `MemberActionUnavailableRoute.memberAction` reads it back, and a name no build knows reads as null, which the screen shows as "no longer applies" | The multiplatform navigation-compose 2.9.2 has no `NavType` for an enum. The route test caught this on its first run, which is what D5 asked of it |
|
||||
| D3: `onClickLabel = "See why"` on an unavailable item | The item gets `stateDescription = "Unavailable"`, plus the trailing info icon's description, "Why this is unavailable" | The merged node reads as the action, why it is unavailable, and the state. Giving a second click label to a node whose click `DropdownMenuItem` already owns depends on which semantics modifier wins, and nothing here tests that order |
|
||||
| D6: **Only admin** and **Below the floor** as separate reasons | The only admin is the floor of one, so one reason, `OnlyAdmin`. `BelowFloor` names a higher floor | The first test run listed both for the same member |
|
||||
| D6: `OfferPending` for an offer *from this account* | For an unanswered offer **by anyone** (`PromotionManager.unansweredOfferTargets`) | A second admin asking again is the same duplicate |
|
||||
| D6: `SignaturesNotRequired(waitingOn)`, "an admin turns that on", with **Back to the group** | `SignaturesNotRequired` carries no data. It says the group was made before signed changes and keeps its admins, and it has no button | Merged from `giza`: a keyed room is now born needing the group's signature, and the switch, the automatic switch and the waiting on devices are gone (`1ccd8c7f`). A keyed room without the rule is one made before that, and nothing turns it on |
|
||||
| D1: your own row shows **Step down as admin** when `canDemote(me, me)`, never in a keyed room | In a keyed room it is also shown when `AdminGovernance.canAskToStepDown` holds: the room needs the group's signature, rotation is on, you are above the floor, and another admin with a leaf is there to ask | Merged from `giza` (`bb35d73c`): an admin of a keyed room steps down by asking another admin's device to propose it. D1 itself stands: your own row still lists only an open step-down |
|
||||
| Phase 2: a view model test | A repository test in `AdminChangesJvmTest`, through the real database and group | That is the loader both screens read, so testing it covers both |
|
||||
|
||||
---
|
||||
|
||||
## What the row does today
|
||||
|
||||
`ChatRoomDetailScreen.kt` draws one `Card` per `localChatRoom.localParticipants`. The
|
||||
card's `onClick` opens `ProfilePreviewRoute`. The trailing slot is one of two things:
|
||||
|
||||
- **`MemberActionsMenu`** (`MemberAdminControls.kt`), when
|
||||
`chatRoomDetailUIState.memberActions[member]` is non-empty. That is a `MoreVert`
|
||||
`IconButton` with a `DropdownMenu` of the allowed actions, in `MemberAction.entries`
|
||||
order.
|
||||
- **`Icons.Default.ChevronRight`** with the description "View profile", a hardcoded
|
||||
string, in every other case.
|
||||
|
||||
`memberActions` comes from `AdminGovernance.memberActions(group, me, floor)`. The view
|
||||
model calls it only when `canGovern` is true, meaning the room is on the current Marmot
|
||||
profile, this device is an admin, and the room is neither disbanded nor left. The
|
||||
function returns *only* the allowed actions and drops members with none. So:
|
||||
|
||||
| viewer | what a row shows today |
|
||||
|---|---|
|
||||
| not an admin, or any NIP-17 or legacy room | a chevron on every row; no actions, and no hint that any exist |
|
||||
| an admin | the menu on rows where something is allowed, a chevron on the rest, with no explanation of the difference |
|
||||
| an admin, own row | **Step down as admin** when `canDemote(me, me)`, otherwise a chevron |
|
||||
|
||||
The reasons an action is refused already exist, but only as exception messages from
|
||||
`MarmotOutboundDao.promote`/`demote`/`removeMember`, shown in a snackbar after the
|
||||
fact. Nothing tells a person *before* they try.
|
||||
|
||||
### Every reason an action can be refused, from the code
|
||||
|
||||
Read from `AdminGovernance`, `MarmotGroupPermissions` (marmot-kmp 2.2.1), the view
|
||||
model's `canGovern`, and the refusals in `MarmotOutboundDao`:
|
||||
|
||||
| # | reason | where it is decided today | affects |
|
||||
|---|---|---|---|
|
||||
| 1 | The room is a NIP-17 room: it has no admins of its own; its members administer the room its key made | `mlsGroupState == null`; `adminRoomId` | all |
|
||||
| 2 | The room is on the legacy Marmot profile | `marmotProfile() != CURRENT` → `group == null` | all |
|
||||
| 3 | The group has been disbanded | `currentGroupState().isDisbanded` | all |
|
||||
| 4 | This device has left the group | `chatRoom.leftGroupAt != null` | all |
|
||||
| 5 | The viewer is not an admin | `MarmotGroupPermissions.canManage` | all |
|
||||
| 6 | A keyed room that does not require the group's signature yet | `GovernanceGate.isGoverned` inside `keyedChangesAllowed` | make admin, remove as admin |
|
||||
| 7 | A keyed room in a build without share rotation | `ExperimentalFeatures.shareRefresh` inside `keyedChangesAllowed` | make admin, remove as admin |
|
||||
| 8 | The member holds no leaf in the group (still being added, or already being removed) | `target in members(group)` in `canPromote`; the participant row exists without a leaf | make admin, remove from group |
|
||||
| 9 | They are the only admin among the members | `MarmotGroupPermissions.canDemote` (admin depletion) | remove as admin |
|
||||
| 10 | It would leave a keyed room below its admin floor `max(3, t)` | `AdminGovernance.keepsFloor` with `adminFloor` | remove as admin, remove from group |
|
||||
| 11 | An earlier change to the room is still waiting for a relay | `engine.gate.canPrepareLocalCommit` → `MarmotCommitPendingException` | all (transient) |
|
||||
| 12 | They have already been offered admin and have not accepted | `PromotionManager` offers | make admin (transient) |
|
||||
|
||||
Reasons 1 to 10 are facts about the group's state and can be computed when the screen
|
||||
loads. Reasons 11 and 12 are about work in flight; Phase 5 handles them separately.
|
||||
|
||||
---
|
||||
|
||||
## The decisions
|
||||
|
||||
### D1. The row's trailing control is the menu on every row but the viewer's own
|
||||
|
||||
Every other member gets the `MoreVert` overflow button whatever the viewer's role and
|
||||
whatever the room kind. The chevron is removed from those rows.
|
||||
|
||||
The viewer's own row keeps what it has today: the menu with **Step down as admin**
|
||||
when that is allowed, the chevron otherwise. "Except the current user" asks for no
|
||||
always-on menu on that row. It does not ask to take away step down, which is the only
|
||||
place that action lives.
|
||||
|
||||
Decided: your own row is unchanged by this plan. The alternative was a full menu there
|
||||
too, with **Step down** explained when it is unavailable (a keyed room, or being the
|
||||
only admin). It was turned down to keep the request as worded: your own row lists
|
||||
nothing it cannot do.
|
||||
|
||||
### D2. "All possible actions" means every action that applies to *this member's* role
|
||||
|
||||
A menu that offers **Make admin** on somebody who is already an admin makes no sense.
|
||||
That is a category error, not an action that is "disabled for the time being".
|
||||
Whether a member is an admin decides which of the two role actions appears:
|
||||
|
||||
| member | items, in this order |
|
||||
|---|---|
|
||||
| not an admin | **Make admin**, **Remove from group** |
|
||||
| an admin | **Remove as admin**, **Remove from group** |
|
||||
|
||||
The order is fixed (`MemberAction.entries`), so an item never moves when it becomes
|
||||
available. Whether a member is an admin comes from `adminPublicKeys`, the group's
|
||||
state, as D1 of member-admin-promotion requires. Where there is no group to read (a
|
||||
NIP-17 or legacy room), it comes from `participant.adminAt`, the only source those
|
||||
rooms have.
|
||||
|
||||
The member-admin-promotion table's **Retry enrollment** and **Rotate shares** rows
|
||||
were never built as `MemberAction`s and are out of scope here (see *Out of scope*).
|
||||
|
||||
### D3. An action the viewer cannot take now is listed, marked, and explains itself
|
||||
|
||||
An unavailable item is **not** `enabled = false`. M3's disabled `DropdownMenuItem`
|
||||
takes no click, so the explanation screen could never be reached from it. Instead:
|
||||
|
||||
- The text uses `MaterialTheme.colorScheme.onSurfaceVariant` through
|
||||
`MenuDefaults.itemColors(textColor = …)`, a role, with no `.copy(alpha = …)`.
|
||||
- A trailing `Icons.Outlined.Info` icon with a decided description, "Why this is
|
||||
unavailable", from the catalogue.
|
||||
- Semantics: `stateDescription = "Unavailable"` and `onClickLabel = "See why"`, so a
|
||||
screen reader says what the visual does.
|
||||
|
||||
Choosing it closes the menu and navigates to the explanation screen (D5). An
|
||||
available item behaves exactly as it does now: the confirm dialog for an admin
|
||||
change, and the direct call for **Remove from group**.
|
||||
|
||||
### D4. One function decides, and it returns reasons, not a set
|
||||
|
||||
Today `memberActions` returns `Set<MemberAction>`, which can say yes but not why not.
|
||||
It is replaced at the source by a function that returns, for each member, each
|
||||
applicable action together with an ordered list of what blocks it:
|
||||
|
||||
```kotlin
|
||||
data class MemberActionOption(
|
||||
val action: MemberAction,
|
||||
val blockers: List<MemberActionBlocker>, // empty = available
|
||||
)
|
||||
```
|
||||
|
||||
`AdminGovernance.memberActions` stays as a thin filter over it (`blockers.isEmpty()`).
|
||||
Every caller and test that relies on it, including `AdminChangesJvmTest` and
|
||||
`GovernanceGateJvmTest`, keeps passing unchanged. That is the proof the new function
|
||||
agrees with the old one where the old one had an answer.
|
||||
|
||||
The rules stay in one place, as the comment on `AdminGovernance` asks. The screen
|
||||
never decides an action itself, and neither does the explanation screen.
|
||||
|
||||
**Order of blockers.** Room-wide reasons come first, then the viewer's role, then the
|
||||
room's rules, then the member, then work in flight. The screen leads with the first
|
||||
blocker and lists the rest under it. That way a non-admin in a disbanded room hears
|
||||
"the group was disbanded" rather than "you're not an admin".
|
||||
|
||||
### D5. The explanation is a pushed screen, and it recomputes its reason
|
||||
|
||||
A new route:
|
||||
|
||||
```kotlin
|
||||
@Serializable
|
||||
data class MemberActionUnavailableRoute(
|
||||
val activeUserPublicKey: String,
|
||||
val chatRoomId: String,
|
||||
val memberPublicKey: HexKey,
|
||||
val action: MemberAction,
|
||||
) : Route()
|
||||
```
|
||||
|
||||
The route carries **what was asked**, not the answer. The screen's view model reloads
|
||||
the room and runs the same D4 function. That has three consequences:
|
||||
|
||||
- The reasons cannot be stale, and they cannot be forged by whatever built the route.
|
||||
- If the blocker clears while the screen is open, for example when a relay accepts
|
||||
the pending commit, the screen says so instead of explaining something no longer
|
||||
true.
|
||||
- The route has no list of sealed classes to serialise.
|
||||
|
||||
navigation-compose 2.9.2 serialises an `@Serializable` enum in a type-safe route. A
|
||||
route test pins this, so a regression fails in the test and not on a device.
|
||||
|
||||
It is a screen rather than a dialog because the request says "open a screen", and
|
||||
because some reasons need room. Reason 6 names who has not updated Giza. Reason 10
|
||||
explains a floor and points to the fix. A pushed screen also gets
|
||||
`NavigateBackButton`, which the desktop target needs (CLAUDE.md, "A pushed screen has
|
||||
a way back").
|
||||
|
||||
### D6. Each reason says what is in the way *and* what would change it, with the one action that helps
|
||||
|
||||
| blocker | title | what would change it | the screen's one action |
|
||||
|---|---|---|---|
|
||||
| `NoAdminsInThisRoom` | This room has no admins | Its members administer the group's admin room. Make the change there. | **Open the admin room** (when `adminRoomId` is known) |
|
||||
| `LegacyRoom` | This group uses an older format | Groups made before the current format can't change who runs them. A new group can. | — |
|
||||
| `Disbanded` | This group was disbanded | Nothing can change a disbanded group. | — |
|
||||
| `YouLeft` | You've left this group | Only members can make changes. | — |
|
||||
| `NotAnAdmin(admins)` | Only admins can do this | Ask one of the group's admins: {names}. | — |
|
||||
| `SignaturesNotRequired` | This group was made before signed changes | Who runs a group with a shared key changes only with the group's signature. This one was made before Giza asked for one, so its admins stay as they are. A new group can. | — |
|
||||
| `ShareRotationUnavailable` | Not in this version of Giza yet | Changing the admins of a group with a shared key moves a share of the key, and this version can't do that yet. | — |
|
||||
| `NotInGroupYet` | {name} isn't fully in the group | They're still being added, or they're already being removed. Try again once that has landed. | — |
|
||||
| `OnlyAdmin` | {name} is the only admin | A group always needs an admin. Make someone else an admin first. | — |
|
||||
| `BelowFloor(floor)` | A group with a shared key needs at least {floor} admins | Make someone else an admin first, then try again. | — |
|
||||
| `ChangePending` | An earlier change is still on its way | A relay hasn't accepted the last change to this group. This clears by itself. | — |
|
||||
| `OfferPending` | {name} has already been asked | They've been offered admin and haven't answered yet. | — |
|
||||
|
||||
These lines are drafts. They go into `strings.xml` in sentence case, interpolated
|
||||
with `%1$s` and never `"${…}"`, and they keep the apostrophes CLAUDE.md warns
|
||||
Compose Resources does not unescape. `StringCatalogueJvmTest` gains a case for any
|
||||
escape the new strings rely on.
|
||||
|
||||
When the screen recomputes and finds **no** blocker, it shows "You can do this now"
|
||||
and a **Back to the group** button, which pops back. It does not perform the action
|
||||
itself: the confirm dialogs and their wording live on the detail screen, and two
|
||||
copies of them would drift apart.
|
||||
|
||||
### D7. The row still opens the profile, and says so
|
||||
|
||||
Removing the chevron removes the only visual hint that the card is a target. The
|
||||
`Card` keeps its `onClick` to `ProfilePreviewRoute` and gains
|
||||
`Modifier.semantics { onClick(label = "View profile", …) }` from the catalogue, so
|
||||
assistive technology keeps the information the chevron's description used to carry.
|
||||
This also replaces one of the hardcoded `contentDescription` literals.
|
||||
|
||||
---
|
||||
|
||||
## Phase 1 — the reasons, as a pure function
|
||||
|
||||
**One day.** No UI change.
|
||||
|
||||
1. `ui/view/state/MemberAction.kt`: add `MemberActionOption` and a
|
||||
`sealed interface MemberActionBlocker` with the cases in D6. The ones that carry
|
||||
data are `NotAnAdmin(admins: Set<HexKey>)` and `BelowFloor(floor: Int)`;
|
||||
the rest are `data object`s.
|
||||
2. `managers/MemberActionPolicy.kt`, new: a pure function over a plain context, so
|
||||
every case can be tested without building an MLS group:
|
||||
|
||||
```kotlin
|
||||
data class MemberActionContext(
|
||||
val room: RoomKind, // NIP17, LEGACY, CURRENT
|
||||
val isDisbanded: Boolean,
|
||||
val hasLeft: Boolean,
|
||||
val me: HexKey,
|
||||
val admins: Set<HexKey>, // the group's, or adminAt-derived (D2)
|
||||
val members: Set<HexKey>, // holders of a leaf; empty off-CURRENT
|
||||
val isKeyed: Boolean,
|
||||
val governance: GovernanceStatus?,
|
||||
val shareRefresh: Boolean,
|
||||
val floor: Int,
|
||||
)
|
||||
|
||||
object MemberActionPolicy {
|
||||
fun options(context: MemberActionContext, rows: List<HexKey>): Map<HexKey, List<MemberActionOption>>
|
||||
}
|
||||
```
|
||||
|
||||
The function defers to `MarmotGroupPermissions` for the library's rules (D4: one
|
||||
place). It checks blockers in D4's order. It returns an entry for every row except
|
||||
`me`, plus `me` with `STEP_DOWN` only when step down is available (D1).
|
||||
3. `AdminGovernance`: add `context(group, me, floor, …)`, which builds the context
|
||||
from an `MlsGroup`. Re-express `memberActions` as
|
||||
`MemberActionPolicy.options(...)` filtered to available, with the same signature.
|
||||
|
||||
**Tests**, `MemberActionPolicyTest` (commonTest, no fixtures):
|
||||
|
||||
- one test per blocker, for each action it affects, asserting it is present and
|
||||
*first* where D4's order says it should be;
|
||||
- the D2 table: which of make/remove-as-admin appears per role, in fixed order;
|
||||
- no entry for `me` except step down;
|
||||
- **the equivalence**: `AdminChangesJvmTest` and `GovernanceGateJvmTest` run
|
||||
unchanged against the re-expressed `memberActions`.
|
||||
|
||||
## Phase 2 — the state, for every viewer and every room kind
|
||||
|
||||
**Half a day.**
|
||||
|
||||
1. `ChatRepository`/`DatabaseChatRepository`: add
|
||||
`suspend fun memberActionOptions(localChatRoom): Map<HexKey, List<MemberActionOption>>`.
|
||||
It builds the context the way `ChatRoomDetailViewModel.initiateChatRoomDetail` does
|
||||
today: group, `isDisbanded`, `leftGroupAt`, `adminFloor`, `governanceStatus`. It is
|
||||
the **one** loader both screens use, so the detail screen and the explanation
|
||||
screen cannot disagree. Give the `NO_OP` repository an empty map.
|
||||
2. `ChatRoomDetailUIState.Loaded`: replace
|
||||
`memberActions: Map<HexKey, Set<MemberAction>>` with
|
||||
`memberActions: Map<HexKey, List<MemberActionOption>>`, and fix the KDoc.
|
||||
3. `ChatRoomDetailViewModel`: drop the `group?.takeIf { canGovern }` guard and fill
|
||||
the field from the repository call for **every** room. `canGovern` stays as it is
|
||||
for disband and the other admin controls.
|
||||
|
||||
**Tests:** extend the view model's existing loaded-state tests, or add a small one, for
|
||||
a non-admin viewer (every row has options, all blocked by `NotAnAdmin`) and a NIP-17
|
||||
room (every row blocked by `NoAdminsInThisRoom`).
|
||||
|
||||
## Phase 3 — the row
|
||||
|
||||
**One day.**
|
||||
|
||||
1. `MemberActionsMenu` takes `options: List<MemberActionOption>` and two callbacks:
|
||||
`onAction(MemberAction)` for available items and
|
||||
`onExplain(MemberAction)` for the rest. Unavailable items are styled as D3 says.
|
||||
2. `ChatRoomDetailScreen`'s `trailingContent`:
|
||||
- another member → always `MemberActionsMenu`;
|
||||
- the viewer's own row → the menu when it has `STEP_DOWN`, otherwise the chevron
|
||||
(D1), with its description moved to the catalogue;
|
||||
- `onExplain` → `onNavigateToRoute(MemberActionUnavailableRoute(...))`.
|
||||
3. The card's `onClick` semantics label (D7).
|
||||
4. Strings: `why_this_is_unavailable`, `unavailable`, `see_why`, `view_profile`.
|
||||
|
||||
**Tests**, `ChatRoomMemberRowJvmTest`:
|
||||
|
||||
- update `onAllNodesWithContentDescription("Member actions").assertCountEquals(1)`. With
|
||||
both fixture rows being other members, the count is now 2, and that is the point of
|
||||
the change;
|
||||
- a non-admin viewer opens the menu on each row and sees **Make admin** and **Remove
|
||||
from group**, both marked unavailable;
|
||||
- choosing an unavailable item navigates to `MemberActionUnavailableRoute` with the
|
||||
member and the action, and opens no dialog;
|
||||
- an available item still opens "Make Nomvula an admin?" (the existing test, with the
|
||||
new state shape);
|
||||
- the viewer's own row has no menu unless step down is available;
|
||||
- tapping the row body still opens `ProfilePreviewRoute`, as both existing tests
|
||||
require.
|
||||
|
||||
## Phase 4 — the explanation screen
|
||||
|
||||
**Two days.**
|
||||
|
||||
1. `routes/MemberActionUnavailableRoute.kt` (D5), and its `composable<…>` in
|
||||
`GizaNavHost.kt`, next to `ProfilePreviewRoute`. The host passes
|
||||
`popBackStack()` as `onNavigateBack`, and passes `onNavigateToRoute` for **Open the
|
||||
admin room**.
|
||||
2. `MemberActionUnavailableViewModel`: loads the room, calls
|
||||
`chatRepository.memberActionOptions`, picks the option for `(member, action)`, and
|
||||
exposes:
|
||||
|
||||
```kotlin
|
||||
sealed interface MemberActionUnavailableUIState {
|
||||
data object Loading
|
||||
data class Error(val message: String) // room or member gone
|
||||
data class Blocked(val memberName: String, val action: MemberAction,
|
||||
val blockers: List<MemberActionBlocker>, val adminNames: …, val adminRoomId: String?)
|
||||
data class NowAvailable(val memberName: String, val action: MemberAction)
|
||||
}
|
||||
```
|
||||
|
||||
It re-runs on `observeSharesInputs(chatRoomId)` and on a room change, so a blocker
|
||||
that clears while the screen is open is reflected there (D5).
|
||||
3. `MemberActionUnavailableScreen`:
|
||||
- `TopAppBar` titled with the action ("Make Nomvula an admin"), with
|
||||
`NavigateBackButton(onNavigateBack)`;
|
||||
- content root `Modifier.padding(innerPadding).readableContent()`;
|
||||
- `ScreenStateTransition` over the `when`, which is the composable's whole body
|
||||
(CLAUDE.md);
|
||||
- `LoadingDataIndicator`, `ErrorState(onRetry = viewModel::reload)`, and the two
|
||||
loaded states. In `Blocked`, the first blocker's title is `headlineSmall` with
|
||||
its body and its D6 action below. Any further blockers follow as a list under
|
||||
"Also in the way". `NowAvailable` shows the D6 "You can do this now" layout;
|
||||
- spacing only from `MaterialTheme.spacing` semantic names, and colour only from
|
||||
roles;
|
||||
- a leading icon per blocker family (lock for role, group for room, schedule for
|
||||
transient), each `Decorative` because the title beside it says the same thing.
|
||||
4. Strings: every D6 title and body, "Also in the way", "You can do this now",
|
||||
"Back to the group", "Open the admin room".
|
||||
|
||||
**Tests**, `MemberActionUnavailableScreenJvmTest`, rendered the way
|
||||
`ChatRoomMemberRowJvmTest` renders (`runDesktopComposeUiTest`, `GizaTheme`):
|
||||
|
||||
- each blocker renders its title and body, with names and the floor interpolated;
|
||||
- **Open the admin room** navigates to the admin room's route and appears only for
|
||||
`NoAdminsInThisRoom` with a known `adminRoomId`;
|
||||
- two blockers: the first leads and the second is under "Also in the way";
|
||||
- `NowAvailable` shows its message and **Back to the group** calls `onNavigateBack`;
|
||||
- the back button exists (desktop has no system back);
|
||||
- a route round-trip test: `MemberActionUnavailableRoute` encodes and decodes with
|
||||
each `MemberAction` (D5's pin).
|
||||
|
||||
## Phase 5 — reasons about work in flight
|
||||
|
||||
**One day.** These two need a query each, and they change without the group's state
|
||||
changing, so they ship after the screen works for the eight structural reasons.
|
||||
|
||||
1. `ChangePending`: the repository asks `engine.gate.canPrepareLocalCommit(routingId)`
|
||||
when it builds the context. Two cases: a room with no live engine group, which is
|
||||
not this blocker, and a gate that clears, which the explanation screen's observer
|
||||
has to see.
|
||||
2. `OfferPending`: a `PromotionManager` query for an open offer *from* this account
|
||||
*to* the member. Today `pendingOffer` answers only for an offer *to* `me`, so this
|
||||
is a new query over the same rows.
|
||||
3. Both go last in D4's order, and both say "this clears by itself".
|
||||
|
||||
**Tests:** policy cases for both. A repository-level test with a gate held by an
|
||||
unconfirmed commit shows `ChangePending`, and confirming the commit clears it.
|
||||
|
||||
## Phase 6 — docs and the audits
|
||||
|
||||
**Half a day.**
|
||||
|
||||
- Set this note's status line to built, with any choice the build made differently.
|
||||
- Add an entry in [README.md](./README.md).
|
||||
- In [member-admin-promotion.md](./member-admin-promotion.md) Phase 11, add a line
|
||||
pointing here: its "the view model hides an action that would break [the floor] and
|
||||
says why" (D8) is now done by explaining instead of hiding.
|
||||
- Run `./gradlew :composeApp:m3Audit`. It must stay at **0** spacing `.dp`, **0**
|
||||
hardcoded colours, **0** title-case strings, **0** unguarded `.clickable` and **0**
|
||||
untriaged `contentDescription = null`. The two literals this work removes ("View
|
||||
profile" on the chevron, and the row's implicit one) may lower the reported count
|
||||
of literals in composables.
|
||||
- `./gradlew check`, which also runs the brand and wallet audits. The new strings say
|
||||
Giza, never Bennu, and none of them mentions a wallet.
|
||||
|
||||
---
|
||||
|
||||
## Ship order
|
||||
|
||||
| commit | phases | users see |
|
||||
|---|---|---|
|
||||
| 1 | 1 | nothing; the rules gain reasons, with old behaviour pinned |
|
||||
| 2 | 2, 3, 4 | the menu on every other member's row; every unavailable action explains itself |
|
||||
| 3 | 5 | "an earlier change is still on its way" and "already asked" instead of a snackbar after the fact |
|
||||
| 4 | 6 | — |
|
||||
|
||||
Phases 2, 3 and 4 ship together. A menu whose unavailable items navigate to a route
|
||||
that does not exist yet is worse than today's chevron.
|
||||
|
||||
## Checking the work
|
||||
|
||||
```bash
|
||||
./gradlew :composeApp:compileDebugKotlinAndroid :composeApp:jvmTest
|
||||
```
|
||||
|
||||
```bash
|
||||
./gradlew check
|
||||
```
|
||||
|
||||
By hand, on the desktop target, which has no system back:
|
||||
|
||||
1. As a **non-admin** in a robust group: every other row has the menu, both items are
|
||||
marked, and each opens a screen naming the admins. Back returns to the group.
|
||||
2. As an **admin** of a robust group at its floor of three: **Remove as admin** on
|
||||
another admin explains the floor. Make a fourth member an admin. Once the change
|
||||
lands, the open explanation screen switches to "You can do this now".
|
||||
3. As an admin of a keyed room made before signed changes: **Make admin** explains
|
||||
that the group keeps its admins. In one born needing the signature, with four
|
||||
admins, your own row offers **Step down as admin**, and the request goes to
|
||||
another admin.
|
||||
4. In the group's **NIP-17 room**: every row explains that the room has no admins, and
|
||||
**Open the admin room** goes there.
|
||||
5. With **TalkBack**/VoiceOver: an unavailable item reads as "Make admin, unavailable,
|
||||
double-tap to see why", and the row body reads as "View profile".
|
||||
|
||||
## Estimate
|
||||
|
||||
| phase | size |
|
||||
|---|---|
|
||||
| 1 — the reasons | one day |
|
||||
| 2 — the state | half a day |
|
||||
| 3 — the row | one day |
|
||||
| 4 — the explanation screen | two days |
|
||||
| 5 — work in flight | one day |
|
||||
| 6 — docs and audits | half a day |
|
||||
|
||||
About six days. Nothing waits on marmot-kmp or mls-kmp; every rule it reports already
|
||||
exists in this repository or in `MarmotGroupPermissions`.
|
||||
|
||||
## Open questions
|
||||
|
||||
- **Q1. "View profile" in the menu.** D7 relies on the row body. Adding **View
|
||||
profile** as the menu's first item would make the menu a complete list of what
|
||||
can be done to a member, at the cost of a duplicate target.
|
||||
|
||||
## Out of scope
|
||||
|
||||
- **Retry enrollment** and **Rotate shares** as row actions (member-admin-promotion's
|
||||
Phase 11 table). They are not `MemberAction`s. Rotation is already offered from the
|
||||
Shares section, and enrollment retries are driven by the ceremony.
|
||||
- Performing an action from the explanation screen (D6).
|
||||
- Direct-message rooms, whose detail screen has no member rows.
|
||||
Reference in new issue
Block a user