diff --git a/composeApp/src/commonMain/composeResources/values/strings.xml b/composeApp/src/commonMain/composeResources/values/strings.xml index ed538b84..5b3a8349 100644 --- a/composeApp/src/commonMain/composeResources/values/strings.xml +++ b/composeApp/src/commonMain/composeResources/values/strings.xml @@ -535,10 +535,6 @@ If they have stopped answering, any member can abandon the ceremony. No key is made, and the group can start again. Open the room Admin - Founding members aren't admins - %1$s took part in the key ceremony that made this group, but this room doesn't list them as admins. - Make them admins - Asked the group to make them admins Not every founding member was invited %1$s took part in the key ceremony that made this group, but the invitation to this room never went out. Invite them 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 76f0869f..5ad72c91 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 @@ -1088,42 +1088,6 @@ abstract class MarmotOutboundDao( } } - /** - * Adds [publicKeys] to a current-profile room's admin policy, as an admin. - * - * Additions only. The policy committed is the one the group holds now plus - * these -- never a list built somewhere else -- so an admin already there is - * never dropped by it. One commit for all of them, through the publish gate - * like every other governance change. Nothing to do when every one is already - * listed. docs/robust-group-admins.md, Phase 3. - */ - @Transaction - open suspend fun addAdmins(localChatRoom: LocalChatRoom, publicKeys: Set) { - require(localChatRoom.chatRoom.marmotProfile() == MarmotProfile.CURRENT) { "Only a current-profile room can change its admins" } - val group = database.marmotEngine.groupFor(localChatRoom.routingId) - ?: throw MarmotMissingChatGroupException("No live group for ${localChatRoom.chatRoom.id}") - - val current = group.currentAdminIdentities() - val added = publicKeys - current - if (added.isEmpty()) return - - // A governed room's admins change only with the group's signature, so the - // repair is proposed rather than committed. The founders it adds took part - // in the ceremony and hold shares of the key, as R1 asks of every admin. - // docs/member-admin-promotion.md, Phase 5. - if (GovernanceGate.isGoverned(group)) { - GovernanceManager.propose(database, localChatRoom, localChatRoom.chatRoom.userPublicKey) { copy -> - copy.proposeAppDataUpdate(AdminPolicyV1.COMPONENT_ID, AdminPolicyV1.ofHex(current + added).encode()) - } - return - } - - val policy = AdminPolicyV1.ofHex(current + added).encode() - publishGatedCommit(localChatRoom) { manager, id -> - manager.stageAppDataUpdate(id, AdminPolicyV1.COMPONENT_ID, policy) - } - } - /** * Disbands a current-profile room, as an admin. * 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 b18d349a..d91bb47a 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 @@ -67,7 +67,6 @@ import mobi.giza.compose.exceptions.MarmotMissingNostrGroupDataExtension import mobi.giza.compose.exceptions.MarmotNotMemberOfChatGroupException import mobi.giza.compose.extensions.toHex import mobi.giza.compose.managers.AdminFlags -import mobi.giza.compose.managers.FoundingAdmins import mobi.giza.compose.managers.ChillDkgRitualManager import mobi.giza.compose.managers.ShareRefreshManager import mobi.giza.compose.managers.ShareRepairManager @@ -980,17 +979,6 @@ abstract class NostrDao( chatRoomId = nostrGroupId ) - // And with the state on file, whether the room - // names every member of that ceremony as an - // admin -- this device's own record against the - // creator's list. docs/robust-group-admins.md, - // Phase 3. - FoundingAdmins.announceIfMissing( - database = database, - chatRoomId = nostrGroupId, - userPublicKey = userPublicKey, - ) - // Where is the decoded welcome message... // TODO: Sync GroupEvents/Messages... // database.chatMessageDao().upsert( diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/model/ChatMessage.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/model/ChatMessage.kt index ccebcdfe..6a4a2af8 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/model/ChatMessage.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/model/ChatMessage.kt @@ -606,10 +606,15 @@ data class ChatMessage( const val TYPE_CHANGE_REJECTED = "changeRejected" /** - * The admin room this device was welcomed into does not name every member + * The admin room this device was welcomed into did not name every member * of the ceremony that made its key as an admin. Derived at the Welcome - * from this device's own record of the ceremony, never received, and - * written once. docs/robust-group-admins.md, Phase 3. + * from this device's own record of the ceremony, never received. + * docs/robust-group-admins.md, Phase 3. + * + * Retired: no longer written (docs/remove-founding-admins-card.md, D3). + * Kept, and kept in [MEMBERSHIP_TYPES], because rows written before are + * still on devices, as the user's own, and out of the set each would + * render as a bubble from the user. */ const val TYPE_FOUNDING_ADMINS_MISSING = "foundingAdminsMissing" 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 4077dbc9..a8c45987 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 @@ -19,7 +19,6 @@ 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 import mobi.giza.compose.managers.SharedKeyDerivation import mobi.giza.compose.managers.CeremonyFollowThrough import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl @@ -119,13 +118,13 @@ class DatabaseChatRepository( ) override suspend fun finishFoundingInvite(chatRoomId: String): MarmotGroupCreation.FoundingInvite { - val (ceremony, ceremonyRoom) = FoundingAdmins.ceremonyOf(database, chatRoomId) + val (ceremony, ceremonyRoom) = MarmotGroupCreation.ceremonyOf(database, chatRoomId) ?: return MarmotGroupCreation.FoundingInvite.NothingToDo return finishFoundingInvite(ceremony, ceremonyRoom) } override suspend fun uninvitedFounders(localChatRoom: LocalChatRoom): Set = try { - FoundingAdmins.ceremonyOf(database, localChatRoom.chatRoom.id) + MarmotGroupCreation.ceremonyOf(database, localChatRoom.chatRoom.id) ?.let { (ceremony, ceremonyRoom) -> MarmotGroupCreation.uninvitedFounders(database, localChatRoom, ceremony, ceremonyRoom) } @@ -812,19 +811,6 @@ class DatabaseChatRepository( database.marmotOutboundDao().removeMember(localChatRoom, memberPublicKey) } - override suspend fun addAdmins(localChatRoom: LocalChatRoom, publicKeys: Set) { - database.marmotOutboundDao().addAdmins(localChatRoom, publicKeys) - } - - override suspend fun foundingAdmins(chatRoomId: String): FoundingAdmins.Check = try { - FoundingAdmins.check(database, chatRoomId) - } catch (e: Throwable) { - // A room whose check threw is shown without the warning rather than not - // at all; the check is a label on the room, not a gate in front of it. - logger.e("Error checking the founding admins of $chatRoomId", e) - FoundingAdmins.Check.CannotCheck - } - override suspend fun holdsShare(localChatRoom: LocalChatRoom, memberPublicKey: HexKey): Boolean = ExperimentalFeatures.shareRefresh && runCatching { ShareRefreshManager.liveIdOf(database, localChatRoom, memberPublicKey) != null }.getOrDefault(false) diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/FoundingAdmins.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/FoundingAdmins.kt deleted file mode 100644 index 505ea68c..00000000 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/FoundingAdmins.kt +++ /dev/null @@ -1,131 +0,0 @@ -package mobi.giza.compose.managers - -import com.vitorpamplona.marmot.groups.currentAdminIdentities -import com.vitorpamplona.quartz.nip01Core.core.Event -import com.vitorpamplona.quartz.nip01Core.core.HexKey -import mobi.giza.compose.database.GizaDatabase -import mobi.giza.compose.database.model.ChatMessage -import mobi.giza.compose.database.model.DkgSession -import mobi.giza.compose.database.model.intermdiate.LocalChatRoom -import mobi.giza.compose.nostr.subgroup.SubgroupBirthCertificateEvent - -/** - * Whether a key-backed room's admin policy names every one of its founding - * members. docs/robust-group-admins.md, Phase 3. - * - * The founding members are the participants of the ceremony that made the room's - * key (D1). Every one of their devices built that set from the proposal it agreed - * to, so each can check the room it was welcomed into against its own record - * rather than trusting the device that happened to create it -- a bug, an older - * build, or a Bennu peer could all have listed fewer. A subgroup has a second - * record of the same set: the birth certificate its parent's quorum signed, which - * names its admins. - * - * Nothing is refused on a mismatch. The room's address is the key, and there is - * no second room to go to; a warning that names who is missing is what can be - * acted on, by any admin, with [missingFrom]'s answer. - */ -object FoundingAdmins { - - /** Enough of a key to tell two members apart when no profile is stored. */ - private const val SHORTENED_PUBLIC_KEY_LENGTH = 12 - - sealed interface Check { - /** - * No key behind the room: a one-to-one chat, a group made before every - * group was robust, or one a Bennu peer made. Run by its creator. - */ - data object NotKeyBacked : Check - - /** - * A key-backed room this device holds no ceremony for: a member added - * after the founding, or a reinstall. It is not one of the founders, and - * has nothing of its own to check the room against. - */ - data object CannotCheck : Check - - data object Matches : Check - - /** Founding members the room's admin policy does not name. */ - data class Missing(val publicKeys: Set) : Check - } - - suspend fun check(database: GizaDatabase, chatRoomId: String): Check { - val state = database.groupKeyStateDao().getByChatRoomId(chatRoomId) ?: return Check.NotKeyBacked - val group = database.chatRoomDao().findChatRoomById(chatRoomId)?.chatRoom?.toMlsGroup() - ?: return Check.CannotCheck - val ceremony = database.dkgSessionDao().getSessionById(state.dkgSessionId) - - val founders = foundersOf(database, ceremony).orEmpty() + certifiedAdmins(state.birthCertificateJson) - if (founders.isEmpty()) return Check.CannotCheck - - val missing = founders - group.currentAdminIdentities() - return if (missing.isEmpty()) Check.Matches else Check.Missing(missing) - } - - /** - * Checks the room this device was just welcomed into, and says so in its - * transcript when founding members are missing from its admins. Once, at the - * Welcome: the detail screen repeats the check on every visit, and a line per - * visit would be the same news told again. - * - * A whole sentence naming who is missing, like the membership lines it sits - * among, so nothing prefixes a sender's name to it. - */ - suspend fun announceIfMissing(database: GizaDatabase, chatRoomId: String, userPublicKey: HexKey): Check { - val check = check(database, chatRoomId) - if (check !is Check.Missing) return check - - val names = check.publicKeys.map { publicKey -> - database.profileDao().getProfileByPublicKey(publicKey)?.humanReadableNameOrPubkey() - ?: publicKey.take(SHORTENED_PUBLIC_KEY_LENGTH) - }.sorted() - - database.chatMessageDao().upsert( - ChatMessage( - content = "This room was created without ${names.joinToString(", ")} as " + - (if (names.size == 1) "an admin" else "admins") + - ", though they took part in the key ceremony. An admin can add them back from the room's details.", - messageType = ChatMessage.TYPE_FOUNDING_ADMINS_MISSING, - chatRoomId = chatRoomId, - senderPublicKey = userPublicKey, - isUserMessage = true, - giftWrapPayloadId = null, - marmotGroupEventId = null, - marmotInnerEventId = null, - ) - ) - return check - } - - /** - * The ceremony that made [chatRoomId]'s key, as this device holds it, and the - * room it ran in -- or null where this device holds no key state for the room, - * no record of that ceremony, or no longer the room it ran in. - */ - suspend fun ceremonyOf(database: GizaDatabase, chatRoomId: String): Pair? { - val state = database.groupKeyStateDao().getByChatRoomId(chatRoomId) ?: return null - val ceremony = database.dkgSessionDao().getSessionById(state.dkgSessionId) ?: return null - val ceremonyRoom = database.chatRoomDao().findChatRoomById(ceremony.chatRoomId) ?: return null - return ceremony to ceremonyRoom - } - - /** The ceremony's participants, or null when this device holds no record of them. */ - private suspend fun foundersOf(database: GizaDatabase, ceremony: DkgSession?): Set? { - ceremony ?: return null - ceremony.participantPublicKeySet()?.let { return it } - val ceremonyRoom = database.chatRoomDao().findChatRoomById(ceremony.chatRoomId) ?: return null - return ChillDkgRitualManager.participantsOf(ceremony, ceremonyRoom) - } - - /** - * The admins a subgroup's parent certified it with, or nothing for a group - * with no parent. Only read off a state that `GroupKeyStateManager.stateFrom` - * kept, which it does only for a certificate that checked out. - */ - private fun certifiedAdmins(birthCertificateJson: String?): Set = - birthCertificateJson - ?.let { Event.fromJsonOrNull(it) } - ?.let { SubgroupBirthCertificateEvent.parseAdminPublicKeys(it.tags).toSet() } - .orEmpty() -} 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 77b933e3..cbddf6e8 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/MarmotGroupCreation.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/MarmotGroupCreation.kt @@ -322,6 +322,18 @@ object MarmotGroupCreation { return ChillDkgRitualManager.participantsOf(ceremony, ceremonyRoom) - holdingLeaves } + /** + * The ceremony that made [chatRoomId]'s key, as this device holds it, and the + * room it ran in -- or null where this device holds no key state for the room, + * no record of that ceremony, or no longer the room it ran in. + */ + suspend fun ceremonyOf(database: GizaDatabase, chatRoomId: String): Pair? { + val state = database.groupKeyStateDao().getByChatRoomId(chatRoomId) ?: return null + val ceremony = database.dkgSessionDao().getSessionById(state.dkgSessionId) ?: return null + val ceremonyRoom = database.chatRoomDao().findChatRoomById(ceremony.chatRoomId) ?: return null + return ceremony to ceremonyRoom + } + /** * Invites the founding members [room]'s founding invite never reached -- see * [uninvitedFounders] -- in one commit, as [create] would have. 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 9231f344..aa814b0a 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/repository/ChatRepository.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/repository/ChatRepository.kt @@ -19,7 +19,6 @@ import mobi.giza.compose.database.model.Participant import mobi.giza.compose.database.model.intermdiate.LocalChatMessage import mobi.giza.compose.database.model.intermdiate.LocalChatRoom import mobi.giza.compose.database.model.types.MarmotReindexReport -import mobi.giza.compose.managers.FoundingAdmins import mobi.giza.compose.managers.MarmotGroupCreation import mobi.giza.compose.managers.SubgroupManager import mobi.giza.compose.nostr.MarmotProfile @@ -369,21 +368,6 @@ interface ChatRepository { /** Accepts [offerId]. Returns null when the acceptance went out, or why it could not. */ suspend fun acceptPromotion(localChatRoom: LocalChatRoom, offerId: HexKey): String? - /** - * Adds [publicKeys] to a current-profile room's admin policy, as an admin of - * it: one commit through the publish gate, additions only. The repair for a - * room missing founding members from its admins -- see [foundingAdmins] and - * docs/robust-group-admins.md, Phase 3. - */ - suspend fun addAdmins(localChatRoom: LocalChatRoom, publicKeys: Set) - - /** - * Whether [chatRoomId]'s admin policy names every member of the ceremony that - * made its key, as this device's own record of that ceremony has them. See - * `FoundingAdmins`. - */ - suspend fun foundingAdmins(chatRoomId: String): FoundingAdmins.Check - /** * Whether [memberPublicKey] holds a live share of the room's key, and so * whether a removal leaves them able to help sign until the shares are @@ -650,11 +634,6 @@ interface ChatRepository { override suspend fun removeMember(localChatRoom: LocalChatRoom, memberPublicKey: HexKey) = Unit - override suspend fun addAdmins(localChatRoom: LocalChatRoom, publicKeys: Set) = Unit - - override suspend fun foundingAdmins(chatRoomId: String): FoundingAdmins.Check = - FoundingAdmins.Check.NotKeyBacked - override suspend fun holdsShare(localChatRoom: LocalChatRoom, memberPublicKey: HexKey): Boolean = false override suspend fun rotateSharesWithout(localChatRoom: LocalChatRoom, memberPublicKey: HexKey): String? = null 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 c333056b..d2a48d34 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 @@ -107,10 +107,6 @@ import mobi.giza.compose.resources.founding_members_invited import mobi.giza.compose.resources.invite_them import mobi.giza.compose.resources.s_took_part_in_the_key_ceremony_but_were_not_invited import mobi.giza.compose.resources.not_every_founding_member_was_invited -import mobi.giza.compose.resources.founding_members_made_admins_requested -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 @@ -265,7 +261,6 @@ fun ChatRoomDetailScreen( val noKeyToRotate = stringResource(Res.string.rotation_no_key) val keyStateRequested = stringResource(Res.string.key_state_requested) val rotationHeldAfterRemoval = stringResource(Res.string.rotation_held_after_removal) - val madeAdminsRequested = stringResource(Res.string.founding_members_made_admins_requested) val foundersInvited = stringResource(Res.string.founding_members_invited) val foundersHaveNoKeyPackage = stringResource(Res.string.founding_members_have_no_key_package) @@ -574,36 +569,10 @@ fun ChatRoomDetailScreen( } } - // The founding members, where the room is not as the - // ceremony that made its key left it: founders its - // policy does not list as admins, or founders its - // founding invite never reached. Under the key and the - // parent, because it is about the same thing -- who the - // group that made this room is. docs/robust-group-admins.md, - // Phase 5. - if (chatRoomDetailUIState.missingFoundingAdmins.isNotEmpty()) { - item { - FoundingMembersCard( - title = stringResource(Res.string.founding_members_are_not_admins), - body = stringResource( - Res.string.s_took_part_in_the_key_ceremony_but_are_not_admins, - chatRoomDetailUIState.founderNamesFor(chatRoomDetailUIState.missingFoundingAdmins), - ), - // An admin of a room the app governs: the - // repair is a commit only they can make. - actionLabel = stringResource(Res.string.make_them_admins) - .takeIf { chatRoomDetailUIState.canGovern }, - isActionPending = chatRoomDetailViewModel.isActionPending.value, - onAction = { - chatRoomDetailViewModel.addMissingFoundingAdmins( - localChatRoom = chatRoomDetailUIState.localChatRoom, - missing = chatRoomDetailUIState.missingFoundingAdmins, - ) { failure -> notify(failure ?: madeAdminsRequested) } - }, - ) - } - } - + // The founding members the founding invite never + // reached. Under the key and the parent, because it is + // about the same thing -- who the group that made this + // room is. docs/robust-group-admins.md, Phase 5. if (chatRoomDetailUIState.uninvitedFounders.isNotEmpty()) { item { FoundingMembersCard( @@ -1906,8 +1875,8 @@ private fun RotationRunningCard(running: SharesSummary.Running, onAbandon: () -> /** * Something about this room's founding members that is not as the ceremony - * left it -- founders it does not list as admins, or founders its invite never - * reached -- and, where this device can, the one action that repairs it. + * left it -- founders its invite never reached -- and, where this device can, + * the one action that repairs it. * * On the error container: the room works, but not as the group that made it * agreed, and that is worth more than a supporting line. docs/robust-group-admins.md, 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 1a71bb55..4e8964df 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 @@ -22,7 +22,6 @@ import kotlinx.coroutines.IO import kotlinx.coroutines.Job import kotlinx.coroutines.flow.debounce import kotlinx.coroutines.launch -import mobi.giza.compose.managers.FoundingAdmins import mobi.giza.compose.managers.MarmotGroupCreation import mobi.giza.compose.database.model.intermdiate.LocalChatRoom import mobi.giza.compose.database.model.types.MarmotReindexReport @@ -120,11 +119,8 @@ class ChatRoomDetailViewModel( val me = localChatRoom.chatRoom.userPublicKey val roomIsOpen = !isDisbanded && localChatRoom.chatRoom.leftGroupAt == null // The founding members, against what the ceremony that made the - // room's key said: who the policy leaves out, and who the founding - // invite never reached. docs/robust-group-admins.md, Phases 3 and 4. - val missingFoundingAdmins = (chatRepository.foundingAdmins(chatRoomId) as? FoundingAdmins.Check.Missing) - ?.publicKeys - .orEmpty() + // room's key said: who the founding invite never reached. + // docs/robust-group-admins.md, Phase 4. val uninvitedFounders = chatRepository.uninvitedFounders(localChatRoom) ChatRoomDetailUIState.Loaded( @@ -163,9 +159,8 @@ class ChatRoomDetailViewModel( .onFailure { if (it is CancellationException) throw it } .getOrNull() ?.let { it.id to it.from }, - missingFoundingAdmins = missingFoundingAdmins, uninvitedFounders = uninvitedFounders, - founderNames = (missingFoundingAdmins + uninvitedFounders).associateWith { publicKey -> + founderNames = uninvitedFounders.associateWith { publicKey -> nostrRepository.getProfileWithPublicKey(publicKey)?.humanReadableNameOrPubkey() ?: publicKey.take(SHORTENED_PUBLIC_KEY_LENGTH) }, @@ -302,24 +297,6 @@ class ChatRoomDetailViewModel( } } - /** - * Adds the founding members the room's admin policy is missing, as an admin, - * and reloads the screen. One commit, applied when a relay accepts it, so the - * warning stays until then. docs/robust-group-admins.md, Phase 3. - */ - fun addMissingFoundingAdmins(localChatRoom: LocalChatRoom, missing: Set, onDone: (String?) -> Unit = {}) { - if (isActionPending.value) return - isActionPending.value = true - viewModelScope.launch(Dispatchers.IO) { - val failure = runCatching { chatRepository.addAdmins(localChatRoom, missing) }.exceptionOrNull() - initiateChatRoomDetail() - viewModelScope.launch(Dispatchers.Main) { - isActionPending.value = false - onDone(failure?.message) - } - } - } - /** * Finishes the room's founding invite, and reloads the screen. Reports null * when it went out, or why not -- naming the founders still without a key diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/ChatRoomDetailUIState.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/ChatRoomDetailUIState.kt index 450d25a2..d416ab75 100755 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/ChatRoomDetailUIState.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/ChatRoomDetailUIState.kt @@ -121,13 +121,6 @@ sealed interface ChatRoomDetailUIState { * docs/member-admin-promotion.md, Phase 8. */ val promotionOffer: Pair? = null, - /** - * Members of the ceremony that made this room's key whom its admin policy - * does not name -- empty when it names them all, and when this device has - * no record of the ceremony to check against. Read through - * `FoundingAdmins.check`; docs/robust-group-admins.md, Phase 3. - */ - val missingFoundingAdmins: Set = emptySet(), /** * Founding members this room's founding invite never reached -- only ever * non-empty on the device that made the room, while it is still at epoch 0. @@ -136,9 +129,8 @@ sealed interface ChatRoomDetailUIState { */ val uninvitedFounders: Set = emptySet(), /** - * What to call the founders the two sets above name. They need not be in - * this room -- an uninvited one is not, by definition -- so the room's own - * rows cannot be asked. + * What to call the founders [uninvitedFounders] names. They are not in this + * room, by definition, so the room's own rows cannot be asked. */ val founderNames: Map = emptyMap(), /** diff --git a/composeApp/src/commonTest/kotlin/mobi/giza/compose/database/model/intermdiate/ChatRoomLastMessagePreviewTest.kt b/composeApp/src/commonTest/kotlin/mobi/giza/compose/database/model/intermdiate/ChatRoomLastMessagePreviewTest.kt index d972e93c..9b8d1ffe 100644 --- a/composeApp/src/commonTest/kotlin/mobi/giza/compose/database/model/intermdiate/ChatRoomLastMessagePreviewTest.kt +++ b/composeApp/src/commonTest/kotlin/mobi/giza/compose/database/model/intermdiate/ChatRoomLastMessagePreviewTest.kt @@ -7,6 +7,7 @@ import mobi.giza.compose.database.model.Profile import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertNull +import kotlin.test.assertTrue import kotlin.time.Instant /** @@ -172,6 +173,19 @@ class ChatRoomLastMessagePreviewTest { } } + /** + * No longer written, but rows of it are still on devices, written as the user's own. + * Out of the set, each one would render as a bubble from the user. + * docs/remove-founding-admins-card.md, D3. + */ + @Test + fun `a retired caption type still renders as a caption`() { + assertTrue( + ChatMessage.TYPE_FOUNDING_ADMINS_MISSING in ChatMessage.MEMBERSHIP_TYPES, + "it would render as a chat bubble", + ) + } + /** * The bystanders' copy of a private message has no content. An empty preview would * read as the sender having said nothing, so the line says what the group can in diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/FoundingAdminsJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/FoundingAdminsJvmTest.kt deleted file mode 100644 index adb93818..00000000 --- a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/FoundingAdminsJvmTest.kt +++ /dev/null @@ -1,221 +0,0 @@ -package mobi.giza.compose.managers - -import androidx.room3.Room -import com.vitorpamplona.marmot.groups.currentAdminIdentities -import com.vitorpamplona.quartz.marmot.mip03GroupMessages.GroupEvent -import com.vitorpamplona.quartz.nip01Core.core.HexKey -import com.vitorpamplona.quartz.nip01Core.core.toHexKey -import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair -import kotlin.test.AfterTest -import kotlin.test.Test -import kotlin.test.assertEquals -import kotlin.test.assertIs -import kotlin.test.assertNotNull -import kotlin.test.assertTrue -import kotlin.time.Clock -import kotlin.time.Instant -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.runBlocking -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.model.ChatRoom -import mobi.giza.compose.database.model.DkgSession -import mobi.giza.compose.database.model.GroupKeyState -import mobi.giza.compose.database.model.Participant -import mobi.giza.compose.database.model.types.DkgRitualStage -import mobi.giza.compose.database.repository.DatabaseChatRepository -import mobi.giza.compose.database.repository.DatabaseNostrRepository -import mobi.giza.compose.extensions.toHex -import mobi.giza.compose.nostr.MarmotProfile -import mobi.giza.compose.nostr.Relays - -/** - * A device checking the room it holds against the ceremony it took part in. - * docs/robust-group-admins.md, Phase 3. - * - * The rooms here are made with [MarmotGroupCreation.create] and a list of admins - * on purpose: that is the one way to stand in for a room some other device made - * with fewer admins than the ceremony had, which is what the check is for. - */ -class FoundingAdminsJvmTest { - - private val db: GizaDatabase = getRoomDatabase(Room.inMemoryDatabaseBuilder()) - private val scope = CoroutineScope(Dispatchers.Default) - private val chatRepository = DatabaseChatRepository(db, scope) - private val nostrRepository = DatabaseNostrRepository(db, scope) - - @AfterTest - fun closeDb() = db.close() - - private val keyPair = KeyPair() - private val user = keyPair.pubKey.toHexKey() - private val alice = KeyPair().pubKey.toHexKey() - private val bob = KeyPair().pubKey.toHexKey() - private val founders = setOf(user, alice, bob) - - private val thresholdPublicKey = "02" + KeyPair().pubKey.toHexKey() - private val roomId = SharedKeyDerivation.marmotGroupId(thresholdPublicKey) - private val ceremonyRoomId = "ce1e".repeat(16) - private val sessionId = "the-ceremony" - - /** - * A room at [roomId] whose epoch-0 admins are [admins] -- whatever the ceremony - * said -- holding only its creator. Built from the steps `MarmotGroupCreation` - * takes, minus the invites: the check is about the policy, and listing an admin - * needs no key package of theirs. - */ - private suspend fun roomWithAdmins(admins: Set, profile: MarmotProfile = MarmotProfile.LEGACY) { - (founders + admins).forEach { MarmotStandIn.seedProfile(db, it) } - val created = MarmotGroupFactory.create( - creator = keyPair, - roomId = roomId, - name = "#Ekklesia", - description = SharedKeyDerivation.describe("Admins of Ekklesia."), - adminPublicKeys = admins, - relays = Relays.DefaultDMRelayList.map { it.url }, - profile = profile, - ) - assertNotNull( - chatRepository.getOrCreateChatRoom( - chatRoomId = roomId, - activeUserPublicKey = user, - relayHint = null, - defaultSubject = "#Ekklesia", - description = null, - mlsGroupState = created.group.saveState().encodeTls().toHex(), - ) - ) - chatRepository.recordMarmotRouting(chatRoomId = roomId, routingId = created.routingId) - } - - private suspend fun ceremony(participants: Set? = founders) { - db.chatRoomDao().upsert(ChatRoom(id = ceremonyRoomId, userPublicKey = user, subject = "Ekklesia", description = null, mlsGroupState = null)) - db.dkgSessionDao().upsert( - DkgSession( - id = sessionId, - chatRoomId = ceremonyRoomId, - coordinatorPublicKey = user, - userPublicKey = user, - threshold = 2, - participantCount = 3, - participantPublicKeys = participants?.let { DkgSession.formatParticipants(it) }, - subject = "Ekklesia", - stage = DkgRitualStage.COMPLETE, - hostPublicKey = user, - round1Random = "aa".repeat(32), - round2AuxRandom = "bb".repeat(32), - thresholdPublicKey = thresholdPublicKey, - secretShare = "cc".repeat(32), - ) - ) - } - - private suspend fun keyState() { - db.groupKeyStateDao().replace( - GroupKeyState( - chatRoomId = roomId, - dkgSessionId = sessionId, - thresholdPublicKey = thresholdPublicKey, - derivationPath = SharedKeyDerivation.formatPath(SharedKeyDerivation.MARMOT_ADMIN_GROUP_PATH), - announcedBy = roomId, - announcedAt = Clock.System.now(), - ) - ) - } - - @Test - fun `a room with no key behind it has no founders to check`(): Unit = runBlocking { - roomWithAdmins(setOf(user)) - assertEquals(FoundingAdmins.Check.NotKeyBacked, FoundingAdmins.check(db, roomId)) - } - - @Test - fun `a device that holds no ceremony for the room cannot check it`(): Unit = runBlocking { - roomWithAdmins(setOf(user)) - keyState() - assertEquals(FoundingAdmins.Check.CannotCheck, FoundingAdmins.check(db, roomId)) - } - - @Test - fun `a room made with every founder as an admin matches`(): Unit = runBlocking { - roomWithAdmins(founders) - ceremony() - keyState() - assertEquals(FoundingAdmins.Check.Matches, FoundingAdmins.check(db, roomId)) - } - - @Test - fun `a room made by a device that listed only itself is missing the others`(): Unit = runBlocking { - roomWithAdmins(setOf(user)) - ceremony() - keyState() - assertEquals(FoundingAdmins.Check.Missing(setOf(alice, bob)), FoundingAdmins.check(db, roomId)) - } - - @Test - fun `a ceremony from before its participant list falls back to its room's members`(): Unit = runBlocking { - roomWithAdmins(setOf(user)) - ceremony(participants = null) - db.participantDao().upsert(founders.map { Participant(participantPublicKey = it, chatRoomId = ceremonyRoomId, relayHint = null) }) - keyState() - assertEquals(FoundingAdmins.Check.Missing(setOf(alice, bob)), FoundingAdmins.check(db, roomId)) - } - - /** What the Welcome path writes: one line naming who is missing, and none when nobody is. */ - @Test - fun `the room says who it is missing, once, and only when someone is`(): Unit = runBlocking { - roomWithAdmins(setOf(user)) - ceremony() - keyState() - - FoundingAdmins.announceIfMissing(db, roomId, user) - val lines = db.chatMessageDao().getChatMessagesByChatRoomId(roomId).map { it.chatMessage } - .filter { it.messageType == ChatMessage.TYPE_FOUNDING_ADMINS_MISSING } - val line = lines.single() - assertTrue(alice.take(8) in line.content && bob.take(8) in line.content, line.content) - assertTrue(ChatMessage.TYPE_FOUNDING_ADMINS_MISSING in ChatMessage.MEMBERSHIP_TYPES, "it would render as a chat bubble") - } - - @Test - fun `a room that names every founder says nothing`(): Unit = runBlocking { - roomWithAdmins(founders) - ceremony() - keyState() - - assertEquals(FoundingAdmins.Check.Matches, FoundingAdmins.announceIfMissing(db, roomId, user)) - assertTrue(db.chatMessageDao().getChatMessagesByChatRoomId(roomId).none { - it.chatMessage.messageType == ChatMessage.TYPE_FOUNDING_ADMINS_MISSING - }) - } - - /** - * The repair: one commit that adds the missing founders to the policy and - * leaves every admin already there in place. On the current profile, where - * the app governs a room; the relay's OK is played by hand. - */ - @Test - fun `an admin puts the missing founders back into the policy`(): Unit = runBlocking { - roomWithAdmins(setOf(user), MarmotProfile.CURRENT) - ceremony() - keyState() - val missing = assertIs(FoundingAdmins.check(db, roomId)).publicKeys - - chatRepository.addAdmins(db.chatRoomDao().findChatRoomById(roomId)!!, missing) - okTheLatestCommit() - - val room = db.chatRoomDao().findChatRoomById(roomId)!! - val group = assertNotNull(db.marmotEngine.groupFor(room.routingId)) - assertEquals(founders, group.currentAdminIdentities()) - assertEquals(FoundingAdmins.Check.Matches, FoundingAdmins.check(db, roomId)) - } - - private suspend fun okTheLatestCommit() { - val event = db.nostrEventDao().getMLSGroupEvents(since = Instant.fromEpochSeconds(0), limit = 20) - .filter { it.kind == GroupEvent.KIND } - .last { db.marmotCommitResultDao().getMarmotCommitRequestById(it.id) != null } - val request = assertNotNull(db.broadcastNostrEventRequestDao().getFirstBroadcastNostrEventRequestByNostrEventId(event.id)) - nostrRepository.broadcastProcessed(request, "published") - } -} 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 ab4888af..fb2d8446 100644 --- a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/RobustGroupAdminsJvmTest.kt +++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/RobustGroupAdminsJvmTest.kt @@ -20,6 +20,7 @@ import kotlin.test.assertFalse import kotlin.test.assertEquals import kotlin.test.assertIs import kotlin.test.assertNotNull +import kotlin.test.assertNull import kotlin.test.assertTrue import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers @@ -480,9 +481,8 @@ class RobustGroupAdminsJvmTest { val group = assertNotNull(room.chatRoom.toMlsGroup(), "$joiner holds no group ($profile)") assertEquals(setOf(creator.publicKey), group.currentAdminIdentities(), "$joiner's admin policy ($profile)") assertFalse(group.isLocalAdmin(), "$joiner is not an admin of a room its creator runs ($profile)") - assertEquals( - FoundingAdmins.Check.NotKeyBacked, - FoundingAdmins.check(joiner.db, soloRoomId), + assertNull( + joiner.db.groupKeyStateDao().getByChatRoomId(soloRoomId), "no key behind it, so no founders to check ($profile)", ) } diff --git a/docs/README.md b/docs/README.md index e871c501..fb830afc 100644 --- a/docs/README.md +++ b/docs/README.md @@ -40,8 +40,9 @@ the [retired](./retired/) notes now. | [admin-change-rotation.md](./admin-change-rotation.md) | an admin change carries its rotation with it: a phased plan, built but for its device session, in which the rotation that follows removing an admin, and the one before a first promotion, asks nobody, because the group's signature on the change already decided who is withheld, and in which admin changes and rotations take turns. Covers the five ways the two overlap today, a removed admin who keeps a live share among them, and the one check a device makes to take part unasked | | [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 | +| [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 (since removed), 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 | +| [remove-founding-admins-card.md](./remove-founding-admins-card.md) | taking out the "Founding members aren't admins" card, its repair and the Welcome line behind it -- phased and built. Covers why a founder missing from the policy stopped meaning a fault once admins could be demoted, why the check cannot be taught the difference, and why the retired caption type stays | Start with the ceremony if you are new to this area; the Marmot notes all assume it. Read the skipped-keys note before debugging any "the other device never got it" diff --git a/docs/remove-convenient-groups.md b/docs/remove-convenient-groups.md index 45b6a3b2..fd3a593c 100644 --- a/docs/remove-convenient-groups.md +++ b/docs/remove-convenient-groups.md @@ -25,6 +25,11 @@ lists where the build differed: Written against `e78dfe50`. +`FoundingAdmins.Check.NotKeyBacked`, which the phases below name as the test for "no key +behind the room", is gone with the rest of that check +([remove-founding-admins-card.md](./remove-founding-admins-card.md)). The same test is +now a room with no `GroupKeyState` row, which is what `RobustGroupAdminsJvmTest` asserts. + Read [robust-group-admins.md](./robust-group-admins.md) first; it describes what a robust group is in the code, and this plan leaves that unchanged. [subgroups.md](./subgroups.md) holds the reasoning for the three-member floor that Phase 3 moves. diff --git a/docs/remove-founding-admins-card.md b/docs/remove-founding-admins-card.md new file mode 100644 index 00000000..b013fbb9 --- /dev/null +++ b/docs/remove-founding-admins-card.md @@ -0,0 +1,295 @@ +# The "Founding members aren't admins" card goes + +A phased plan to take out the warning card that the group detail screen shows when a keyed +room's admin policy leaves out someone who took part in the key ceremony. It covers the +card, its "Make them admins" repair, the transcript line written at the Welcome that sends +the reader to the card, and the check behind all three. + +**Built**, phases 0-5, one commit each on `claude/founding-members-admin-card-b2b644`. +The build followed the plan as written. Phase 3 kept its own commit: `FoundingAdminsJvmTest` +calls `announceIfMissing` directly, so it still passed until Phase 4 deleted both. +`:composeApp:jvmTest` passed after Phase 4 with 1382 tests. **Not run:** the three device +checks under "Checking the work" have not been tried on a device. + +Written against `b7de119e` on `giza`. Read +[robust-group-admins.md](./robust-group-admins.md), Phases 3 and 5, which added what this +plan takes out, and [member-admin-promotion.md](./member-admin-promotion.md), Phase 9, which +is why it has to go. + +--- + +## Why + +`FoundingAdmins.check` answers one question: *founders minus the policy's admins*, where +"founders" means the ceremony's participants plus, for a subgroup, the admins named in +its birth certificate. When robust-group-admins was written, nobody could stop being an +admin of a keyed room. So the only way a founder could be missing from the policy was a +fault: a buggy or older creator, or a Bennu peer, had listed fewer admins. The card called +that an error, used the error container, and offered to repair it. + +That is no longer the only way, so the check now gives wrong answers: + +- **Demotion** (`51eda2d2`, member-admin-promotion Phase 9). The group's signature takes + an admin out of the policy. Every device that took part in the ceremony then shows the + card with that person's name, in red, saying the room "doesn't list them as admins". + This is true, but it is something the group decided, not a fault. +- **Stepping down** (`bb35d73c`). An admin of a keyed room asks another admin to propose + their removal. The result is the same: a founder who is no longer in the policy, because + they asked to be taken out. +- **The repair undoes the decision.** "Make them admins" calls `addAdmins`. In a governed + room that is `GovernanceManager.propose` with the old policy plus the demoted founder. One + tap proposes reversing a change the quorum just signed. The offer is made to every admin, + and nothing says what it reverses. + +The check cannot tell a fault from a decision. The policy keeps no history, and a device +welcomed after the demotion has no record of it. The card can only be right where nobody +has ever been demoted, and that is less true with every release. + +The guarantee the card was a backstop for is still in place: **every founding member is an +admin when the group is made**. `MarmotGroupCreation` makes it so (robust-group-admins +Phases 1, 2 and 4), and `RobustGroupAdminsJvmTest` pins it on every device. This plan takes +out only the after-the-fact warning. + +## What stays + +- **"Not every founding member was invited"**, the second `FoundingMembersCard`, and its + "Invite them" action. It is shown only on the creator's device, only while the room is at + epoch 0, and demotion cannot happen before epoch 0 ends. `uninvitedFounders`, + `finishFoundingInvite`, `inviteFounders` and `founderNames` all stay. +- **`FoundingMembersCard`** stays, with the invite card as its one caller. Do not inline + it; that only adds noise to the diff. +- **`ChatMessage.TYPE_FOUNDING_ADMINS_MISSING`** and its place in `MEMBERSHIP_TYPES`. See D3. +- Everything in `RobustGroupAdminsJvmTest` that asserts the founding set and the policy + directly. + +## Decisions + +### D1. Remove the card. Do not teach it about demotion + +The other way would keep the card and subtract the founders who were demoted or who stepped +down. That needs a record of signed demotions that every device agrees on. The +`TYPE_ADMIN_REMOVED` transcript rows are per device, and a member welcomed later has none of +them. The policy is the only shared record, and it holds only the present. A check fed +history that some devices have and others lack would show the card on some phones and not +others. That is worse than not showing it. + +If detecting an under-listed policy from a Bennu peer is wanted again later, it belongs at +the Welcome, before any commit could have demoted anyone (see D3). It does not belong on the +detail screen, which runs at every later epoch. + +### D2. The repair goes with the card + +`ChatRoomDetailViewModel.addMissingFoundingAdmins`, `ChatRepository.addAdmins` and +`MarmotOutboundDao.addAdmins` have no other caller. Member promotion goes through +`PromotionManager` and its offer/accept flow, which also enrolls the new admin in the key. +`addAdmins` did not enroll anyone; it relied on founders already holding shares. A path +that adds an admin without the promotion's checks should not outlive the one screen that +needed it. + +### D3. Stop writing the Welcome line. Keep its type + +`FoundingAdmins.announceIfMissing` runs at the Welcome. At that moment the room is at +the epoch of the founding invite, so it cannot have been caused by a demotion. On its own +it is still correct. It goes anyway because its sentence ends "An admin can add them back +from the room's details", and after this plan nothing there does that. Rewording it to +point nowhere would leave a warning nobody can act on. That is the kind of line +`EmptyState` and `ErrorState` were introduced to remove. + +The constant stays in `MEMBERSHIP_TYPES` permanently. Rows of this type are already +stored on devices. `MEMBERSHIP_TYPES`' own KDoc says that a type missing from it renders +"as a chat bubble -- silently, and looking exactly like the inviter having said" it. In +this case the "inviter" is the device's own user, because the row was written with +`isUserMessage = true`. The KDoc changes to "no longer written". + +Do not delete the existing rows. They were true when they were written, and they appear +only in rooms whose creator under-listed admins, which is rare. Deleting history the user +has already read costs more than one stale pointer. + +### D4. `FoundingAdmins` loses everything but `ceremonyOf`, and `ceremonyOf` moves + +After D1-D3, the only code left in `FoundingAdmins` that anything calls is `ceremonyOf`, +which `DatabaseChatRepository.finishFoundingInvite` and `.uninvitedFounders` use. It moves +next to its callers' subject, as `MarmotGroupCreation.ceremonyOf`, and `FoundingAdmins.kt` +is deleted. A `FoundingAdmins` object with nothing about founding admins left in it would +be a misleading name. + +`foundersOf` and `certifiedAdmins` are private to `check` and go with it. Nothing else reads +the birth certificate's admin list: `SubgroupBirthCertificateEvent.parseAdminPublicKeys` +stays, because certificate verification and its own tests use it. + +--- + +## Phases + +One commit each, in order, and each one compiles and passes `jvmTest` on its own. Phase 0 +comes first so that nothing is deleted before what has to outlive it is pinned somewhere +else. + +### Phase 0: pin what outlives the check + +Two assertions currently live in code that Phase 4 deletes. + +- **The caption type.** `FoundingAdminsJvmTest` line 178 asserts + `TYPE_FOUNDING_ADMINS_MISSING in MEMBERSHIP_TYPES`. Move it to + `ChatRoomLastMessagePreviewTest`, in `commonTest`, which already reads `MEMBERSHIP_TYPES`. + Name it `a retired caption type still renders as a caption` and give it a one-line + comment pointing here (D3). +- **The legacy-room assertion.** `RobustGroupAdminsJvmTest`, lines 483-487, asserts + `FoundingAdmins.check(...) == NotKeyBacked` for a room run by its creator. What the + assertion means is "there is no key behind it". Say that directly: + `assertNull(joiner.db.groupKeyStateDao().getByChatRoomId(soloRoomId), ...)`, with the + same message. Drop the `FoundingAdmins` import if this was its last use in the file. + +**Done when** `:composeApp:jvmTest` passes, and `git grep FoundingAdmins -- '*Test*'` finds +only `FoundingAdminsJvmTest`. + +### Phase 1: the card goes + +All in `ui/composable/ChatRoomDetailScreen.kt`: + +- Delete the `if (chatRoomDetailUIState.missingFoundingAdmins.isNotEmpty()) { item { … } }` + block (lines 578-599). +- Rewrite the comment above it (lines 571-577), which describes both cards, to describe + only the invite card: founders the founding invite never reached, under the key and the + parent for the same reason as before. +- Delete `val madeAdminsRequested = …` (line 263). +- Delete the imports of `founding_members_are_not_admins`, + `s_took_part_in_the_key_ceremony_but_are_not_admins`, `make_them_admins` and + `founding_members_made_admins_requested`. +- `FoundingMembersCard`'s KDoc (lines ~1890-1898): keep the error-container rationale, + and change "founders" wording that assumed two callers. + +In `composeResources/values/strings.xml`, delete the same four strings (lines 533-536). No +other file uses any of them. Check with `git grep` before deleting, since the Compose +Resources accessor fails at compile time and not at review. + +**Done when** the detail screen of a keyed room where a founder has been demoted shows the +members, the key and the Shares section, and no red card. `./gradlew :composeApp:m3Audit` +passes. Its literals report should not move, because the removed strings came from the +catalogue. + +### Phase 2: the screen stops asking + +- `ui/view/state/ChatRoomDetailUIState.kt`: delete `missingFoundingAdmins` and its KDoc + (lines ~124-130). In `founderNames`' KDoc, "the two sets above" becomes + "`uninvitedFounders`". +- `ui/view/model/ChatRoomDetailViewModel.kt`: + - Delete the `missingFoundingAdmins` read (lines 125-127). Rewrite the comment above it to + mention only Phase 4. + - `founderNames = uninvitedFounders.associateWith { … }`. + - Delete `missingFoundingAdmins = missingFoundingAdmins,`. + - Delete `addMissingFoundingAdmins` and its KDoc (lines ~305-321). + - Drop the `FoundingAdmins` import. + +This also takes one repository call off every detail load. That call did a database read +and an MLS group decode on every visit. + +**Done when** `git grep -n missingFoundingAdmins` finds nothing. + +### Phase 3: the Welcome stops announcing + +- `database/dao/NostrDao.kt`: delete the `FoundingAdmins.announceIfMissing(…)` call and the + comment above it (lines ~982-992), and the import (line 70). `GroupKeyStateManager.adopt` + and its comment stay exactly as they are. +- `database/model/ChatMessage.kt`: rewrite `TYPE_FOUNDING_ADMINS_MISSING`'s KDoc as + retired. No longer written (link this note). Kept, and kept in `MEMBERSHIP_TYPES`, + because rows written before are still on devices and would otherwise render as a + bubble from the user. + +**Done when** a device welcomed into a room whose policy under-lists the founders writes no +transcript line. `FoundingAdminsJvmTest` still passes here: it calls `announceIfMissing` +directly, not through the Welcome. Phase 4 deletes both. + +### Phase 4: the check and the repair go + +- `managers/FoundingAdmins.kt`: move `ceremonyOf` to `MarmotGroupCreation` (D4), keeping + its KDoc, then delete the file. +- `database/repository/DatabaseChatRepository.kt`: the two `FoundingAdmins.ceremonyOf` + calls (lines 120, 126) become `MarmotGroupCreation.ceremonyOf`. Delete `addAdmins` + (line 791) and `foundingAdmins` (lines 795-802). +- `repository/ChatRepository.kt`: delete `addAdmins` and `foundingAdmins` from the + interface (lines ~372-385) and from the preview stub (lines 653-656). Drop the + `FoundingAdmins` import. +- `database/dao/MarmotOutboundDao.kt`: delete `addAdmins` and its KDoc (lines ~1091-1123). + Look again at its imports; `GovernanceManager` and `AdminPolicyV1` are used elsewhere in + the file, so they probably stay. +- `jvmTest/.../managers/FoundingAdminsJvmTest.kt`: delete it. Every case in it tests + `check`, `announceIfMissing` or `addAdmins`. +- Search for test fakes of `ChatRepository` that override the two removed members + (`git grep -n "override suspend fun addAdmins\|override suspend fun foundingAdmins"`) + and delete those overrides. + +**Done when** + +```bash +git grep -nE "FoundingAdmins|addAdmins|foundingAdmins\(|announceIfMissing|founding_members_are_not_admins|make_them_admins" -- composeApp iosApp +``` + +finds nothing, `TYPE_FOUNDING_ADMINS_MISSING` appears only in `ChatMessage.kt` and the +Phase 0 test, and `./gradlew :composeApp:compileDebugKotlinAndroid :composeApp:jvmTest` +passes. + +### Phase 5: docs + +- **This note**: mark it built, with a "where the build chose differently" table if it did. +- **[robust-group-admins.md](./robust-group-admins.md)**: under the "Built" paragraph, add + one line saying Phase 3's check, transcript line and repair, and the Phase 5 warning + card, were removed after admins of a keyed room could be demoted, with a link here. Leave + the phase text as written, as these notes do. Its phases are the reasoning. +- **[README.md](./README.md)**: add a row for this note. The robust-group-admins row's + summary mentions "the joiner's check against…"; add "(since removed)". +- **[remove-convenient-groups.md](./remove-convenient-groups.md)**: it names + `FoundingAdmins.Check.NotKeyBacked` four times (lines 54, 343, 356, 368) as the test for + "no key behind the room". That is plan text. Leave it, and add one sentence to its notes + section: the check is gone, and "no key behind it" now means no `GroupKeyState` row, + which is what Phase 0 here asserts. + +**Done when** `git grep -n FoundingAdmins docs` finds only those historical mentions and +this note. + +--- + +## Checking the work + +```bash +./gradlew :composeApp:m3Audit +``` + +```bash +./gradlew :composeApp:compileDebugKotlinAndroid :composeApp:jvmTest +``` + +```bash +./gradlew check +``` + +`check` also runs the brand and wallet audits. Nothing here touches either of them, but they +are the gate. + +On a device, which is not covered by any test above: + +1. Make a three-member group and let the ceremony finish. The detail screen shows no + card on any phone. This is the same as before. +2. Demote one founder with the group's signature. Previously every founder's phone showed + "Founding members aren't admins" naming them. Now none does. +3. Open a room that already has a "This room was created without … as an admin" line in + its transcript. It still renders as a centred caption, not as a bubble from you. + +## Risks + +- **An under-listing Bennu peer goes unremarked.** A room created by a Bennu build that + lists fewer admins is no longer flagged on the detail screen or in the transcript. The + member list still shows who is an admin (the "Admin" supporting text), so this is + visible but not called out. Accepted (D1). If it matters, the place to bring it back is + the Welcome, where it cannot be confused with a demotion. +- **Stale pointer in old transcript lines.** Rows written before Phase 3 still say "an + admin can add them back from the room's details". Accepted (D3). +- **A fake `ChatRepository` the search misses.** The compiler finds every one, so the risk + is a slow first build, not a wrong one. + +## Out of scope + +- The "Not every founding member was invited" card, `uninvitedFounders` and + `finishFoundingInvite`. See "What stays". +- Showing demotion history on the detail screen. +- Anything about how a room is created. The founding set is still every participant. diff --git a/docs/robust-group-admins.md b/docs/robust-group-admins.md index d395ea29..5e36fded 100644 --- a/docs/robust-group-admins.md +++ b/docs/robust-group-admins.md @@ -23,6 +23,12 @@ so, and it did nine times worth reading: Written against `fc437d05`. +**Since removed:** Phase 3's check, its transcript line and its repair, and the Phase 5 +warning card that showed them. Once an admin of a keyed room could be demoted or step +down, a founder missing from the policy was usually the group's decision, and the repair +offered to undo it. [remove-founding-admins-card.md](./remove-founding-admins-card.md) +has the reasoning. Phase 4's invite card stays. + Read [shared-key-ceremony.md](./shared-key-ceremony.md) and [ceremony-creation.md](./ceremony-creation.md) first.