diff --git a/composeApp/src/commonMain/composeResources/values/strings.xml b/composeApp/src/commonMain/composeResources/values/strings.xml
index a559eb54..bb343c97 100644
--- a/composeApp/src/commonMain/composeResources/values/strings.xml
+++ b/composeApp/src/commonMain/composeResources/values/strings.xml
@@ -117,6 +117,8 @@
Step down as admin?
You stay in the group as a member. Only an admin can make you one again.
Step down
+ You stay in the group as a member. Another admin's Giza proposes it for the group to sign, and your share of the group's key is rotated away once it's done.
+ Asked the other admins; it happens once the group signs it
Sent; it takes effect once a relay accepts it
Leave the group?
You're an admin, so you'll step down first, then leave once a relay accepts it.
@@ -125,9 +127,6 @@
Make admin and leave
Disband group instead
Changes to who is in this group need the group's signature. It always keeps at least %1$d admins.
- Require the group's signature for changes
- From then on, adding or removing a member, or changing who the admins are, is proposed and has to be signed by the group before it happens.
- Before changes can need the group's signature, %1$s need to update Giza.
They'll be asked to accept, then the group signs it, and they'll hold a share of the group's key and be asked to approve its changes.
Once the group signs it, they stay in the group as a member and their share of the group's key is rotated away.
Asked; they become an admin once they accept and the group signs it
@@ -135,7 +134,6 @@
Accept
Accepted; the group signs it next
Proposed; it happens once the group signs it
- Sent; changes will need the group's signature once a relay accepts it
Stepping down; you'll leave once a relay accepts it
Remove from group
Disband group
@@ -567,9 +565,8 @@
Only members of a group can change it.
Only admins can do this
Ask one of the group's admins: %1$s.
- The group has to sign changes first
- In a group with a shared key, a change to who runs it needs the group's signature. An admin can switch that on from the group's page.
- That waits until %1$s update Giza.
+ This group was made before signed changes
+ 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.
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 of Giza can't do that yet.
%1$s isn't fully in the group
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/dao/MarmotOutboundDao.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/dao/MarmotOutboundDao.kt
index 7f2378a7..25955812 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/dao/MarmotOutboundDao.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/dao/MarmotOutboundDao.kt
@@ -69,7 +69,6 @@ import mobi.giza.compose.ExperimentalFeatures
import mobi.giza.compose.managers.GovernanceGate
import mobi.giza.compose.managers.GovernanceManager
import mobi.giza.compose.managers.GovernanceMarker
-import mobi.giza.compose.managers.GovernanceSupport
import mobi.giza.compose.managers.ChronicleManager
import mobi.giza.compose.managers.MarmotGroupFactory
import mobi.giza.compose.managers.MarmotInboundManager
@@ -984,13 +983,16 @@ abstract class MarmotOutboundDao(
// away once it lands (docs/member-admin-promotion.md, Phase 9).
if (AdminGovernance.isKeyedRoom(group)) {
check(AdminGovernance.keyedChangesAllowed(group)) { KEYED_ROOM_REFUSAL }
- check(adminPublicKey != localChatRoom.chatRoom.userPublicKey) {
- "In a group with a shared key, another admin removes you as admin, so the group can rotate your share away"
- }
val floor = AdminGovernance.adminFloor(database, localChatRoom.chatRoom.id, group)
if (!AdminGovernance.keepsFloor(group, adminPublicKey, floor)) {
throw IllegalStateException("A group with a shared key needs at least $floor admins. Make someone else an admin first")
}
+ // Your own: asked of another admin, whose device proposes it and then
+ // rotates your share away -- a rotation's proposer has to keep a share.
+ if (adminPublicKey == localChatRoom.chatRoom.userPublicKey) {
+ PromotionManager.requestStepDown(database, localChatRoom, adminPublicKey)
+ return
+ }
val admins = group.currentAdminIdentities()
GovernanceManager.propose(
database, localChatRoom, localChatRoom.chatRoom.userPublicKey,
@@ -1060,42 +1062,6 @@ abstract class MarmotOutboundDao(
}
}
- /**
- * Makes a keyed room's changes need the group's signature from the next epoch:
- * one ordinary commit adding [GovernanceMarker]'s line to the profile
- * description, with the floor the room's quorum sets. It is the room's last bare
- * commit, and every device that applies it enforces the rule from the state it
- * just applied. docs/member-admin-promotion.md, D4 and Phase 4b.
- *
- * Refused while any member has not said their device can follow signed commits
- * -- they would be left in a different group by the first change -- and while
- * the room has fewer admins than the floor it would set.
- */
- @Transaction
- open suspend fun requireSignatures(localChatRoom: LocalChatRoom) {
- val group = governedGroup(localChatRoom)
- val roomId = localChatRoom.chatRoom.id
- check(AdminGovernance.isKeyedRoom(group)) { "Only a group with a shared key can require its signature" }
- if (GovernanceGate.isGoverned(group)) return
- val missing = GovernanceSupport.missing(database, roomId, group)
- if (missing.isNotEmpty()) {
- throw IllegalStateException("Waiting for ${missing.map { memberName(it) }.sorted().joinToString()} to update Giza")
- }
- val floor = AdminGovernance.adminFloor(database, roomId, group)
- val admins = group.currentAdminIdentities() intersect AdminGovernance.members(group)
- check(admins.size >= floor) { "A group with a shared key needs at least $floor admins first" }
-
- publishGatedCommit(localChatRoom) { manager, id ->
- val live = manager.getGroup(id) ?: throw MarmotMissingChatGroupException("No live group for $id")
- val profile = live.currentGroupState().profile ?: throw IllegalStateException("The group has no profile to record the rule in")
- manager.stageAppDataUpdate(
- id,
- GroupProfileV1.COMPONENT_ID,
- GroupProfileV1(profile.name, GovernanceMarker.describe(profile.description, floor)).encode(),
- )
- }
- }
-
/** Whether [memberPublicKey] holds a live share of the room's key, with rotation on. */
private suspend fun holdsLiveShare(localChatRoom: LocalChatRoom, memberPublicKey: HexKey): Boolean =
ExperimentalFeatures.shareRefresh &&
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/dao/NostrDao.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/dao/NostrDao.kt
index 54941a19..b18d349a 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/dao/NostrDao.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/dao/NostrDao.kt
@@ -7,8 +7,6 @@ import com.vitorpamplona.marmot.GroupEventResult
import com.vitorpamplona.marmot.groups.MarmotGroupPolicy
import com.vitorpamplona.marmot.groups.currentAdminIdentities
import mobi.giza.compose.managers.GovernanceGate
-import mobi.giza.compose.managers.GovernanceSupport
-import mobi.giza.compose.nostr.frost.GovernanceSupportEvent
import mobi.giza.compose.nostr.frost.GovernanceEvents
import mobi.giza.compose.nostr.frost.GovernanceCarrierEvent
import mobi.giza.compose.nostr.frost.OwnCommitEvent
@@ -1696,16 +1694,6 @@ abstract class NostrDao(
// A change to a governed room, inside the group's signature or,
// for a member's own leave, its committer's. Checked, and its
// commit applied, only here (docs/member-admin-promotion.md).
- // Another member says their device follows signed commits:
- // this one says so back, once, so that a member who never
- // opens the room's screen is still counted (Phase 4b).
- innerEvent.kind == GovernanceSupportEvent.KIND ->
- if (localChatRoom.chatRoom.marmotProfile() == MarmotProfile.CURRENT) {
- database.marmotEngine.groupFor(localChatRoom.routingId)?.let { group ->
- GovernanceSupport.announce(database, localChatRoom.chatRoom.id, group, activeKeyPair.pubKey.toHex())
- }
- }
-
innerEvent.kind == OwnCommitEvent.KIND ->
admitEnvelopedCommit(localChatRoom, innerEvent, activeKeyPair)
innerEvent.kind == GovernanceCarrierEvent.KIND ->
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/repository/DatabaseChatRepository.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/repository/DatabaseChatRepository.kt
index 236108e7..db1e7a11 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/repository/DatabaseChatRepository.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/repository/DatabaseChatRepository.kt
@@ -14,7 +14,6 @@ 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.GovernanceSupport
import mobi.giza.compose.managers.MemberActionContext
import mobi.giza.compose.managers.MemberActionPolicy
import mobi.giza.compose.managers.MemberActionRoom
@@ -722,11 +721,7 @@ class DatabaseChatRepository(
if (room.chatRoom.marmotProfile() != MarmotProfile.CURRENT) return null
val group = database.marmotEngine.groupFor(room.routingId) ?: return null
if (!AdminGovernance.isKeyedRoom(group)) return null
- GovernanceGate.minimumAdmins(group)?.let { return GovernanceStatus.Governed(it) }
- if (room.chatRoom.leftGroupAt == null) GovernanceSupport.announce(database, chatRoomId, group, room.chatRoom.userPublicKey)
- val missing = GovernanceSupport.missing(database, chatRoomId, group)
- return if (missing.isEmpty()) GovernanceStatus.Ready(AdminGovernance.adminFloor(database, chatRoomId, group))
- else GovernanceStatus.Waiting(missing)
+ return GovernanceGate.minimumAdmins(group)?.let { GovernanceStatus.Governed(it) }
}
override suspend fun memberActionOptions(localChatRoom: LocalChatRoom): Map> {
@@ -752,8 +747,6 @@ class DatabaseChatRepository(
val engine = database.marmotEngine
context.copy(
hasLeft = hasLeft,
- // Only asked when it is the answer: a keyed room not yet governed.
- waitingOn = if (context.isKeyed && !context.governed) GovernanceSupport.missing(database, chatRoom.id, group) else emptySet(),
// 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.
@@ -766,10 +759,6 @@ class DatabaseChatRepository(
return MemberActionPolicy.options(context, rows)
}
- override suspend fun requireSignatures(localChatRoom: LocalChatRoom) {
- database.marmotOutboundDao().requireSignatures(localChatRoom)
- }
-
override suspend fun promoteMember(localChatRoom: LocalChatRoom, memberPublicKey: HexKey) {
database.marmotOutboundDao().promote(localChatRoom, memberPublicKey)
}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/AdminGovernance.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/AdminGovernance.kt
index e5eb7a32..8fa62e48 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/AdminGovernance.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/AdminGovernance.kt
@@ -4,7 +4,9 @@ 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
+import com.vitorpamplona.quartz.nip01Core.core.toHexKey
import mobi.giza.compose.ExperimentalFeatures
import mobi.giza.compose.database.GizaDatabase
import mobi.giza.compose.database.model.types.DkgRitualStage
@@ -97,6 +99,35 @@ object AdminGovernance {
fun keyedChangesAllowed(group: MlsGroup): Boolean =
isKeyedRoom(group) && GovernanceGate.isGoverned(group) && ExperimentalFeatures.shareRefresh
+ /**
+ * Whether [me] may ask to stop being an admin of keyed room [group]. They cannot
+ * demote themselves: a demotion's proposer starts the rotation that takes their
+ * share away, and the proposer has to keep a share. So they ask, and
+ * [stepDownProposer]'s device proposes it. Never below [floor], and only while
+ * another admin is there to ask.
+ */
+ fun canAskToStepDown(group: MlsGroup, me: HexKey, floor: Int): Boolean =
+ keyedChangesAllowed(group) &&
+ me in group.currentAdminIdentities() &&
+ keepsFloor(group, me, floor) &&
+ stepDownProposer(group, me) != null
+
+ /**
+ * The admin whose device proposes [requester]'s step-down: the one in the lowest
+ * leaf, [requester] apart. Read off the group's state, so every device names the
+ * same one and only one of them proposes -- two proposals at one epoch would be
+ * two commits the library cannot settle for their authors (docs/marmot-v2.md,
+ * Phase 8). Null when nobody else is an admin.
+ */
+ fun stepDownProposer(group: MlsGroup, requester: HexKey): HexKey? {
+ val admins = group.currentAdminIdentities() - requester
+ return group.members()
+ .sortedBy { (leafIndex, _) -> leafIndex }
+ .firstNotNullOfOrNull { (_, leaf) ->
+ (leaf.credential as? Credential.Basic)?.identity?.toHexKey()?.takeIf { it in admins }
+ }
+ }
+
/**
* What [MemberActionPolicy] reads, from [group]'s state: its admins, its
* members, whether it is keyed and needs the group's signature, and [floor].
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/GovernanceFollowThrough.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/GovernanceFollowThrough.kt
index 9bdf87a7..f832f01f 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/GovernanceFollowThrough.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/GovernanceFollowThrough.kt
@@ -37,7 +37,7 @@ object GovernanceFollowThrough {
suspend fun observe(database: GizaDatabase, keyPair: KeyPair) {
combine(
database.governanceProposalDao().observeAll(),
- database.marmotInnerEventDao().observeCountByKinds(listOf(PromotionEvents.OFFER, PromotionEvents.ACCEPT, PromotionEvents.HANDOVER)),
+ database.marmotInnerEventDao().observeCountByKinds(listOf(PromotionEvents.OFFER, PromotionEvents.ACCEPT, PromotionEvents.HANDOVER, PromotionEvents.STEP_DOWN)),
database.groupSignedEventDao().observeByKind(GroupKeyStateEvent.KIND),
) { _, _, _ -> Unit }
.conflate()
@@ -71,6 +71,9 @@ object GovernanceFollowThrough {
announce(database, offer.chatRoomId, me, "Couldn't ask the group to make them an admin: ${it.message}")
}
}
+ // An admin who asked to step down, when this device is the one to propose it.
+ PromotionManager.followStepDowns(database, me)
+
PromotionManager.handoversOwed(database).forEach { proposal ->
runCatching { PromotionManager.handover(database, proposal, me) }.onFailure {
if (it is CancellationException) throw it
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/GovernanceMarker.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/GovernanceMarker.kt
index 90453b3a..3c3c0ef9 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/GovernanceMarker.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/GovernanceMarker.kt
@@ -5,8 +5,12 @@ package mobi.giza.compose.managers
* group's signature, and how few admins it may ever have. docs/member-admin-promotion.md,
* D4 and D8.
*
- * In the group's state, so every device that applies the commit adding it enforces
- * the rule from the same epoch, and reads the same floor: a floor each device worked
+ * Written into a keyed room's epoch-0 description when it is made
+ * (`MarmotGroupCreation.createFor`), so there is no later moment it is switched on
+ * and nobody it waits for; docs/remove-convenient-groups.md, "After the build".
+ *
+ * In the group's state, so every device enforces the rule from the same epoch, and
+ * reads the same floor: a floor each device worked
* out for itself from the ceremony it happens to hold would differ between a founder
* and a member welcomed later, and the two would disagree about a commit. The
* description is the one free text the current profile offers, which is why
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/GovernanceSupport.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/GovernanceSupport.kt
deleted file mode 100644
index 88b4469e..00000000
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/GovernanceSupport.kt
+++ /dev/null
@@ -1,62 +0,0 @@
-package mobi.giza.compose.managers
-
-import com.vitorpamplona.mls.group.MlsGroup
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.vitorpamplona.quartz.nip01Core.crypto.EventHasher
-import kotlin.time.Clock
-import kotlin.time.Instant
-import mobi.giza.compose.database.GizaDatabase
-import mobi.giza.compose.database.model.MarmotInnerEvent
-import mobi.giza.compose.nostr.frost.GovernanceSupportEvent
-
-/**
- * Who in a keyed room has said their device follows signed commits, and this
- * device saying it. docs/member-admin-promotion.md, D4 and Phase 4b.
- *
- * The rule cannot be switched on while anybody in the room would be left behind
- * by it: a device that does not know it applies the bare commits Giza drops and
- * reads none of the envelopes, and is in a different group from the first change.
- * So each device says, once per room, that it can follow -- and says it back when
- * it hears another say it, which is how a member who never opens the room's screen
- * still gets counted.
- */
-object GovernanceSupport {
-
- /** The accounts that have said, in [chatRoomId], that they follow signed commits. */
- suspend fun supporters(database: GizaDatabase, chatRoomId: String): Set =
- database.marmotInnerEventDao().getByChatRoomAndKinds(chatRoomId, listOf(GovernanceSupportEvent.KIND))
- .filter { row -> row.tags.any { it.size >= 2 && it[0] == GovernanceSupportEvent.VERSION_TAG && it[1] == GovernanceSupportEvent.VERSION } }
- .map { it.publicKey }
- .toSet()
-
- /** The members of [group] who have not said it yet. */
- suspend fun missing(database: GizaDatabase, chatRoomId: String, group: MlsGroup): Set =
- AdminGovernance.members(group) - supporters(database, chatRoomId)
-
- /**
- * Says, for [me], that this device follows signed commits in [chatRoomId] -- once:
- * nothing happens when it already has. Only in a keyed room, which is the only
- * kind the rule can be switched on in. Returns whether it said it now.
- */
- suspend fun announce(database: GizaDatabase, chatRoomId: String, group: MlsGroup, me: HexKey): Boolean {
- if (!AdminGovernance.isKeyedRoom(group)) return false
- if (me in supporters(database, chatRoomId)) return false
- val tags = GovernanceSupportEvent.assembleTags(chatRoomId)
- val createdAt = Clock.System.now().epochSeconds
- val id = EventHasher.hashId(pubKey = me, createdAt = createdAt, kind = GovernanceSupportEvent.KIND, tags = tags, content = "")
- // Unsent: the outbound worker puts an inner event with no group event behind
- // it into the room, as it does for every manager's messages.
- database.marmotInnerEventDao().upsert(
- MarmotInnerEvent(
- id = id,
- publicKey = me,
- kind = GovernanceSupportEvent.KIND,
- createdAt = Instant.fromEpochSeconds(createdAt),
- tags = tags,
- content = "",
- chatRoomId = chatRoomId,
- )
- )
- return true
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/MarmotGroupCreation.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/MarmotGroupCreation.kt
index 08663efc..77b933e3 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/MarmotGroupCreation.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/MarmotGroupCreation.kt
@@ -109,6 +109,7 @@ object MarmotGroupCreation {
name: String,
purpose: String,
adminPublicKeys: Set,
+ minimumAdmins: Int?,
userPublicKey: HexKey,
keyPair: KeyPair,
path: List = SharedKeyDerivation.MARMOT_ADMIN_GROUP_PATH,
@@ -133,7 +134,18 @@ object MarmotGroupCreation {
keyPackage?.let { publicKey to it }
}
+ // Born needing the group's signature for every change, with the floor of
+ // admins it may never go under: there is no later moment to switch the rule
+ // on, and nobody it waits for. Founding comes before it in effect -- the
+ // founding invite is the creator's commit while it is the room's only member,
+ // which no other device ever processes. docs/remove-convenient-groups.md,
+ // "After the build", and docs/member-admin-promotion.md, D7 and D8.
+ //
+ // [minimumAdmins] null is a room without the rule: one made before every keyed
+ // room was born with it, which tests of a group's mechanics still model.
+ // [createFor], the app's one caller, always passes the ceremony's.
val description = SharedKeyDerivation.describe(purpose = purpose, path = path)
+ .let { if (minimumAdmins == null) it else GovernanceMarker.describe(it, minimumAdmins) }
// On whichever profile new rooms are on. The room id is the derived key
// either way; on the current profile the group's routing address is minted
@@ -259,6 +271,7 @@ object MarmotGroupCreation {
name = CeremonyFollowThrough.roomName(ceremony),
purpose = CeremonyFollowThrough.roomPurpose(ceremony),
adminPublicKeys = founders,
+ minimumAdmins = Quorum.minimumAdmins(ceremony.threshold),
userPublicKey = ceremony.userPublicKey,
keyPair = keyPair,
parentChatRoomId = parentChatRoomId,
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/MemberActionPolicy.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/MemberActionPolicy.kt
index 1a4de5dd..fab025b6 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/MemberActionPolicy.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/MemberActionPolicy.kt
@@ -36,10 +36,8 @@ data class MemberActionContext(
val isDisbanded: Boolean = false,
val hasLeft: Boolean = false,
val isKeyed: Boolean = false,
- /** Whether a keyed room's changes need the group's signature. */
+ /** Whether a keyed room's changes need the group's signature; one made before that never will. */
val governed: Boolean = false,
- /** Whose devices a keyed room is waiting on before it can need that signature. */
- val waitingOn: Set = emptySet(),
/** `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. */
@@ -77,12 +75,21 @@ object MemberActionPolicy {
}.toMap()
private fun stepDown(context: MemberActionContext): MemberActionOption? {
+ val me = context.me
val open = context.room == MemberActionRoom.CURRENT &&
!context.isDisbanded &&
!context.hasLeft &&
- // In a keyed room another admin removes you, so the group can rotate your share away.
- !context.isKeyed &&
- MarmotGroupPermissions.canDemote(context.admins, context.members, context.me, context.me)
+ 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
}
@@ -100,7 +107,7 @@ object MemberActionPolicy {
)
val keyed = if (context.isKeyed) {
listOfNotNull(
- MemberActionBlocker.SignaturesNotRequired(context.waitingOn).takeUnless { context.governed },
+ MemberActionBlocker.SignaturesNotRequired.takeUnless { context.governed },
MemberActionBlocker.ShareRotationUnavailable.takeUnless { context.shareRefresh },
)
} else {
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/PromotionManager.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/PromotionManager.kt
index b429209d..91b3a6c0 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/PromotionManager.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/PromotionManager.kt
@@ -179,6 +179,69 @@ object PromotionManager {
announce(database, localChatRoom.chatRoom.id, me, ChatMessage.TYPE_ADMIN_OFFERED, "You accepted becoming an admin. The group signs it next")
}
+ // ---- stepping down, asked of another admin ---------------------------------------------------------------------
+
+ /**
+ * Asks, as [me], to stop being an admin of keyed room [localChatRoom]. An admin
+ * cannot propose their own demotion there: the rotation that takes their share
+ * away is started by the demotion's proposer, who has to keep a share. So the
+ * request goes into the room, and [followStepDowns] on
+ * [AdminGovernance.stepDownProposer]'s device proposes it, as that admin pressing
+ * **Remove as admin** would. Nothing is committed here.
+ */
+ suspend fun requestStepDown(database: GizaDatabase, localChatRoom: LocalChatRoom, me: HexKey): HexKey {
+ val group = database.marmotEngine.groupFor(localChatRoom.routingId)
+ ?: throw MarmotMissingChatGroupException("No live group for ${localChatRoom.chatRoom.id}")
+ check(me in group.currentAdminIdentities()) { "You're not an admin of this group" }
+ check(AdminGovernance.stepDownProposer(group, me) != null) { "You're the only admin. Make someone else an admin first" }
+ val id = send(database, localChatRoom.chatRoom.id, me, PromotionEvents.STEP_DOWN, "", PromotionEvents.stepDownTags(localChatRoom.chatRoom.id))
+ announce(database, localChatRoom.chatRoom.id, me, ChatMessage.TYPE_ADMIN_OFFERED, "You asked to step down as admin. The group signs it next")
+ return id
+ }
+
+ /**
+ * Takes up the step-down requests whose [AdminGovernance.stepDownProposer] is
+ * [me]: proposes each one's demotion for the group's signature, through the same
+ * `demote` an admin's own **Remove as admin** runs, so its rotation follows the
+ * same way. Run by `GovernanceFollowThrough` whenever a request arrives, and on
+ * start.
+ *
+ * A request is used once. The proposer's device drops it after proposing, or
+ * after saying in the room why it could not; every device drops one whose
+ * requester is no longer an admin, so a member made an admin again later is not
+ * stepped down by what they asked the first time.
+ *
+ * @return how many demotions were proposed.
+ */
+ suspend fun followStepDowns(database: GizaDatabase, me: HexKey): Int {
+ var proposed = 0
+ database.marmotInnerEventDao().getByKinds(listOf(PromotionEvents.STEP_DOWN)).forEach { request ->
+ val requester = request.publicKey
+ val room = database.chatRoomDao().findChatRoomById(request.chatRoomId)
+ val group = room?.let { database.marmotEngine.groupFor(it.routingId) }
+ if (room == null || group == null || requester !in group.currentAdminIdentities()) {
+ database.marmotInnerEventDao().deleteById(request.id)
+ return@forEach
+ }
+ if (room.chatRoom.userPublicKey != me || AdminGovernance.stepDownProposer(group, requester) != me) return@forEach
+
+ val failure = runCatching { database.marmotOutboundDao().demote(room, requester) }.exceptionOrNull()
+ if (failure is kotlinx.coroutines.CancellationException) throw failure
+ database.marmotInnerEventDao().deleteById(request.id)
+ if (failure == null) {
+ proposed++
+ logger.i("Proposed ${requester.take(8)}…'s step-down in ${room.chatRoom.id}")
+ } else {
+ logger.w("Couldn't propose ${requester.take(8)}…'s step-down: ${failure.message}")
+ announce(
+ database, room.chatRoom.id, me, ChatMessage.TYPE_CHANGE_NOT_APPLIED,
+ "Couldn't ask the group to remove ${nameOf(database, requester)} as admin, as they asked: ${failure.message}",
+ )
+ }
+ }
+ return proposed
+ }
+
// ---- 3. the proposal, by the device that offered ---------------------------------------------------------------
/** This device's offers that have been accepted and not yet proposed, with their acceptance. */
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/nostr/frost/GovernanceEvents.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/nostr/frost/GovernanceEvents.kt
index f3b6dae0..f41e5e5d 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/nostr/frost/GovernanceEvents.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/nostr/frost/GovernanceEvents.kt
@@ -27,8 +27,8 @@ import com.vitorpamplona.quartz.nip01Core.tags.dTag.DTag
*/
object GovernanceEvents {
val ALL: Set = setOf(
- GovernanceStatementEvent.KIND, OwnCommitEvent.KIND, GovernanceSupportEvent.KIND, GovernanceCarrierEvent.KIND,
- PromotionEvents.OFFER, PromotionEvents.ACCEPT, PromotionEvents.HANDOVER,
+ GovernanceStatementEvent.KIND, OwnCommitEvent.KIND, GovernanceCarrierEvent.KIND,
+ PromotionEvents.OFFER, PromotionEvents.ACCEPT, PromotionEvents.HANDOVER, PromotionEvents.STEP_DOWN,
)
/** The epoch tag every envelope names: the epoch its commit is built at. */
@@ -66,24 +66,6 @@ object OwnCommitEvent {
arrayOf(DTag.assemble(chatRoomId), arrayOf(GovernanceEvents.EPOCH_TAG, epoch.toString()))
}
-/**
- * A member's word that their device applies signed commits, said once per room so
- * the room can tell when the rule can be switched on without leaving anybody behind.
- * Signed by the member's account. docs/member-admin-promotion.md, Phase 4b.
- */
-object GovernanceSupportEvent {
- val KIND: Kind = 30372
-
- const val VERSION_TAG = "governance"
- const val VERSION = "signed-commits/v1"
-
- fun assembleTags(chatRoomId: HexKey): Array> =
- arrayOf(DTag.assemble(chatRoomId), arrayOf(VERSION_TAG, VERSION))
-
- fun supports(event: Event): Boolean =
- event.kind == KIND && event.tags.any { it.size >= 2 && it[0] == VERSION_TAG && it[1] == VERSION }
-}
-
/**
* A member sending the group's signed statement into the room: its content is the
* statement, as signed. The carrier vouches for nothing -- the statement inside is
@@ -122,6 +104,15 @@ object PromotionEvents {
val ACCEPT: Kind = 30375
val HANDOVER: Kind = 30376
+ /**
+ * An admin of a keyed room asking to be removed as one. They cannot propose it
+ * themselves: the rotation that follows a demotion is started by its proposer,
+ * and has to be started by somebody who keeps a share. So one remaining admin's
+ * device proposes it for them (`PromotionManager.followStepDowns`). Signed by the
+ * admin stepping down, whom MLS authenticates as its sender.
+ */
+ val STEP_DOWN: Kind = 30377
+
const val TARGET_TAG = "target"
const val OFFER_TAG = "offer"
const val HOST_KEY_TAG = "host"
@@ -135,5 +126,7 @@ object PromotionEvents {
fun handoverTags(chatRoomId: HexKey, target: HexKey): Array> =
arrayOf(DTag.assemble(chatRoomId), arrayOf(TARGET_TAG, target))
+ fun stepDownTags(chatRoomId: HexKey): Array> = arrayOf(DTag.assemble(chatRoomId))
+
fun value(tags: Array>, name: String): String? = tags.firstOrNull { it.size >= 2 && it[0] == name }?.get(1)
}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/repository/ChatRepository.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/repository/ChatRepository.kt
index 3b348614..9231f344 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/repository/ChatRepository.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/repository/ChatRepository.kt
@@ -330,8 +330,6 @@ interface ChatRepository {
*/
suspend fun memberActionOptions(localChatRoom: LocalChatRoom): Map>
- /** Makes a keyed room's changes need the group's signature. Throws with words a person can act on. */
- suspend fun requireSignatures(localChatRoom: LocalChatRoom)
/**
* Removes [memberPublicKey] from a current-profile room this device administers:
@@ -640,8 +638,6 @@ interface ChatRepository {
override suspend fun memberActionOptions(localChatRoom: LocalChatRoom): Map> = emptyMap()
- override suspend fun requireSignatures(localChatRoom: LocalChatRoom) = Unit
-
override suspend fun promoteMember(localChatRoom: LocalChatRoom, memberPublicKey: HexKey) = Unit
override suspend fun demoteMember(localChatRoom: LocalChatRoom, adminPublicKey: HexKey) = Unit
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ChatRoomDetailScreen.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ChatRoomDetailScreen.kt
index 8c968e80..794b17d1 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ChatRoomDetailScreen.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ChatRoomDetailScreen.kt
@@ -91,8 +91,8 @@ import mobi.giza.compose.ui.theme.spacing
import mobi.giza.compose.resources.couldn_t_leave_the_group
import mobi.giza.compose.resources.admin_change_requested
import mobi.giza.compose.resources.stepping_down_to_leave
-import mobi.giza.compose.resources.require_signatures_sent
import mobi.giza.compose.resources.change_proposed
+import mobi.giza.compose.resources.step_down_requested
import mobi.giza.compose.resources.admin_offer_sent
import mobi.giza.compose.resources.promotion_accepted
import mobi.giza.compose.ui.view.state.GovernanceStatus
@@ -248,8 +248,8 @@ fun ChatRoomDetailScreen(
val couldNotLeave = stringResource(Res.string.couldn_t_leave_the_group)
val adminChangeRequested = stringResource(Res.string.admin_change_requested)
val steppingDownToLeave = stringResource(Res.string.stepping_down_to_leave)
- val requireSignaturesSent = stringResource(Res.string.require_signatures_sent)
val changeProposed = stringResource(Res.string.change_proposed)
+ val stepDownRequested = stringResource(Res.string.step_down_requested)
val adminOfferSent = stringResource(Res.string.admin_offer_sent)
val promotionAccepted = stringResource(Res.string.promotion_accepted)
val adminLabel = stringResource(Res.string.admin)
@@ -397,6 +397,7 @@ fun ChatRoomDetailScreen(
notify(
failure ?: when {
governed && action == MemberAction.MAKE_ADMIN -> adminOfferSent
+ governed && action == MemberAction.STEP_DOWN -> stepDownRequested
governed -> changeProposed
else -> adminChangeRequested
}
@@ -1212,16 +1213,7 @@ fun ChatRoomDetailScreen(
chatRoomDetailUIState.governance?.let { governance ->
item {
- GovernanceSection(
- governance = governance,
- canGovern = chatRoomDetailUIState.canGovern,
- nameOf = nameOf,
- onRequireSignatures = {
- chatRoomDetailViewModel.requireSignatures(chatRoomDetailUIState.localChatRoom) { failure ->
- notify(failure ?: requireSignaturesSent)
- }
- },
- )
+ GovernanceSection(governance = governance)
}
}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/MemberActionUnavailableScreen.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/MemberActionUnavailableScreen.kt
index 2b09349e..fa192f97 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/MemberActionUnavailableScreen.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/MemberActionUnavailableScreen.kt
@@ -21,7 +21,6 @@ import androidx.compose.material3.Button
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
-import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.Text
@@ -60,7 +59,6 @@ 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_signatures_waiting
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
@@ -172,8 +170,9 @@ fun MemberActionUnavailableScreen(
titleStyle = MaterialTheme.typography.headlineSmall,
)
- when {
- lead == MemberActionBlocker.NoAdminsInThisRoom && state.adminRoomId != null -> Button(
+ // The one reason with something to do about it from here.
+ if (lead == MemberActionBlocker.NoAdminsInThisRoom && state.adminRoomId != null) {
+ Button(
onClick = {
onNavigateToRoute(
ChatRoomDetailRoute(
@@ -186,11 +185,6 @@ fun MemberActionUnavailableScreen(
) {
Text(stringResource(Res.string.open_the_admin_room))
}
-
- // The switch is on the group's page, under its members.
- lead is MemberActionBlocker.SignaturesNotRequired -> OutlinedButton(onClick = onNavigateBack) {
- Text(stringResource(Res.string.back_to_the_group))
- }
}
val rest = state.blockers.drop(1)
@@ -257,13 +251,6 @@ private fun Blocker(
Text(text = blocker.title(memberName), style = titleStyle)
}
Text(text = blocker.body(names), style = MaterialTheme.typography.bodyLarge)
- if (blocker is MemberActionBlocker.SignaturesNotRequired && blocker.waitingOn.isNotEmpty()) {
- Text(
- text = stringResource(Res.string.member_action_signatures_waiting, blocker.waitingOn.namedBy(names)),
- style = MaterialTheme.typography.bodyLarge,
- color = MaterialTheme.colorScheme.onSurfaceVariant,
- )
- }
}
}
@@ -276,7 +263,7 @@ private fun MemberActionBlocker.icon(): ImageVector = when (this) {
MemberActionBlocker.Disbanded,
MemberActionBlocker.YouLeft -> Icons.Default.Groups
is MemberActionBlocker.NotAnAdmin -> Icons.Default.Lock
- is MemberActionBlocker.SignaturesNotRequired,
+ MemberActionBlocker.SignaturesNotRequired,
MemberActionBlocker.ShareRotationUnavailable -> Icons.Default.Key
MemberActionBlocker.NotInGroupYet -> Icons.Default.Person
MemberActionBlocker.OnlyAdmin,
@@ -292,7 +279,7 @@ private fun MemberActionBlocker.title(memberName: String): String = when (this)
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)
- is MemberActionBlocker.SignaturesNotRequired -> stringResource(Res.string.member_action_signatures_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)
@@ -308,7 +295,7 @@ private fun MemberActionBlocker.body(names: Map): String = when
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))
- is MemberActionBlocker.SignaturesNotRequired -> stringResource(Res.string.member_action_signatures_body)
+ 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)
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/MemberAdminControls.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/MemberAdminControls.kt
index 711b1027..ace54b48 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/MemberAdminControls.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/MemberAdminControls.kt
@@ -37,9 +37,6 @@ import mobi.giza.compose.resources.Res
import mobi.giza.compose.resources.cancel
import mobi.giza.compose.resources.disband_group_instead
import mobi.giza.compose.resources.governance_on
-import mobi.giza.compose.resources.governance_waiting
-import mobi.giza.compose.resources.require_signatures
-import mobi.giza.compose.resources.require_signatures_explainer
import mobi.giza.compose.resources.make_admin
import mobi.giza.compose.resources.make_admin_and_leave
import mobi.giza.compose.resources.make_admin_body
@@ -58,6 +55,7 @@ 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_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
@@ -143,7 +141,7 @@ internal fun ConfirmAdminChangeDialog(
)
MemberAction.STEP_DOWN -> Triple(
stringResource(Res.string.step_down_title),
- stringResource(Res.string.step_down_body),
+ stringResource(if (keyed) Res.string.step_down_body_keyed else Res.string.step_down_body),
stringResource(Res.string.step_down),
)
// Removal keeps the immediate action it always had.
@@ -217,51 +215,25 @@ internal fun LeaveAsAdminDialog(
}
/**
- * Whether a keyed room's changes need the group's signature. Once they do, a line
- * saying so; before, for an admin, the switch -- or who it is still waiting on,
- * since switching it on with a member whose device cannot follow would leave them
- * in a different group from the first change. docs/member-admin-promotion.md, Phase 4b.
+ * That a keyed room's changes need the group's signature, and how few admins it may
+ * have. Every keyed room is born that way, so there is nothing to switch on and
+ * nobody to wait for. docs/member-admin-promotion.md, R2 and D8, and
+ * docs/remove-convenient-groups.md, "After the build".
*/
@Composable
-internal fun GovernanceSection(
- governance: GovernanceStatus,
- canGovern: Boolean,
- nameOf: (HexKey) -> String,
- onRequireSignatures: () -> Unit,
-) {
- val explainer = Modifier.padding(
- horizontal = MaterialTheme.spacing.containerPadding,
- vertical = MaterialTheme.spacing.compactPadding,
- )
- Column(modifier = Modifier.fillMaxWidth()) {
- when (governance) {
- is GovernanceStatus.Governed -> Text(
- text = stringResource(Res.string.governance_on, governance.minimumAdmins),
- style = MaterialTheme.typography.bodyMedium,
- color = MaterialTheme.colorScheme.onSurfaceVariant,
- modifier = explainer,
- )
- is GovernanceStatus.Ready -> if (canGovern) {
- TextButton(onClick = onRequireSignatures) {
- Icon(Icons.Default.Verified, contentDescription = Decorative)
- Text(stringResource(Res.string.require_signatures), modifier = Modifier.padding(start = MaterialTheme.spacing.relatedGap))
- }
- Text(
- text = stringResource(Res.string.require_signatures_explainer),
- style = MaterialTheme.typography.bodySmall,
- color = MaterialTheme.colorScheme.onSurfaceVariant,
- modifier = explainer,
- )
- }
- is GovernanceStatus.Waiting -> if (canGovern) {
- Text(
- text = stringResource(Res.string.governance_waiting, governance.missing.map(nameOf).sorted().joinToString()),
- style = MaterialTheme.typography.bodySmall,
- color = MaterialTheme.colorScheme.onSurfaceVariant,
- modifier = explainer,
- )
- }
- }
+internal fun GovernanceSection(governance: GovernanceStatus) {
+ when (governance) {
+ is GovernanceStatus.Governed -> Text(
+ text = stringResource(Res.string.governance_on, governance.minimumAdmins),
+ style = MaterialTheme.typography.bodyMedium,
+ color = MaterialTheme.colorScheme.onSurfaceVariant,
+ modifier = Modifier
+ .fillMaxWidth()
+ .padding(
+ horizontal = MaterialTheme.spacing.containerPadding,
+ vertical = MaterialTheme.spacing.compactPadding,
+ ),
+ )
}
}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/ChatRoomDetailViewModel.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/ChatRoomDetailViewModel.kt
index ca35a249..1a71bb55 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/ChatRoomDetailViewModel.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/ChatRoomDetailViewModel.kt
@@ -270,10 +270,6 @@ class ChatRoomDetailViewModel(
}
}
- /** Makes the room's changes need the group's signature. docs/member-admin-promotion.md, Phase 4b. */
- fun requireSignatures(localChatRoom: LocalChatRoom, onDone: (String?) -> Unit) =
- adminAction(onDone) { chatRepository.requireSignatures(localChatRoom) }
-
/** Accepts becoming an admin of a keyed room. docs/member-admin-promotion.md, Phase 8. */
fun acceptPromotion(localChatRoom: LocalChatRoom, offerId: HexKey, onDone: (String?) -> Unit) =
adminAction(onDone) { chatRepository.acceptPromotion(localChatRoom, offerId)?.let { throw IllegalStateException(it) } }
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/MemberActionUnavailableViewModel.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/MemberActionUnavailableViewModel.kt
index fe1babd2..5fe0d886 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/MemberActionUnavailableViewModel.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/MemberActionUnavailableViewModel.kt
@@ -77,7 +77,6 @@ class MemberActionUnavailableViewModel(
val named = option.blockers.flatMap { blocker ->
when (blocker) {
is MemberActionBlocker.NotAnAdmin -> blocker.admins
- is MemberActionBlocker.SignaturesNotRequired -> blocker.waitingOn
else -> emptySet()
}
}.toSet()
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/GovernanceStatus.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/GovernanceStatus.kt
index cc6f0897..cee24d8d 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/GovernanceStatus.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/GovernanceStatus.kt
@@ -1,18 +1,12 @@
package mobi.giza.compose.ui.view.state
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-
/**
- * Where a keyed room stands on needing the group's signature for its changes.
- * docs/member-admin-promotion.md, R2 and Phase 4b.
+ * How a keyed room needs the group's signature for its changes. Every keyed room
+ * Giza makes is born needing it (docs/remove-convenient-groups.md, "After the
+ * build"); a room with no state saying so -- one made before that -- has none.
+ * docs/member-admin-promotion.md, R2.
*/
sealed interface GovernanceStatus {
- /** It does: every change is proposed, signed by the group, and only then applied. */
+ /** Every change is proposed, signed by the group, and only then applied. */
data class Governed(val minimumAdmins: Int) : GovernanceStatus
-
- /** It does not yet, and every member's device could follow if it were switched on. */
- data class Ready(val minimumAdmins: Int) : GovernanceStatus
-
- /** It does not yet, and these members have not said their device could follow. */
- data class Waiting(val missing: Set) : GovernanceStatus
}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/MemberAction.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/MemberAction.kt
index c221a404..f49dfe71 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/MemberAction.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/MemberAction.kt
@@ -50,11 +50,12 @@ sealed interface MemberActionBlocker {
data class NotAnAdmin(val admins: Set) : MemberActionBlocker
/**
- * A keyed room whose changes do not need the group's signature yet, which
- * every change to its admins has to (R2). [waitingOn] are the members whose
- * devices have not said they can follow; empty when it only needs switching on.
+ * 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 class SignaturesNotRequired(val waitingOn: Set) : MemberActionBlocker
+ data object SignaturesNotRequired : MemberActionBlocker
/** A keyed room in a build without share rotation, which every admin change moves (R1). */
data object ShareRotationUnavailable : MemberActionBlocker
diff --git a/composeApp/src/commonTest/kotlin/mobi/giza/compose/managers/MemberActionPolicyTest.kt b/composeApp/src/commonTest/kotlin/mobi/giza/compose/managers/MemberActionPolicyTest.kt
index 4990d769..e846203d 100644
--- a/composeApp/src/commonTest/kotlin/mobi/giza/compose/managers/MemberActionPolicyTest.kt
+++ b/composeApp/src/commonTest/kotlin/mobi/giza/compose/managers/MemberActionPolicyTest.kt
@@ -65,7 +65,25 @@ class MemberActionPolicyTest {
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")
- assertNull(MemberActionPolicy.options(keyed(), listOf(me))[me], "an admin of a keyed room was offered to step down alone")
+ }
+
+ /**
+ * 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
@@ -117,11 +135,11 @@ class MemberActionPolicyTest {
}
@Test
- fun `a keyed room that does not need the group's signature names who it waits on`() {
- val context = keyed(admins = setOf(me, carol, dana)).copy(governed = false, waitingOn = setOf(dana))
+ 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(setOf(dana))), context.blockers(bob, MemberAction.MAKE_ADMIN))
- assertEquals(listOf(MemberActionBlocker.SignaturesNotRequired(setOf(dana))), context.blockers(carol, MemberAction.REMOVE_AS_ADMIN).take(1))
+ 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")
}
diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/AdminChangesJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/AdminChangesJvmTest.kt
index 3fcbde1d..486a7fd8 100644
--- a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/AdminChangesJvmTest.kt
+++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/AdminChangesJvmTest.kt
@@ -358,14 +358,17 @@ class AdminChangesJvmTest {
assertIs(
MarmotGroupCreation.create(
database = db, chatRepository = chatRepository, groupId = keyedRoomId, name = "#keyed",
- purpose = "Admins.", adminPublicKeys = setOf(user), userPublicKey = user, keyPair = keyPair,
- profile = MarmotProfile.CURRENT,
+ purpose = "Admins.", adminPublicKeys = setOf(user), minimumAdmins = Quorum.MINIMUM_GROUP_SIZE,
+ userPublicKey = user, keyPair = keyPair, profile = MarmotProfile.CURRENT,
)
)
val keyedRoom = db.chatRoomDao().findChatRoomById(keyedRoomId)!!
+ // Born needing the group's signature. Its only admin stepping down would take
+ // it under its floor, so it is refused before anything is asked or committed.
val refusal = assertFailsWith { chatRepository.demoteMember(keyedRoom, user) }
- assertEquals(mobi.giza.compose.database.dao.MarmotOutboundDao.KEYED_ROOM_REFUSAL, refusal.message)
+ assertTrue("at least 3 admins" in refusal.message.orEmpty(), refusal.message)
+ assertTrue(db.marmotInnerEventDao().getByKinds(listOf(mobi.giza.compose.nostr.frost.PromotionEvents.STEP_DOWN)).isEmpty())
assertTrue(db.marmotPublishObligationDao().getAll().isEmpty())
val keyedGroup = db.marmotEngine.groupFor(keyedRoom.routingId)!!
assertEquals(AdminLeave.CANNOT, AdminGovernance.adminLeave(keyedGroup, user))
diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/GovernanceGateJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/GovernanceGateJvmTest.kt
index 6117e5ef..feb0b41d 100644
--- a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/GovernanceGateJvmTest.kt
+++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/GovernanceGateJvmTest.kt
@@ -14,7 +14,6 @@ import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerSync
import kotlin.test.AfterTest
import mobi.giza.compose.extensions.toHex
import mobi.giza.compose.ui.view.state.GovernanceStatus
-import mobi.giza.compose.nostr.frost.GovernanceSupportEvent
import mobi.giza.compose.database.repository.DatabaseNostrRepository
import mobi.giza.compose.database.repository.DatabaseChatRepository
import kotlin.test.assertIs
@@ -31,6 +30,7 @@ import mobi.giza.compose.database.GizaDatabase
import mobi.giza.compose.database.builder.getRoomDatabase
import mobi.giza.compose.database.model.ChatMessage
import mobi.giza.compose.database.repository.DatabaseMarmotRepository
+import mobi.giza.compose.nostr.frost.PromotionEvents
import mobi.giza.compose.nostr.frost.GovernanceCarrierEvent
import mobi.giza.compose.nostr.frost.GovernanceChange
import mobi.giza.compose.nostr.frost.GovernanceStatementEvent
@@ -217,41 +217,8 @@ class GovernanceGateJvmTest {
assertEquals(setOf(dana.hex, userHex), appGroup().currentAdminIdentities())
}
- // --- Phase 4b: who can follow, and the switch ---------------------------------
-
private val erin = MarmotStandIn()
- /** Erin joins Dana's room, by Dana's bare commit; the app applies it. */
- private suspend fun erinJoins() {
- MarmotStandIn.seedProfile(db, erin.hex, "Erin")
- erin.makeBundle()
- val add = dana.commitLocally(routingId) { dana.manager.addMember(routingId, erin.bundle.keyPackage.toTlsBytes()) }
- erin.manager.processWelcome(assertNotNull(add.welcomeBytes), erin.bundle)
- erin.inbound.trackGroup(routingId)
- MarmotStandIn.storeInApp(db, user, commitEvent(add))
- }
-
- /** Dana makes [admins] the admin list by a bare commit, which Erin and the app apply. */
- private suspend fun danaSetsAdminsBare(admins: List) {
- val commit = dana.commitLocally(routingId) {
- val staged = dana.manager.stageAppDataUpdate(routingId, AdminPolicyV1.COMPONENT_ID, AdminPolicyV1.ofHex(admins).encode())
- dana.manager.installState(routingId, staged.pendingState)
- staged.result
- }
- val event = commitEvent(commit)
- erin.inbound.processGroupEvent(event)
- MarmotStandIn.storeInApp(db, user, event)
- }
-
- /** [member] says, in the room, that their device follows signed commits. */
- private suspend fun says(member: MarmotStandIn) {
- val payload = MarmotAppEvent.build(
- pubKey = member.hex, kind = GovernanceSupportEvent.KIND, content = "", createdAt = 1_700_000_002,
- tags = GovernanceSupportEvent.assembleTags(roomId),
- ).encodeToPayload()
- MarmotStandIn.storeInApp(db, user, member.outbound.buildGroupEventFromBytes(routingId, payload).signedEvent)
- }
-
private suspend fun room() = db.chatRoomDao().findChatRoomById(roomId)!!
/** The relay's OK on the newest commit this device put on the wire. */
@@ -264,51 +231,6 @@ class GovernanceGateJvmTest {
return event.toGroupEvent(userHex)!!
}
- @Test
- fun `hearing another member say it, this device says it back`() = runBlocking {
- governedRoom(governed = false)
- assertFalse(userHex in GovernanceSupport.supporters(db, roomId))
-
- says(dana)
-
- assertTrue(userHex in GovernanceSupport.supporters(db, roomId), "the app did not answer")
- assertTrue(dana.hex in GovernanceSupport.supporters(db, roomId))
- }
-
- @Test
- fun `the switch waits for every member, then turns the rule on for everyone`() = runBlocking {
- governedRoom(governed = false)
- erinJoins()
- danaSetsAdminsBare(listOf(dana.hex, userHex, erin.hex))
- says(dana)
-
- val waiting = assertIs(chatRepository.governanceStatus(roomId))
- assertEquals(setOf(erin.hex), waiting.missing)
- val refusal = assertFailsWith { chatRepository.requireSignatures(room()) }
- assertTrue("Erin" in refusal.message.orEmpty(), refusal.message)
-
- says(erin)
- assertEquals(GovernanceStatus.Ready(minimumAdmins = 3), chatRepository.governanceStatus(roomId))
-
- chatRepository.requireSignatures(room())
- val switch = okTheLatestCommit()
-
- assertEquals(3, GovernanceGate.minimumAdmins(appGroup()), "the rule is not on here")
- dana.inbound.processGroupEvent(switch)
- assertEquals(3, GovernanceMarker.minimumAdmins(dana.manager.getGroup(routingId)!!.roomDescription()), "the rule did not reach Dana")
- assertEquals(GovernanceStatus.Governed(3), chatRepository.governanceStatus(roomId))
-
- // And from here, Dana's bare commit is refused.
- val epoch = appGroup().epoch
- val bare = dana.commitLocally(routingId) {
- val staged = dana.manager.stageAppDataUpdate(routingId, AdminPolicyV1.COMPONENT_ID, AdminPolicyV1.ofHex(listOf(dana.hex, userHex)).encode())
- dana.manager.installState(routingId, staged.pendingState)
- staged.result
- }
- MarmotStandIn.storeInApp(db, user, commitEvent(bare))
- assertEquals(epoch, appGroup().epoch, "a bare commit landed after the switch")
- }
-
// --- Phase 5: this device proposes, the group signs, this device publishes ------
/** The app made an admin beside Dana, inside the group's signature. */
@@ -513,20 +435,84 @@ class GovernanceGateJvmTest {
// --- Phase 9: demotion and removal in a keyed room, then a rotation ------------
@Test
- fun `in a governed keyed room an admin is offered demoting another, never stepping down`() = runBlocking {
+ fun `in a governed keyed room an admin is offered demoting another, and stepping down`() = runBlocking {
governedRoom()
appIsAdmin()
mobi.giza.compose.ExperimentalFeatures.shareRefreshOverride = true
try {
val actions = AdminGovernance.memberActions(appGroup(), userHex, floor = 1)
assertTrue(mobi.giza.compose.ui.view.state.MemberAction.REMOVE_AS_ADMIN in actions[dana.hex].orEmpty())
- assertFalse(mobi.giza.compose.ui.view.state.MemberAction.STEP_DOWN in actions[userHex].orEmpty(), "an admin was offered stepping down from a keyed room")
- assertFalse(mobi.giza.compose.ui.view.state.MemberAction.REMOVE_AS_ADMIN in AdminGovernance.memberActions(appGroup(), userHex, floor = 2)[dana.hex].orEmpty(), "the floor was ignored")
+ assertTrue(mobi.giza.compose.ui.view.state.MemberAction.STEP_DOWN in actions[userHex].orEmpty(), "an admin's own row offered no step-down")
+ val atTheFloor = AdminGovernance.memberActions(appGroup(), userHex, floor = 2)
+ assertFalse(mobi.giza.compose.ui.view.state.MemberAction.REMOVE_AS_ADMIN in atTheFloor[dana.hex].orEmpty(), "the floor was ignored")
+ assertFalse(mobi.giza.compose.ui.view.state.MemberAction.STEP_DOWN in atTheFloor[userHex].orEmpty(), "the floor was ignored for a step-down")
} finally {
mobi.giza.compose.ExperimentalFeatures.shareRefreshOverride = null
}
}
+ @Test
+ fun `a step-down is proposed by the admin in the lowest leaf, never the one stepping down`() = runBlocking {
+ governedRoom()
+ appIsAdmin()
+ // Dana made the room and holds leaf 0; the app holds leaf 1.
+ assertEquals(dana.hex, AdminGovernance.stepDownProposer(appGroup(), userHex))
+ assertEquals(userHex, AdminGovernance.stepDownProposer(appGroup(), dana.hex))
+ }
+
+ @Test
+ fun `stepping down from a keyed room asks the other admins, and commits nothing`() = runBlocking {
+ governedRoom()
+ appIsAdmin()
+
+ PromotionManager.requestStepDown(db, room(), userHex)
+
+ val requests = db.marmotInnerEventDao().getByChatRoomAndKinds(roomId, listOf(PromotionEvents.STEP_DOWN))
+ assertEquals(listOf(userHex), requests.map { it.publicKey })
+ assertTrue(db.marmotPublishObligationDao().getAll().isEmpty(), "a commit went out")
+ assertTrue(db.governanceProposalDao().getAll().isEmpty(), "the one stepping down proposed it")
+ assertTrue(userHex in appGroup().currentAdminIdentities())
+ // Not this device's to take up: Dana's is the one that proposes it.
+ assertEquals(0, PromotionManager.followStepDowns(db, userHex))
+ assertEquals(1, db.marmotInnerEventDao().getByChatRoomAndKinds(roomId, listOf(PromotionEvents.STEP_DOWN)).size)
+ }
+
+ @Test
+ fun `the admin whose it is to propose a step-down takes the request up`() = runBlocking {
+ governedRoom()
+ appIsAdmin()
+ mobi.giza.compose.ExperimentalFeatures.shareRefreshOverride = true
+ try {
+ danaSays(PromotionEvents.STEP_DOWN, "", PromotionEvents.stepDownTags(roomId))
+
+ // Dana's request reaches `demote` on this device, which is the one to
+ // propose it. This room has two admins under a floor of three, so the
+ // demotion is refused there and the room says why; the request is used.
+ assertEquals(0, PromotionManager.followStepDowns(db, userHex))
+ assertTrue(lines(ChatMessage.TYPE_CHANGE_NOT_APPLIED).any { "as they asked" in it.content && "at least 3 admins" in it.content })
+ assertTrue(db.marmotInnerEventDao().getByChatRoomAndKinds(roomId, listOf(PromotionEvents.STEP_DOWN)).isEmpty(), "the request was kept")
+ } finally {
+ mobi.giza.compose.ExperimentalFeatures.shareRefreshOverride = null
+ }
+ }
+
+ @Test
+ fun `a request from someone who is no longer an admin is dropped`() = runBlocking {
+ governedRoom()
+ // A request the app sent while it was an admin, filed after it stopped being one.
+ db.marmotInnerEventDao().upsert(
+ mobi.giza.compose.database.model.MarmotInnerEvent(
+ id = "ab".repeat(32), publicKey = userHex, kind = PromotionEvents.STEP_DOWN,
+ createdAt = kotlin.time.Instant.fromEpochSeconds(1_700_000_000),
+ tags = PromotionEvents.stepDownTags(roomId), content = "", chatRoomId = roomId,
+ )
+ )
+
+ PromotionManager.followStepDowns(db, dana.hex)
+
+ assertTrue(db.marmotInnerEventDao().getByChatRoomAndKinds(roomId, listOf(PromotionEvents.STEP_DOWN)).isEmpty())
+ }
+
@Test
fun `a signed demotion that lands owes a rotation without the member, and asks for one`() = runBlocking {
governedRoom()
diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/GroupLifecycleJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/GroupLifecycleJvmTest.kt
index 90cfeba2..3fb25f99 100644
--- a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/GroupLifecycleJvmTest.kt
+++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/GroupLifecycleJvmTest.kt
@@ -84,7 +84,7 @@ class GroupLifecycleJvmTest {
assertIs(
MarmotGroupCreation.create(
database = db, chatRepository = chatRepository, groupId = roomId, name = "#room",
- purpose = "Admins.", adminPublicKeys = setOf(user), userPublicKey = user, keyPair = keyPair,
+ purpose = "Admins.", adminPublicKeys = setOf(user), minimumAdmins = null, userPublicKey = user, keyPair = keyPair,
profile = MarmotProfile.CURRENT,
)
)
diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/MarmotGroupCreationJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/MarmotGroupCreationJvmTest.kt
index 3fc1c19d..2b2dacb0 100644
--- a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/MarmotGroupCreationJvmTest.kt
+++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/MarmotGroupCreationJvmTest.kt
@@ -83,7 +83,7 @@ class MarmotGroupCreationJvmTest {
purpose = "Admins of Ekklesia.",
// A group of one, so nothing has to be invited and no key package has
// to be found. The flag is the whole of what is being tested.
- adminPublicKeys = setOf(user),
+ adminPublicKeys = setOf(user), minimumAdmins = Quorum.MINIMUM_GROUP_SIZE,
userPublicKey = user,
keyPair = keyPair,
)
@@ -112,7 +112,7 @@ class MarmotGroupCreationJvmTest {
groupId = groupId,
name = "#Ekklesia",
purpose = "Admins of Ekklesia.",
- adminPublicKeys = setOf(user),
+ adminPublicKeys = setOf(user), minimumAdmins = Quorum.MINIMUM_GROUP_SIZE,
userPublicKey = user,
keyPair = keyPair,
)
@@ -148,7 +148,7 @@ class MarmotGroupCreationJvmTest {
// so a caller that forgot would mark the room on no device at all.
name = "Ekklesia",
purpose = "Admins of Ekklesia.",
- adminPublicKeys = setOf(user),
+ adminPublicKeys = setOf(user), minimumAdmins = Quorum.MINIMUM_GROUP_SIZE,
userPublicKey = user,
keyPair = keyPair,
)
@@ -176,7 +176,7 @@ class MarmotGroupCreationJvmTest {
groupId = groupId,
name = "#Ekklesia",
purpose = "Admins of Ekklesia.",
- adminPublicKeys = setOf(user),
+ adminPublicKeys = setOf(user), minimumAdmins = Quorum.MINIMUM_GROUP_SIZE,
userPublicKey = user,
keyPair = keyPair,
)
@@ -274,6 +274,9 @@ class MarmotGroupCreationJvmTest {
val group = assertNotNull(created.room.chatRoom.toMlsGroup())
assertEquals(founders, group.currentAdminIdentities(), "${owner.pubKey.toHexKey().take(8)}'s room")
+ // Born needing the group's signature, with the floor its 2-of-3 quorum
+ // sets: nothing to switch on later. docs/remove-convenient-groups.md.
+ assertEquals(Quorum.minimumAdmins(threshold = 2), GovernanceGate.minimumAdmins(group), "the room was born without the rule")
}
} finally {
alicesDb.close()
@@ -332,7 +335,7 @@ class MarmotGroupCreationJvmTest {
groupId = groupId,
name = "#Ekklesia",
purpose = "Admins of Ekklesia.",
- adminPublicKeys = setOf(user),
+ adminPublicKeys = setOf(user), minimumAdmins = Quorum.MINIMUM_GROUP_SIZE,
userPublicKey = user,
keyPair = keyPair,
profile = MarmotProfile.CURRENT,
@@ -368,7 +371,7 @@ class MarmotGroupCreationJvmTest {
groupId = groupId,
name = "#Ekklesia",
purpose = "Admins of Ekklesia.",
- adminPublicKeys = setOf(user),
+ adminPublicKeys = setOf(user), minimumAdmins = Quorum.MINIMUM_GROUP_SIZE,
userPublicKey = user,
keyPair = keyPair,
profile = MarmotProfile.LEGACY,
@@ -396,7 +399,7 @@ class MarmotGroupCreationJvmTest {
groupId = groupId,
name = "#Ekklesia",
purpose = "Admins of Ekklesia.",
- adminPublicKeys = setOf(user),
+ adminPublicKeys = setOf(user), minimumAdmins = Quorum.MINIMUM_GROUP_SIZE,
userPublicKey = user,
keyPair = keyPair,
profile = MarmotProfile.CURRENT,
diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/PublishBeforeApplyJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/PublishBeforeApplyJvmTest.kt
index b1eaafda..cb66e7be 100644
--- a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/PublishBeforeApplyJvmTest.kt
+++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/PublishBeforeApplyJvmTest.kt
@@ -73,7 +73,7 @@ class PublishBeforeApplyJvmTest {
seedProfile(user)
val outcome = MarmotGroupCreation.create(
database = db, chatRepository = chatRepository, groupId = roomId, name = "#room",
- purpose = "Admins.", adminPublicKeys = setOf(user), userPublicKey = user, keyPair = keyPair,
+ purpose = "Admins.", adminPublicKeys = setOf(user), minimumAdmins = null, userPublicKey = user, keyPair = keyPair,
profile = MarmotProfile.CURRENT,
)
assertIs(outcome)
diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/RobustGroupAdminsJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/RobustGroupAdminsJvmTest.kt
index c48ec120..ab4888af 100644
--- a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/RobustGroupAdminsJvmTest.kt
+++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/RobustGroupAdminsJvmTest.kt
@@ -1,5 +1,6 @@
package mobi.giza.compose.managers
+import mobi.giza.compose.ui.view.state.GovernanceStatus
import androidx.room3.Room
import com.vitorpamplona.marmot.groups.currentAdminIdentities
import com.vitorpamplona.marmot.groups.isLocalAdmin
@@ -14,6 +15,7 @@ import com.vitorpamplona.quartz.nip59Giftwrap.rumors.RumorAssembler
import com.vitorpamplona.quartz.nip59Giftwrap.seals.SealEvent
import com.vitorpamplona.quartz.nip59Giftwrap.wraps.GiftWrapEvent
import kotlin.test.Test
+import kotlin.test.assertFailsWith
import kotlin.test.assertFalse
import kotlin.test.assertEquals
import kotlin.test.assertIs
@@ -115,6 +117,7 @@ class RobustGroupAdminsJvmTest {
name = "Ekklesia",
purpose = "Admins of Ekklesia.",
adminPublicKeys = phones.map { it.publicKey }.toSet(),
+ minimumAdmins = Quorum.MINIMUM_GROUP_SIZE,
userPublicKey = creator.publicKey,
keyPair = creator.keyPair,
keyPackageLookupTimeout = 2_000L,
@@ -217,6 +220,18 @@ class RobustGroupAdminsJvmTest {
later.ready()
(phones + later).forEach { phone -> (phones + later).forEach { MarmotStandIn.seedProfile(phone.db, it.publicKey) } }
+ if (profile == MarmotProfile.CURRENT) {
+ // Born needing the group's signature: a later invite is a proposal the
+ // group signs, never a commit of the creator's own -- which is also what
+ // proves it did not take the founding path. These phones hold no share
+ // of a real key, so it stops there. docs/remove-convenient-groups.md.
+ val refusal = assertFailsWith {
+ creator.chatRepository.inviteMember(creator.room(), later.publicKey, later.keyPackage)
+ }
+ assertEquals("This group has no shared key to sign with", refusal.message)
+ assertTrue(creator.db.marmotPublishObligationDao().getAll().isEmpty(), "a bare commit went out")
+ return@use
+ }
creator.chatRepository.inviteMember(creator.room(), later.publicKey, later.keyPackage)
creator.okTheLatestCommit()
welcome(from = creator, to = later)
@@ -400,6 +415,23 @@ class RobustGroupAdminsJvmTest {
// ---- A group run by one person ------------------------------------------------
+ /**
+ * The rule is in the state the founders are welcomed into, so a joiner's phone
+ * enforces it from its first epoch -- there is no switch for anybody to wait on,
+ * press, or miss. docs/remove-convenient-groups.md, "After the build".
+ */
+ @Test
+ fun `a group is born needing its signature, on every founder's phone`() =
+ onEveryProfile(listOf(MarmotProfile.CURRENT)) { _, phones ->
+ phones.forEach { phone ->
+ assertEquals(
+ GovernanceStatus.Governed(minimumAdmins = Quorum.MINIMUM_GROUP_SIZE),
+ phone.chatRepository.governanceStatus(roomId),
+ "$phone's room",
+ )
+ }
+ }
+
/**
* Giza stops making groups its creator runs alone, and does not stop joining
* them. docs/remove-convenient-groups.md, D4: a Bennu member still makes them,
@@ -426,6 +458,7 @@ class RobustGroupAdminsJvmTest {
name = "Checkers",
purpose = "Run by its creator.",
adminPublicKeys = setOf(creator.publicKey),
+ minimumAdmins = 1,
userPublicKey = creator.publicKey,
keyPair = creator.keyPair,
keyPackageLookupTimeout = 2_000L,
diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/composable/MemberActionUnavailableScreenJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/composable/MemberActionUnavailableScreenJvmTest.kt
index 823af683..4e8f462a 100644
--- a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/composable/MemberActionUnavailableScreenJvmTest.kt
+++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/composable/MemberActionUnavailableScreenJvmTest.kt
@@ -62,7 +62,7 @@ class MemberActionUnavailableScreenJvmTest {
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(emptySet()) to "The group has to sign changes first",
+ 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",
@@ -84,13 +84,6 @@ class MemberActionUnavailableScreenJvmTest {
}
}
- @Test
- fun `a keyed room waiting on devices names them`() {
- render(blocked(MemberActionBlocker.SignaturesNotRequired(setOf(thabo)))) {
- onNodeWithText("That waits until Thabo update Giza.").assertExists()
- }
- }
-
@Test
fun `the first reason leads, and the rest are under it`() {
render(blocked(MemberActionBlocker.Disbanded, MemberActionBlocker.NotAnAdmin(setOf(thabo)))) {
diff --git a/docs/member-admin-promotion.md b/docs/member-admin-promotion.md
index e1873ab5..8667a05b 100644
--- a/docs/member-admin-promotion.md
+++ b/docs/member-admin-promotion.md
@@ -51,7 +51,7 @@ Where the build chose differently:
| Phase 8: enrollment as `ShareRepairManager` generalised | the repair protocol unchanged but for its `n`: a request names the `n` it runs with (the new id, the table's size before it), helpers check that against their own table, and an enrollment asks no helper for approval -- the signed binding was everyone's chance to say no |
| Phase 8: `n` grows in "the stored key" | a signing session's and a repair's `n` is the generation's table size, which the enrollment grew; the ceremony's `participantCount` is left as the ceremony made it |
| Phase 9: every remaining holder's deal and confirm made automatic | the rotation is started by the proposer's device once the change lands (`GovernanceFollowThrough`), and each holder is asked once to take part, as every rotation now asks (rotate-shares-single-approval). A rotation that cannot start is said in the room and offered from the Shares section |
-| Phase 9: an admin can step down in a keyed room | not offered. The rotation that has to follow is the remaining holders', so another admin proposes the demotion |
+| Phase 9: an admin can step down in a keyed room | not offered at first: the rotation that has to follow is the remaining holders', so another admin proposes the demotion. Since offered as a request -- **Step down as admin** sends `PromotionEvents.STEP_DOWN` (30377), and the remaining admin in the lowest leaf (`AdminGovernance.stepDownProposer`) proposes the demotion for them, then rotates their share away as after any demotion it proposed. Leaving as an admin of a keyed room is still not offered |
| Phase 11's dialogs for every action | removal keeps the immediate action it had; promotion, demotion and stepping down ask first |
Read [marmot-v2.md](./marmot-v2.md) Phase 7 first. Removing a member, disbanding and
@@ -196,6 +196,9 @@ being invited.
### D4. The commit rides inside the signature, and the rule lives in the group's state (R2)
+*Since built further: the rule is no longer switched on. A keyed room is born with it
+([remove-convenient-groups.md](./remove-convenient-groups.md), "After the build").*
+
Two choices here decide whether R2 holds at all.
**The commit inside the signature, not beside it.** The group signs an event whose
@@ -460,7 +463,11 @@ does not; nothing changes in a room without the marker.
records who has said it.
- **Require signatures for changes**, on a keyed room's detail screen, for an admin, once
every current member has said it. It is one bare commit adding the marker line to the
- profile description. Until every member has, the screen names who has not.
+ profile description. Until every member has, the screen names who has not. (Since
+ removed, with the support event: a keyed room is born governed, its floor in its
+ epoch-0 description, because Giza no longer keeps compatibility with Bennu or older
+ builds, which were all the switch protected; [remove-convenient-groups.md](./remove-convenient-groups.md),
+ "After the build".)
- An invite into a governed room is refused for an account that has not said it, with
words that say why, once it is in the room (it says so from its own device on joining).
diff --git a/docs/member-row-actions.md b/docs/member-row-actions.md
index 496ca8c5..e4eb5e49 100644
--- a/docs/member-row-actions.md
+++ b/docs/member-row-actions.md
@@ -21,7 +21,8 @@ build did differently from the plan is listed in the next section.
| 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: the explainer's "Back to the group" for `SignaturesNotRequired` | That, as an outlined button | — |
+| 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 |
---
@@ -198,7 +199,7 @@ a way back").
| `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(waitingOn)` | The group has to sign changes first | In a group with a shared key, a change to who runs it needs the group's signature. An admin turns that on under "Require signatures" (if {names} haven't updated Giza yet, it waits for them). | **Back to the group** (to the governance section) |
+| `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. | — |
@@ -232,8 +233,7 @@ This also replaces one of the hardcoded `contentDescription` literals.
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)`,
- `SignaturesNotRequired(waitingOn: Set)` and `BelowFloor(floor: Int)`;
+ data are `NotAnAdmin(admins: Set)` 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:
@@ -442,8 +442,10 @@ By hand, on the desktop target, which has no system back:
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 before **Require signatures**: **Make admin** explains
- the signature rule and names anyone who hasn't updated Giza.
+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,
diff --git a/docs/remove-convenient-groups.md b/docs/remove-convenient-groups.md
index 7384ff09..45b6a3b2 100644
--- a/docs/remove-convenient-groups.md
+++ b/docs/remove-convenient-groups.md
@@ -389,6 +389,75 @@ detail screen, and a Bennu peer's convenient group still reaches them.
they were written. Add a parenthetical saying it was removed here.
- [README.md](./README.md): the table row, which this commit adds, says "built".
+### After the build: a group is born needing its signature
+
+Found on a device, with this plan merged alongside member-admin-promotion. A robust
+group's founders were admins holding shares; a member invited afterwards (D7 lets a
+keyed room take one) was a plain member, as designed -- but nobody could make them an
+admin. The ⋮ on their row offered only **Remove from group**.
+
+Making a member of a keyed room an admin needs the room to require the group's
+signature for its changes (`AdminGovernance.keyedChangesAllowed`). That rule was
+switched on after founding by an admin pressing **Require the group's signature for
+changes**, and only once every member's device had said, in the room, that it could
+follow signed commits (member-admin-promotion, D4 and Phase 4b). The founders said it
+before the invite, at an epoch the new member could not read, so the new member's
+device never heard anybody to answer and the room waited on it for good.
+
+That was fixed twice over -- a device said it on joining and at each start, then the
+switch was made by one device on its own -- before the question underneath was asked:
+what was the switch for? Only to keep a Bennu member, or one on an older Giza, from
+being left in a different group by the first signed change. Giza is in development and
+keeps compatibility with neither, so the switch protected nobody. It is gone, and so is
+everything that fed it:
+
+- **A keyed room is born governed.** `MarmotGroupCreation.createFor` writes
+ `GovernanceMarker`'s line into the room's epoch-0 description, with the floor its
+ ceremony's quorum sets (`Quorum.minimumAdmins`). Every founder is welcomed into a
+ state that already enforces the rule; a member added later is added by the group's
+ signature, like every other change.
+- **Founding still needs no signature.** The founding invite, and finishing one that
+ failed (robust-group-admins, Phase 4), are the creator's commits while it is the
+ room's only member. No other device ever processes them -- joiners start from the
+ Welcome -- so there is nobody to refuse them. member-admin-promotion's D7 holds as
+ written.
+- **Removed:** `GovernanceSupport` and its event (kind 30372), the announcement on
+ joining, at start and in answer to another member, the switch and
+ `requireSignatures`, the button, and the screen's *waiting* and *ready* states. The
+ room's details say only that changes need the group's signature, and the floor.
+
+Pinned by `MarmotGroupCreationJvmTest` (the room `createFor` makes carries the floor its
+2-of-3 ceremony sets) and `RobustGroupAdminsJvmTest` (every founder's phone, after a
+real Welcome, reads the room as governed with three admins at least; a later invite is
+a proposal for the group to sign, never the creator's own commit).
+
+A keyed room made before this has no marker, and nothing will ever add one: its
+admins cannot be changed. Make the group again.
+
+Promoting a member still needs the room's share rotation on -- a development build,
+for now -- and the member accepts on their own device.
+
+#### Stepping down, asked of another admin
+
+With every keyed room governed, an admin's own row had no menu: an admin of a keyed
+room could not step down (member-admin-promotion, Phase 9). A demotion's proposer starts
+the rotation that takes the demoted admin's share away, and a rotation's proposer has to
+keep a share -- so the admin stepping down cannot propose it.
+
+They ask instead. **Step down as admin** on their own row sends a request into the room
+(`PromotionEvents.STEP_DOWN`, 30377) and commits nothing. The remaining admin in the
+lowest leaf (`AdminGovernance.stepDownProposer`) -- one device, named the same on every
+device, so that two admins never both propose it -- two commits at one epoch the library cannot settle for their authors -- takes it up in
+`GovernanceFollowThrough` and runs the same `demote` its own **Remove as admin** would:
+proposed, signed by the group, then the share rotated away. The request is used once:
+dropped after it is proposed or refused out loud, and by every device once its requester
+is no longer an admin. It is offered only above the floor and while another admin is
+there to ask.
+
+Pinned in `GovernanceGateJvmTest`: the menu offers it, and not at the floor; asking
+commits nothing and is not the asker's to take up; the lowest-leaf admin's device takes
+it to `demote`; a request from someone no longer an admin is dropped.
+
## Out of scope
- **One-to-one chats** (D1). If they are to become robust, that needs its own plan.