From b75bbaf55c72140cce645679be52ed49cbd945b2 Mon Sep 17 00:00:00 2001 From: Kgothatso Ngako Date: Mon, 23 Nov 2026 02:19:57 +0200 Subject: [PATCH] feat: the confederation's screen takes over what its room offered (confederation-room-removal, Phase 6) ConfederationScreen gains Posts (with Add post for someone who holds a seat), Charter (signed, or Propose the charter for a seat-holder) and Signing (their attempts, the ones waiting on them first), and loses Open the confederation's room. The composer posts for a confederation through AddGroupPostRoute's new confederationId. A post or charter a role holder must answer is its own line, TYPE_CONFEDERATION_SIGNING_ASKED, written into each of their groups' rooms as theirs and classed as needing them. A signed post is owed to relays by every device that signed it. The room screens lose the confederation's card, its members' group labels, ConfederationRoomInfo, confederationOfRoom, the room's charter proposal and the confederation branches of the posts and profile view models; four strings go, and the ceremony room's banner stops saying the confederation works in its own room. Full jvmTest 2,001, all passing; m3, brand, wallet and Marmot audits pass. Co-Authored-By: Claude Opus 5.5 --- .../composeResources/values/strings.xml | 18 ++- .../compose/database/dao/ConfederationDao.kt | 4 + .../compose/database/model/ChatMessage.kt | 13 +- .../repository/DatabaseChatRepository.kt | 39 +----- .../DatabaseConfederationRepository.kt | 19 ++- .../managers/ConfederationSigningManager.kt | 12 +- .../notifications/NotificationClassifier.kt | 2 + .../giza/compose/repository/ChatRepository.kt | 19 +-- .../repository/ConfederationRepository.kt | 13 +- .../ui/composable/AddGroupPostScreen.kt | 3 + .../ui/composable/ChatRoomDetailScreen.kt | 70 ---------- .../ui/composable/ConfederationScreen.kt | 130 +++++++++++++++++- .../composable/EditGroupNostrProfileScreen.kt | 18 +-- .../ui/composable/navigation/GizaNavHost.kt | 1 + .../navigation/routes/AddGroupPostRoute.kt | 9 +- .../composable/widgets/chat/ChatTranscript.kt | 5 +- .../ui/view/model/AddGroupPostViewModel.kt | 26 ++-- .../ui/view/model/ChatRoomDetailViewModel.kt | 14 -- .../ui/view/model/ConfederationViewModel.kt | 52 ++++++- .../model/EditGroupNostrProfileViewModel.kt | 11 +- .../view/model/GroupNostrProfileViewModel.kt | 2 +- .../ui/view/model/GroupPostsViewModel.kt | 3 +- .../ui/view/state/AddGroupPostUIState.kt | 2 + .../ui/view/state/ChatRoomDetailUIState.kt | 19 --- .../ui/view/state/ConfederationUIState.kt | 16 ++- .../managers/ConfederationCeremonyJvmTest.kt | 1 - .../managers/ConfederationSigningJvmTest.kt | 57 ++++++-- .../ConfederationProfileScreensJvmTest.kt | 50 +++++++ docs/confederation-room-removal.md | 1 + 29 files changed, 402 insertions(+), 227 deletions(-) diff --git a/composeApp/src/commonMain/composeResources/values/strings.xml b/composeApp/src/commonMain/composeResources/values/strings.xml index bf190c18..6fd98311 100644 --- a/composeApp/src/commonMain/composeResources/values/strings.xml +++ b/composeApp/src/commonMain/composeResources/values/strings.xml @@ -758,7 +758,6 @@ The ceremony ended: %1$s %1$s: %2$d of %3$d admins to sign Formed - This is the room of the confederation %1$s. Its key is held by the admins of its groups together. Until the confederation can sign, who is in this room cannot change. The confederation's signature Approve Decline @@ -784,7 +783,6 @@ No changes to its profile have been proposed Edit profile How it was formed - Open the confederation's room This device knows nothing of that confederation This device holds no record of the confederation This group is not one of the confederation's @@ -820,10 +818,20 @@ Nothing This change edits no field shown here Being signed. Waiting on %1$s - %1$s: %2$s - Admins who joined a group after %1$s formed are not here. Open the confederation - The key ceremony for %1$s is complete. The confederation works in its own room now. + + The confederation has posted nothing yet + Charter + The confederation has signed its charter, naming its groups + The confederation has no charter yet + Signing + Nothing is being signed + Waiting for your answer + Being signed + Signed + Not signed + Couldn't propose the charter + The key ceremony for %1$s is complete. Its groups open it from their own screens. Inbox Inbox settings diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/dao/ConfederationDao.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/dao/ConfederationDao.kt index 2c432899..66cdaaba 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/dao/ConfederationDao.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/dao/ConfederationDao.kt @@ -94,6 +94,10 @@ abstract class ConfederationDao { @Query("SELECT * FROM ConfederationEvent WHERE confederationId = :confederationId AND kind = 1 ORDER BY eventCreatedAt DESC, id DESC") abstract fun observePosts(confederationId: HexKey): Flow> + /** The charters [confederationId] has signed that this device holds. */ + @Query("SELECT * FROM ConfederationEvent WHERE kind = ${ConfederationKinds.CHARTER} AND pubKey = :confederationId") + abstract fun observeChartersOf(confederationId: HexKey): Flow> + /** Every confederation that has signed a charter this device holds. */ @Query("SELECT DISTINCT pubKey FROM ConfederationEvent WHERE kind = ${ConfederationKinds.CHARTER}") abstract fun observeCharterAuthors(): Flow> 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 6835c034..6577619d 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 @@ -564,10 +564,20 @@ data class ChatMessage( /** A group's room, on its admins' devices: the group is now part of a formed confederation (Phase 12). */ const val TYPE_CONFEDERATION_FORMED = "confederationFormed" - /** The confederation's room: a proposal for it to sign, and one that did not finish (Phase 14). */ + /** + * A proposal for the confederation to sign, and one that did not finish (Phase 14), in the room + * of each group the person holds a seat in (docs/confederation-room-removal.md, D9). + */ const val TYPE_CONFEDERATION_SIGNING_PROPOSED = "confederationSigningProposed" const val TYPE_CONFEDERATION_SIGNING_FAILED = "confederationSigningFailed" + /** + * The confederation asking this person to sign, for their seats: a post or its charter, where + * every role holder answers as a person. Written by their own device, so it is theirs, and a + * notification asks for them (docs/confederation-room-removal.md, D9). + */ + const val TYPE_CONFEDERATION_SIGNING_ASKED = "confederationSigningAsked" + /** * A formed confederation's profile, decided by its groups (docs/confederation-profile.md, D8): * a group proposing a change, another endorsing or objecting to it, and the new profile once @@ -597,6 +607,7 @@ data class ChatMessage( TYPE_CONFEDERATION_CEREMONY_FAILED, TYPE_CONFEDERATION_FORMED, TYPE_CONFEDERATION_SIGNING_PROPOSED, + TYPE_CONFEDERATION_SIGNING_ASKED, TYPE_CONFEDERATION_SIGNING_FAILED, ) 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 3c42116d..739e5f94 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 @@ -382,14 +382,14 @@ class DatabaseChatRepository( emptyList() } - override suspend fun canSignAsConfederation(chatRoomId: String): Boolean { + override suspend fun canSignAsConfederation(confederationId: HexKey): Boolean { if (!ExperimentalFeatures.confederation) return false val me = activeIdentity.value?.takeIf { it.canSign }?.nostrPublicKey ?: return false - return ConfederationSigningManager.canSign(database, chatRoomId, me) + return ConfederationSigningManager.canSign(database, confederationId, me) } override suspend fun proposeAsConfederation( - localChatRoom: LocalChatRoom, + confederationId: HexKey, kind: Kind, tags: Array>, content: String, @@ -397,14 +397,13 @@ class DatabaseChatRepository( val identity = activeIdentity.value ?: throw IllegalStateException("No identity is signed in") val secret = identity.nostrPrivateKey ?: throw IllegalStateException("This identity cannot sign") return ConfederationSigningManager.propose( - database, localChatRoom.chatRoom.id, identity.nostrPublicKey, kind, tags, content, secret.value.toByteArray(), + database, confederationId, identity.nostrPublicKey, kind, tags, content, secret.value.toByteArray(), ).id } - override suspend fun proposeCharter(localChatRoom: LocalChatRoom): String { - val (kind, tags, content) = ConfederationSigningManager.charterTemplate(database, localChatRoom.chatRoom.id) - ?: throw IllegalStateException("This device holds no confederation for this room") - return proposeAsConfederation(localChatRoom, kind, tags, content) + override suspend fun confederationByline(confederationId: HexKey): Pair? { + val membership = mobi.giza.compose.managers.ConfederationProfileManager.membership(database, confederationId) ?: return null + return mobi.giza.compose.managers.ConfederationProfileManager.profiles(database, confederationId).newestProfile to membership.name } override suspend fun keyCeremonyOfRoom(chatRoomId: String): mobi.giza.compose.ui.view.state.KeyCeremonyLink? { @@ -423,30 +422,6 @@ class DatabaseChatRepository( mobi.giza.compose.managers.ConfederationProfileManager.membership(database, confederationId)?.groups ?.firstOrNull { database.chatRoomDao().findChatRoomById(it) != null } - override suspend fun confederationRoomInfo(chatRoomId: String): mobi.giza.compose.ui.view.state.ConfederationRoomInfo? = try { - mobi.giza.compose.managers.ConfederationSigningManager.held(database, chatRoomId)?.let { held -> - val names = held.plan.groups.associateWith { mobi.giza.compose.managers.ConfederationManager.nameOf(database, it) } - val people = held.plan.people.associateWith { mobi.giza.compose.managers.ConfederationManager.nameOf(database, it) } - mobi.giza.compose.ui.view.state.ConfederationRoomInfo( - confederationId = chatRoomId, - name = held.confederation.name, - groups = held.plan.groups.map { group -> - names.getValue(group) to held.plan.seats.filter { it.group == group }.map { people.getValue(it.admin) } - }, - groupsOfMember = held.plan.people.associateWith { person -> held.plan.seatsOf(person).map { names.getValue(it.group) } }, - homeGroupId = homeGroupOf(chatRoomId), - ) - } - } catch (e: Throwable) { - logger.e("Error reading the confederation of $chatRoomId", e) - null - } - - override suspend fun confederationOfRoom(chatRoomId: String): String? = - database.confederationCeremonyDao().getConfederation(chatRoomId) - ?.takeIf { ConfederationFormation.verifies(it) } - ?.name - override suspend fun canSign(chatRoomId: String): Boolean = try { FrostSigningManager.canSign(database, chatRoomId) } catch (e: Throwable) { diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/repository/DatabaseConfederationRepository.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/repository/DatabaseConfederationRepository.kt index daf8ae64..9c7e0023 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/repository/DatabaseConfederationRepository.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/repository/DatabaseConfederationRepository.kt @@ -21,6 +21,7 @@ import mobi.giza.compose.nostr.confederation.ConfederationProfileStatements import mobi.giza.compose.nostr.GroupNostrProfile import mobi.giza.compose.database.model.GroupSignedEvent import mobi.giza.compose.nostr.GroupPost +import mobi.giza.compose.nostr.frost.GroupKeyStateEvent import mobi.giza.compose.managers.ConfederationProfileRefusal import mobi.giza.compose.managers.FrostSigningManager import mobi.giza.compose.managers.InboxReplies @@ -166,8 +167,22 @@ class DatabaseConfederationRepository( override suspend fun formingProposalOf(confederationId: HexKey): HexKey? = database.confederationCeremonyDao().getConfederation(confederationId)?.proposalId - override suspend fun holdsRoomOf(confederationId: HexKey): Boolean = - database.chatRoomDao().findChatRoomById(confederationId) != null + override suspend fun holdsSeat(confederationId: HexKey, userPublicKey: HexKey): Boolean = + ConfederationSigningManager.canSign(database, confederationId, userPublicKey) + + override fun observeSigningAttempts(confederationId: HexKey, userPublicKey: HexKey): Flow> = + database.confederationCeremonyDao().observeAttempts(confederationId).map { attempts -> attempts.filter { it.userPublicKey == userPublicKey } } + + override fun observeCharterSigned(confederationId: HexKey): Flow = + database.confederationDao().observeChartersOf(confederationId).map { rows -> rows.any { GroupKeyStateEvent.isSignedByRoom(it.toEvent(), confederationId) } } + + override suspend fun proposeCharter(confederationId: HexKey): String { + val identity = activeIdentity.value ?: throw IllegalStateException("No identity is signed in") + val secret = identity.nostrPrivateKey ?: throw IllegalStateException("This identity cannot sign") + val (kind, tags, content) = ConfederationSigningManager.charterTemplate(database, confederationId) + ?: throw IllegalStateException("This device holds no record of the confederation") + return ConfederationSigningManager.propose(database, confederationId, identity.nostrPublicKey, kind, tags, content, secret.value.toByteArray()).id + } override suspend fun profileChangeProblem(chatRoomId: String, userPublicKey: HexKey, confederationId: HexKey): ProfileChangeProblem? { val membership = ConfederationProfileManager.membership(database, confederationId) ?: return ProfileChangeProblem.NoRecord diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/ConfederationSigningManager.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/ConfederationSigningManager.kt index 7d8d001d..add3e376 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/ConfederationSigningManager.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/ConfederationSigningManager.kt @@ -446,7 +446,8 @@ object ConfederationSigningManager { settleCrossing(database, sender, held, attempt, event.id) return database.confederationCeremonyDao().getAttempt(attemptId) } - announce(database, attempt, ChatMessage.TYPE_CONFEDERATION_SIGNING_PROPOSED, "A proposal for the confederation to sign: ${describe(event)}") + // This person answers it, as a person: their line asks them (D9). + announce(database, attempt, ChatMessage.TYPE_CONFEDERATION_SIGNING_ASKED, "The confederation asks you to sign ${describe(event)}") replayStoredMessages(database, held, attempt) return database.confederationCeremonyDao().getAttempt(attemptId) } @@ -684,6 +685,10 @@ object ConfederationSigningManager { confederationId = signed.pubKey, ) ) + // Published, by every device that signed it: with no room there is no screen to send it + // from, and the same event from several devices is one to a relay + // (docs/confederation-room-removal.md, D10). + database.confederationDao().markOwn(signed.id, attempt.id) } // A profile its groups decided: filed under the confederation beside the change it came from, // and owed to relays by the device that started the signing (docs/confederation-profile.md, D7). @@ -874,8 +879,9 @@ object ConfederationSigningManager { // The attempt, so the line opens it. Not a FROST session: the column has no key // onto one, and the transcript reads it by the line's type. frostSigningSessionId = attempt.id, - senderPublicKey = attempt.proposerPublicKey, - isUserMessage = false, + // An ask is to this device's owner, so it is theirs, as a FROST ask is (NotificationClassifier.NEEDS_YOU). + senderPublicKey = if (type == ChatMessage.TYPE_CONFEDERATION_SIGNING_ASKED) attempt.userPublicKey else attempt.proposerPublicKey, + isUserMessage = type == ChatMessage.TYPE_CONFEDERATION_SIGNING_ASKED, giftWrapPayloadId = null, marmotGroupEventId = null, marmotInnerEventId = null, diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/notifications/NotificationClassifier.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/notifications/NotificationClassifier.kt index 2b9bc0d6..50011d06 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/notifications/NotificationClassifier.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/notifications/NotificationClassifier.kt @@ -33,6 +33,8 @@ object NotificationClassifier { * session's own key), so unlike the other two categories they are not dropped for being ours. */ val NEEDS_YOU: Set = setOf( + // The confederation asking for this person's answer, for their seats (docs/confederation-room-removal.md, D9). + Line.TYPE_CONFEDERATION_SIGNING_ASKED, Line.TYPE_DKG_APPROVAL_NEEDED_HOST_KEY, Line.TYPE_DKG_APPROVAL_NEEDED_ROUND_1, Line.TYPE_DKG_APPROVAL_NEEDED_ROUND_2, 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 99c3ce9f..0f63acfd 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/repository/ChatRepository.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/repository/ChatRepository.kt @@ -161,9 +161,6 @@ interface ChatRepository { */ suspend fun keyCeremonyOfRoom(chatRoomId: String): mobi.giza.compose.ui.view.state.KeyCeremonyLink? = null - /** This room's confederation, said in its groups, if it is one's room. docs/confederation-profile.md, D9. */ - suspend fun confederationRoomInfo(chatRoomId: String): mobi.giza.compose.ui.view.state.ConfederationRoomInfo? = null - /** * The formed confederations the group of [chatRoomId] is a member of, as (id, name), by record or * charter: what the group's screen lists, each opening the confederation's own screen. @@ -171,22 +168,18 @@ interface ChatRepository { */ suspend fun memberConfederations(chatRoomId: String): List> = emptyList() - /** The confederation whose room [chatRoomId] is, by name, if its record verifies here. docs/confederation.md, Phase 13. */ - suspend fun confederationOfRoom(chatRoomId: String): String? = null - /** What [chatRoomId]'s screen says about its direct messages, to [userPublicKey]. docs/group-threshold-ecdh.md. */ suspend fun groupDmRow(chatRoomId: String, userPublicKey: HexKey): mobi.giza.compose.ui.view.state.GroupDmRow? = null - /** Whether this device holds a role in the confederation whose room [chatRoomId] is. docs/confederation.md, Phase 15. */ - suspend fun canSignAsConfederation(chatRoomId: String): Boolean = false + /** Whether this device holds a seat in [confederationId], and so can propose what it signs. docs/confederation.md, Phase 15. */ + suspend fun canSignAsConfederation(confederationId: HexKey): Boolean = false - /** Proposes that the confederation whose room [localChatRoom] is sign one event. The attempt's id. */ - suspend fun proposeAsConfederation(localChatRoom: LocalChatRoom, kind: Kind, tags: Array>, content: String): String = + /** Proposes that [confederationId] sign one event. The attempt's id. docs/confederation-room-removal.md, D9. */ + suspend fun proposeAsConfederation(confederationId: HexKey, kind: Kind, tags: Array>, content: String): String = throw UnsupportedOperationException("No confederation here") - /** Proposes that the confederation sign its charter: its groups, under its name. The attempt's id. */ - suspend fun proposeCharter(localChatRoom: LocalChatRoom): String = - throw UnsupportedOperationException("No confederation here") + /** Who [confederationId] says it is, and its name: the byline over a post the confederation is to sign. */ + suspend fun confederationByline(confederationId: HexKey): Pair? = null /** * Why these members cannot hold a subgroup ceremony together, or null when diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/repository/ConfederationRepository.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/repository/ConfederationRepository.kt index 9eba7eb5..29edab31 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/repository/ConfederationRepository.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/repository/ConfederationRepository.kt @@ -145,8 +145,17 @@ interface ConfederationRepository { /** The proposal the confederation was formed from, where this device holds it. */ suspend fun formingProposalOf(confederationId: HexKey): HexKey? = null - /** Whether this device holds the confederation's own room. */ - suspend fun holdsRoomOf(confederationId: HexKey): Boolean = false + /** Whether [userPublicKey] holds a seat in the confederation, and so can propose what it signs and answer for it. */ + suspend fun holdsSeat(confederationId: HexKey, userPublicKey: HexKey): Boolean = false + + /** [userPublicKey]'s attempts at the confederation signing something, newest first (docs/confederation-room-removal.md, D9). */ + fun observeSigningAttempts(confederationId: HexKey, userPublicKey: HexKey): Flow> = flowOf(emptyList()) + + /** Whether this device holds a charter the confederation has signed. */ + fun observeCharterSigned(confederationId: HexKey): Flow = flowOf(false) + + /** Proposes that the confederation sign its charter: its groups, under its name. The attempt's id. */ + suspend fun proposeCharter(confederationId: HexKey): String = throw UnsupportedOperationException("No confederation here") /** * Why [userPublicKey] cannot put a change to [confederationId]'s profile to the group of diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/AddGroupPostScreen.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/AddGroupPostScreen.kt index ec70d970..1ec3defd 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/AddGroupPostScreen.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/AddGroupPostScreen.kt @@ -90,6 +90,7 @@ fun AddGroupPostScreen( activeUserPublicKey: HexKey, chatRoomId: String, relayHint: String?, + confederationId: HexKey? = null, initialAddGroupPostUIState: AddGroupPostUIState = AddGroupPostUIState.Loading, chatRepository: ChatRepository, frostSigningRepository: FrostSigningRepository, @@ -100,6 +101,7 @@ fun AddGroupPostScreen( factory = AddGroupPostViewModel.factory( chatRoomId = chatRoomId, relayHint = relayHint, + confederationId = confederationId, initialAddGroupPostUIState = initialAddGroupPostUIState, activeUserPublicKey = activeUserPublicKey, chatRepository = chatRepository, @@ -209,6 +211,7 @@ fun AddGroupPostScreen( Text( text = addGroupPostUIState.groupNostrProfile?.name() + ?: addGroupPostUIState.postingAs ?: addGroupPostUIState.localChatRoom.chatRoom.subject ?: chatRoomId.take(16), style = MaterialTheme.typography.titleSmall, 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 1000a949..f122666f 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 @@ -50,15 +50,10 @@ import mobi.giza.compose.ExperimentalFeatures import androidx.compose.material.icons.filled.Hub import mobi.giza.compose.resources.confederations import mobi.giza.compose.resources.member_of_confederation -import mobi.giza.compose.resources.group_and_its_role_holders -import mobi.giza.compose.resources.admins_who_joined_later_are_not_here import mobi.giza.compose.resources.open_the_confederation import mobi.giza.compose.resources.no_confederations_yet import mobi.giza.compose.resources.one_confederation_proposal import mobi.giza.compose.resources.n_confederation_proposals -import mobi.giza.compose.resources.this_is_the_confederations_room -import mobi.giza.compose.resources.propose_the_charter -import mobi.giza.compose.resources.the_charter_names_the_groups import mobi.giza.compose.ui.composable.navigation.routes.ConfederationSigningRoute import androidx.compose.material.icons.filled.Campaign import mobi.giza.compose.resources.not_described_yet @@ -824,68 +819,6 @@ fun ChatRoomDetailScreen( // The confederations naming this group, and the way into // proposing one (docs/confederation.md). Every member can // read them; the screen behind it gates proposing. - // The confederation's own room: what it is, and why it cannot - // change its members yet. docs/confederation.md, Phase 13. - chatRoomDetailUIState.confederationName?.let { name -> - item { - Card(modifier = Modifier.fillMaxWidth()) { - Column( - modifier = Modifier.padding(MaterialTheme.spacing.containerPadding), - verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.itemGap), - ) { - Text( - text = stringResource(Res.string.this_is_the_confederations_room, name), - style = MaterialTheme.typography.bodyMedium, - ) - // Its groups, and who holds each one's roles: the room's - // members are people, and this says whose. docs/confederation-profile.md, D9. - chatRoomDetailUIState.confederationRoom?.let { room -> - room.groups.forEach { (group, holders) -> - Text( - text = stringResource(Res.string.group_and_its_role_holders, group, holders.joinToString(", ")), - style = MaterialTheme.typography.bodySmall, - ) - } - Text( - text = stringResource(Res.string.admins_who_joined_later_are_not_here, room.name), - style = MaterialTheme.typography.bodySmall, - color = MaterialTheme.colorScheme.onSurfaceVariant, - ) - room.homeGroupId?.let { home -> - TextButton(onClick = { - onNavigateToRoute.invoke( - ConfederationRoute(activeUserPublicKey = activeUserPublicKey, chatRoomId = home, confederationId = room.confederationId) - ) - }) { - Text(stringResource(Res.string.open_the_confederation)) - } - } - } - // Its charter, which it signs itself (Phase 15). - if (chatRoomDetailUIState.canSignAsConfederation && identityCanSign) { - Text( - text = stringResource(Res.string.the_charter_names_the_groups), - style = MaterialTheme.typography.bodySmall, - color = MaterialTheme.colorScheme.onSurfaceVariant, - ) - TextButton(onClick = { - chatRoomDetailViewModel.proposeCharter( - onSuccess = { attemptId -> - onNavigateToRoute.invoke( - ConfederationSigningRoute(activeUserPublicKey = activeUserPublicKey, attemptId = attemptId) - ) - }, - onFailure = {}, - ) - }) { - Text(stringResource(Res.string.propose_the_charter)) - } - } - } - } - } - } - // Each formed confederation this group is in, which opens it: its // profile, its groups, and the changes to its profile. // docs/confederation-profile.md, D1. @@ -1499,9 +1432,6 @@ fun ChatRoomDetailScreen( adminLabel.takeIf { localParticipant.participant.adminAt != null }, (if (beingRotatedAway) shareBeingRotatedAwayLabel else shareLabel) .takeIf { memberPublicKey in chatRoomDetailUIState.shareHolders }, - // In a confederation's room: the groups this person holds roles for. - chatRoomDetailUIState.confederationRoom?.groupsOfMember?.get(memberPublicKey) - ?.takeIf { it.isNotEmpty() }?.joinToString(", "), ) Column { if (roles.isNotEmpty()) { diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ConfederationScreen.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ConfederationScreen.kt index 3ba909ac..e45394a1 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ConfederationScreen.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ConfederationScreen.kt @@ -59,7 +59,6 @@ import mobi.giza.compose.resources.n_of_m_endorsements import mobi.giza.compose.resources.no_name_on_this_profile import mobi.giza.compose.resources.no_profile_changes_yet import mobi.giza.compose.resources.only_admins_see_profile_changes -import mobi.giza.compose.resources.open_the_confederations_room import mobi.giza.compose.resources.open_the_signing_session import mobi.giza.compose.resources.profile_changes import mobi.giza.compose.resources.profile_problem_cannot_sign @@ -70,7 +69,6 @@ import mobi.giza.compose.resources.profile_problem_not_admin import mobi.giza.compose.resources.profile_problem_not_member import mobi.giza.compose.resources.this_device_knows_nothing_of_that_confederation import mobi.giza.compose.resources.waiting_for_the_group_to_sign_its_answer -import mobi.giza.compose.ui.composable.navigation.routes.ChatRoomMessagingRoute import mobi.giza.compose.ui.composable.navigation.routes.ConfederationProfileChangeRoute import mobi.giza.compose.ui.composable.navigation.routes.ConfederationProposalRoute import mobi.giza.compose.ui.composable.navigation.routes.EditConfederationProfileRoute @@ -89,6 +87,28 @@ import mobi.giza.compose.ui.theme.readableContent import mobi.giza.compose.ui.theme.spacing import mobi.giza.compose.ui.view.model.ConfederationViewModel import mobi.giza.compose.ui.view.state.ConfederationUIState +import mobi.giza.compose.database.model.ConfederationSigningStage +import mobi.giza.compose.text.ProposedEvent +import mobi.giza.compose.nostr.GroupPost +import androidx.compose.runtime.rememberCoroutineScope +import mobi.giza.compose.ui.composable.widgets.rememberNotifier +import mobi.giza.compose.ui.composable.navigation.routes.ConfederationSigningRoute +import mobi.giza.compose.ui.composable.navigation.routes.AddGroupPostRoute +import mobi.giza.compose.resources.could_not_propose_the_charter +import mobi.giza.compose.resources.signing_failed +import mobi.giza.compose.resources.signing_complete +import mobi.giza.compose.resources.signing_in_progress +import mobi.giza.compose.resources.waiting_for_your_answer +import mobi.giza.compose.resources.nothing_is_being_signed +import mobi.giza.compose.resources.confederation_signing_attempts +import mobi.giza.compose.resources.propose_the_charter +import mobi.giza.compose.resources.the_charter_names_the_groups +import mobi.giza.compose.resources.confederation_charter_none +import mobi.giza.compose.resources.confederation_charter_signed +import mobi.giza.compose.resources.confederation_charter +import mobi.giza.compose.resources.confederation_has_posted_nothing +import mobi.giza.compose.resources.add_post +import mobi.giza.compose.resources.posts import org.jetbrains.compose.resources.stringResource /** @@ -126,6 +146,9 @@ fun ConfederationScreen( } val state by viewModel.uiState.collectAsState() val identityCanSign = LocalCanSign.current + // Read out here: both are composable and an onClick lambda is not. + val notify = rememberNotifier(rememberCoroutineScope()) + val couldNotProposeCharter = stringResource(Res.string.could_not_propose_the_charter) Scaffold( snackbarHost = { SnackbarHost(LocalSnackbarHostState.current) }, @@ -225,12 +248,69 @@ fun ConfederationScreen( } } + // Its posts, and the way to propose one for a member who holds a seat + // (docs/confederation-room-removal.md, D9). HorizontalDivider() - if (current.holdsRoom) { - TextButton(onClick = { onNavigateToRoute(ChatRoomMessagingRoute(activeUserPublicKey = activeUserPublicKey, chatRoomId = confederationId, relayHint = null)) }) { - Text(stringResource(Res.string.open_the_confederations_room)) + Text(text = stringResource(Res.string.posts), style = MaterialTheme.typography.titleSmall) + if (current.holdsSeat) { + Button( + modifier = Modifier.fillMaxWidth(), + enabled = identityCanSign, + onClick = { onNavigateToRoute(AddGroupPostRoute(activeUserPublicKey, chatRoomId, relayHint = null, confederationId = confederationId)) }, + ) { + Icon(Icons.Default.Edit, contentDescription = Decorative) + Text(text = stringResource(Res.string.add_post), modifier = Modifier.padding(start = MaterialTheme.spacing.relatedGap)) } } + if (current.posts.isEmpty()) { + EmptyState(message = stringResource(Res.string.confederation_has_posted_nothing)) + } else { + current.posts.forEach { post -> ConfederationPostCard(post) } + } + + // Its charter: the public statement of the groups it is made of. + HorizontalDivider() + Text(text = stringResource(Res.string.confederation_charter), style = MaterialTheme.typography.titleSmall) + when { + current.charterSigned -> Text(stringResource(Res.string.confederation_charter_signed)) + current.holdsSeat -> { + Text( + text = stringResource(Res.string.the_charter_names_the_groups), + style = MaterialTheme.typography.bodySmall, + color = MaterialTheme.colorScheme.onSurfaceVariant, + ) + TextButton( + enabled = identityCanSign, + onClick = { + viewModel.proposeCharter( + onSuccess = { attemptId -> onNavigateToRoute(ConfederationSigningRoute(activeUserPublicKey = activeUserPublicKey, attemptId = attemptId)) }, + onFailure = { notify(couldNotProposeCharter) }, + ) + }, + ) { + Text(stringResource(Res.string.propose_the_charter)) + } + } + else -> Text(stringResource(Res.string.confederation_charter_none)) + } + + // What it is signing, and what it asked this person: a seat's work. + if (current.holdsSeat) { + HorizontalDivider() + Text(text = stringResource(Res.string.confederation_signing_attempts), style = MaterialTheme.typography.titleSmall) + if (current.attempts.isEmpty()) { + EmptyState(message = stringResource(Res.string.nothing_is_being_signed)) + } else { + current.attempts.forEach { attempt -> + SigningAttemptCard( + attempt = attempt, + onClick = { onNavigateToRoute(ConfederationSigningRoute(activeUserPublicKey = activeUserPublicKey, attemptId = attempt.id)) }, + ) + } + } + } + + HorizontalDivider() current.formingProposalId?.let { proposalId -> TextButton(onClick = { onNavigateToRoute(ConfederationProposalRoute(activeUserPublicKey, chatRoomId, proposalId)) }) { Text(stringResource(Res.string.how_it_was_formed)) @@ -242,6 +322,46 @@ fun ConfederationScreen( } } +@Composable +private fun ConfederationPostCard(post: GroupPost) { + Card(modifier = Modifier.fillMaxWidth()) { + ListItem( + headlineContent = { Text(text = post.content, maxLines = 6, overflow = TextOverflow.Ellipsis) }, + supportingContent = { + Text( + text = post.postedAt.toFormattedTimeAndDateString(), + style = MaterialTheme.typography.labelSmall, + color = MaterialTheme.colorScheme.onSurfaceVariant, + ) + }, + ) + } +} + +@Composable +private fun SigningAttemptCard(attempt: ConfederationUIState.Attempt, onClick: () -> Unit) { + val summary = attempt.event?.let { ProposedEvent.summarize(it) } + Card(modifier = Modifier.fillMaxWidth(), onClick = onClick) { + ListItem( + overlineContent = { + Text( + stringResource( + when { + attempt.stage == ConfederationSigningStage.COMPLETE -> Res.string.signing_complete + attempt.stage == ConfederationSigningStage.FAILED -> Res.string.signing_failed + attempt.awaitingYou -> Res.string.waiting_for_your_answer + else -> Res.string.signing_in_progress + } + ) + ) + }, + headlineContent = { Text(text = summary?.label.orEmpty(), maxLines = 1, overflow = TextOverflow.Ellipsis) }, + supportingContent = summary?.detail?.let { detail -> { Text(text = detail, maxLines = 2, overflow = TextOverflow.Ellipsis) } }, + trailingContent = { Icon(Icons.Default.ChevronRight, contentDescription = Decorative) }, + ) + } +} + @Composable private fun ConfederationProfileCard(state: ConfederationUIState.Loaded) { val profile = state.profile diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/EditGroupNostrProfileScreen.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/EditGroupNostrProfileScreen.kt index 182ccf28..d8cc43a4 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/EditGroupNostrProfileScreen.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/EditGroupNostrProfileScreen.kt @@ -33,7 +33,6 @@ import mobi.giza.compose.database.model.ChatRoom import mobi.giza.compose.database.model.intermdiate.LocalChatRoom import mobi.giza.compose.repository.ChatRepository import mobi.giza.compose.repository.FrostSigningRepository -import mobi.giza.compose.ui.composable.navigation.routes.ConfederationSigningRoute import mobi.giza.compose.ui.composable.navigation.routes.FrostSigningRoute import mobi.giza.compose.ui.composable.navigation.routes.Route import mobi.giza.compose.ui.composable.widgets.ErrorState @@ -172,18 +171,11 @@ fun EditGroupNostrProfileScreen( // group still showing the old one // would read as a failure. onNavigateToRouteAndPopUpInclusive.invoke( - if (editGroupNostrProfileViewModel.isConfederation) { - ConfederationSigningRoute( - activeUserPublicKey = activeUserPublicKey, - attemptId = sessionId - ) - } else { - FrostSigningRoute( - activeUserPublicKey = activeUserPublicKey, - chatRoomId = chatRoomId, - sessionId = sessionId - ) - } + FrostSigningRoute( + activeUserPublicKey = activeUserPublicKey, + chatRoomId = chatRoomId, + sessionId = sessionId + ) ) }, // Stay on the form with what was typed diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/navigation/GizaNavHost.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/navigation/GizaNavHost.kt index 92450844..109b8fd1 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/navigation/GizaNavHost.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/navigation/GizaNavHost.kt @@ -1514,6 +1514,7 @@ fun GizaNavHost( activeUserPublicKey = route.activeUserPublicKey, chatRoomId = route.chatRoomId, relayHint = route.relayHint, + confederationId = route.confederationId, chatRepository = databaseChatRepository, frostSigningRepository = databaseFrostSigningRepository, onNavigateToRouteAndPopUpInclusive = { signingRoute -> diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/navigation/routes/AddGroupPostRoute.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/navigation/routes/AddGroupPostRoute.kt index 7f246398..14f270c2 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/navigation/routes/AddGroupPostRoute.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/navigation/routes/AddGroupPostRoute.kt @@ -2,10 +2,15 @@ package mobi.giza.compose.ui.composable.navigation.routes import kotlinx.serialization.Serializable -/** The composer that proposes a post for the group's quorum to sign as itself. */ +/** + * The composer that proposes a post for the group's quorum to sign as itself; or, with + * [confederationId], for a confederation the group of [chatRoomId] is in to sign, opened from its + * screen (docs/confederation-room-removal.md, D9). + */ @Serializable data class AddGroupPostRoute( val activeUserPublicKey: String, val chatRoomId: String, // TODO: have this as a publicKey - val relayHint: String? + val relayHint: String?, + val confederationId: String? = null, ): Route() diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/widgets/chat/ChatTranscript.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/widgets/chat/ChatTranscript.kt index ff3528d9..46d21e4c 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/widgets/chat/ChatTranscript.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/widgets/chat/ChatTranscript.kt @@ -386,7 +386,9 @@ fun ChatTranscript( // exists. It leads nowhere. // A request for the confederation to sign: it opens, since a // member answers it there. docs/confederation.md, Phase 15. - if (localChatMessage.chatMessage.messageType == ChatMessage.TYPE_CONFEDERATION_SIGNING_PROPOSED) { + if (localChatMessage.chatMessage.messageType == ChatMessage.TYPE_CONFEDERATION_SIGNING_PROPOSED || + localChatMessage.chatMessage.messageType == ChatMessage.TYPE_CONFEDERATION_SIGNING_ASKED + ) { RitualNotice( localChatMessage = localChatMessage, isAnswered = false, @@ -951,6 +953,7 @@ private fun RitualNotice( ChatMessage.TYPE_CONFEDERATION_CEREMONY_FAILED -> Icons.Default.ErrorOutline ChatMessage.TYPE_CONFEDERATION_FORMED -> Icons.Default.Hub ChatMessage.TYPE_CONFEDERATION_SIGNING_PROPOSED -> Icons.Default.Draw + ChatMessage.TYPE_CONFEDERATION_SIGNING_ASKED -> Icons.Default.Draw ChatMessage.TYPE_CONFEDERATION_SIGNING_FAILED -> Icons.Default.ErrorOutline ChatMessage.TYPE_CONFEDERATION_PROFILE_PROPOSED -> Icons.Default.Edit ChatMessage.TYPE_CONFEDERATION_PROFILE_ENDORSED -> Icons.Default.CheckCircle diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/AddGroupPostViewModel.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/AddGroupPostViewModel.kt index 7ae9b3fd..966797ae 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/AddGroupPostViewModel.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/AddGroupPostViewModel.kt @@ -39,6 +39,8 @@ class AddGroupPostViewModel( val chatRoomId: String, val activeUserPublicKey: HexKey, val relayHint: String?, + /** A confederation the group is in, to sign the post instead of the group (docs/confederation-room-removal.md, D9). */ + val confederationId: HexKey? = null, initialAddGroupPostUIState: AddGroupPostUIState, val chatRepository: ChatRepository, val frostSigningRepository: FrostSigningRepository, @@ -51,9 +53,8 @@ class AddGroupPostViewModel( val isActionPending: MutableState = mutableStateOf(false) - /** Whether this room is a confederation's, whose statements the confederation signs. Read at load. */ - var isConfederation: Boolean = false - private set + /** Whether the confederation, not the group, signs this post. */ + val isConfederation: Boolean get() = confederationId != null fun initiateAddGroupPost() { viewModelScope.launch(Dispatchers.IO) { @@ -62,14 +63,15 @@ class AddGroupPostViewModel( addGroupPostUIState = if (localChatRoom == null) { AddGroupPostUIState.Error("Couldn't find the chat room") } else { + val byline = confederationId?.let { chatRepository.confederationByline(it) } AddGroupPostUIState.Loaded( localChatRoom = localChatRoom, - groupNostrProfile = chatRepository.groupNostrProfile(chatRoomId), - // The same condition the group detail screen gates the entry - // point on. + groupNostrProfile = if (confederationId != null) byline?.first else chatRepository.groupNostrProfile(chatRoomId), + // The same condition the group detail screen, or the confederation's, gates + // the entry point on. canSign = GroupStatementCapability.roomIsOpen(localChatRoom) && - (frostSigningRepository.canSign(chatRoomId) || - chatRepository.canSignAsConfederation(chatRoomId).also { isConfederation = it }), + if (confederationId != null) chatRepository.canSignAsConfederation(confederationId) else frostSigningRepository.canSign(chatRoomId), + postingAs = byline?.second, ) } } @@ -112,10 +114,10 @@ class AddGroupPostViewModel( viewModelScope.launch(Dispatchers.IO) { val session = runCatching { - // A confederation's room signs through the confederation, not a FROST + // A confederation signs through its own signing, not the group's FROST // key: docs/confederation.md, Phase 15. - if (isConfederation) { - chatRepository.proposeAsConfederation(localChatRoom, template.kind, template.tags, template.content) + if (confederationId != null) { + chatRepository.proposeAsConfederation(confederationId, template.kind, template.tags, template.content) } else { frostSigningRepository.proposeSigning( localChatRoom = localChatRoom, @@ -148,6 +150,7 @@ class AddGroupPostViewModel( activeUserPublicKey: HexKey, chatRoomId: String, relayHint: String?, + confederationId: HexKey? = null, initialAddGroupPostUIState: AddGroupPostUIState = AddGroupPostUIState.Loading, chatRepository: ChatRepository, frostSigningRepository: FrostSigningRepository @@ -157,6 +160,7 @@ class AddGroupPostViewModel( activeUserPublicKey = activeUserPublicKey, chatRoomId = chatRoomId, relayHint = relayHint, + confederationId = confederationId, initialAddGroupPostUIState = initialAddGroupPostUIState, chatRepository = chatRepository, frostSigningRepository = frostSigningRepository 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 7044af76..b992e185 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 @@ -134,13 +134,10 @@ class ChatRoomDetailViewModel( groupPosts = chatRepository.groupPosts(chatRoomId), confederationProposalCount = chatRepository.confederationProposalCount(chatRoomId), inbox = chatRepository.inboxSummary(localChatRoom), - confederationName = chatRepository.confederationOfRoom(chatRoomId), - confederationRoom = if (ExperimentalFeatures.confederation) chatRepository.confederationRoomInfo(chatRoomId) else null, memberConfederations = if (ExperimentalFeatures.confederation) chatRepository.memberConfederations(chatRoomId) else emptyList(), groupDmRow = runCatching { chatRepository.groupDmRow(chatRoomId, localChatRoom.chatRoom.userPublicKey) } .onFailure { if (it is CancellationException) throw it else logger.w(throwable = it) { "Couldn't read $chatRoomId's messages row" } } .getOrNull(), - canSignAsConfederation = chatRepository.canSignAsConfederation(chatRoomId), canProposeAsGroup = canSign && roomIsOpen, subgroupsNeedAWallet = canSign && subgroupsNeedAWallet, canGovern = canGovern, @@ -517,17 +514,6 @@ class ChatRoomDetailViewModel( } - /** Proposes the confederation's charter, in its own room. docs/confederation.md, Phase 15. */ - fun proposeCharter(onSuccess: (attemptId: String) -> Unit, onFailure: () -> Unit) { - val loaded = chatRoomDetailUIState as? ChatRoomDetailUIState.Loaded ?: return - viewModelScope.launch(Dispatchers.IO) { - val attemptId = runCatching { chatRepository.proposeCharter(loaded.localChatRoom) } - .onFailure { logger.e("Could not propose the charter for $chatRoomId", it) } - .getOrNull() - viewModelScope.launch(Dispatchers.Main) { if (attemptId != null) onSuccess(attemptId) else onFailure() } - } - } - companion object { private const val TAG = "ChatRoomDetailViewModel" diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/ConfederationViewModel.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/ConfederationViewModel.kt index 96ff91c4..d8f6f391 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/ConfederationViewModel.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/ConfederationViewModel.kt @@ -1,5 +1,8 @@ package mobi.giza.compose.ui.view.model +import com.vitorpamplona.quartz.nip01Core.core.Event +import mobi.giza.compose.managers.ConfederationSigningManager +import mobi.giza.compose.database.model.ConfederationSigningAttempt import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.viewModelScope @@ -51,13 +54,19 @@ class ConfederationViewModel( val readsChanges = confederationRepository.isAdmin(chatRoomId, activeUserPublicKey) val problem = confederationRepository.profileChangeProblem(chatRoomId, activeUserPublicKey, confederationId) val formingProposalId = confederationRepository.formingProposalOf(confederationId) - val holdsRoom = confederationRepository.holdsRoomOf(confederationId) + val holdsSeat = confederationRepository.holdsSeat(confederationId, activeUserPublicKey) combine( - confederationRepository.observeProfile(confederationId), - confederationRepository.observeProfileChanges(confederationId), - confederationRepository.observePendingProfileChange(chatRoomId, confederationId), - ) { profile, changes, pending -> Triple(profile, changes, pending) }.collect { (profile, changes, pending) -> + combine( + confederationRepository.observeProfile(confederationId), + confederationRepository.observeProfileChanges(confederationId), + confederationRepository.observePendingProfileChange(chatRoomId, confederationId), + ) { profile, changes, pending -> Triple(profile, changes, pending) }, + confederationRepository.observePosts(confederationId), + confederationRepository.observeCharterSigned(confederationId), + confederationRepository.observeSigningAttempts(confederationId, activeUserPublicKey), + ) { profileAndChanges, posts, charterSigned, attempts -> Quad(profileAndChanges, posts, charterSigned, attempts) }.collect { (profileAndChanges, posts, charterSigned, attempts) -> + val (profile, changes, pending) = profileAndChanges state.value = ConfederationUIState.Loaded( localChatRoom = localChatRoom, confederationId = confederationId, @@ -70,14 +79,45 @@ class ConfederationViewModel( problem = problem, pendingSessionId = pending?.id, formingProposalId = formingProposalId, - holdsRoom = holdsRoom, + posts = posts, + holdsSeat = holdsSeat, + charterSigned = charterSigned, + attempts = attemptsToShow(attempts), names = names, ) } } } + /** Proposes that the confederation sign its charter; the attempt's id to [onSuccess]. */ + fun proposeCharter(onSuccess: (attemptId: String) -> Unit, onFailure: () -> Unit) { + viewModelScope.launch(Dispatchers.IO) { + val attemptId = runCatching { confederationRepository.proposeCharter(confederationId) }.getOrNull() + launch(Dispatchers.Main) { if (attemptId != null) onSuccess(attemptId) else onFailure() } + } + } + + private data class Quad(val first: A, val second: B, val third: C, val fourth: D) + companion object { + /** How many ended attempts the screen keeps under the running ones. */ + const val ENDED_SHOWN = 5 + + /** Running first, the ones waiting on this person before the rest; then the newest few that ended. */ + internal fun attemptsToShow(attempts: List): List { + val items = attempts.map { attempt -> + ConfederationUIState.Attempt( + id = attempt.id, + event = Event.fromJsonOrNull(attempt.eventJson), + stage = attempt.stage, + awaitingYou = ConfederationSigningManager.isAwaitingApproval(attempt), + ) to attempt + } + val running = items.filter { it.second.isRunning }.sortedWith(compareBy({ !it.first.awaitingYou }, { -it.second.createdAt.epochSeconds })) + val ended = items.filter { !it.second.isRunning }.sortedByDescending { it.second.updatedAt }.take(ENDED_SHOWN) + return (running + ended).map { it.first } + } + fun factory( activeUserPublicKey: HexKey, chatRoomId: String, diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/EditGroupNostrProfileViewModel.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/EditGroupNostrProfileViewModel.kt index a6ebda91..243a1eff 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/EditGroupNostrProfileViewModel.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/EditGroupNostrProfileViewModel.kt @@ -48,12 +48,6 @@ class EditGroupNostrProfileViewModel( val isActionPending: MutableState = mutableStateOf(false) - /** - * Never, now: a confederation's profile is not edited from its room but proposed by one of its - * groups (docs/confederation-profile.md, D5). Kept so the screen's routing reads the same. - */ - val isConfederation: Boolean = false - fun initiateEditGroupNostrProfile() { viewModelScope.launch(Dispatchers.IO) { val localChatRoom = chatRepository.getChatRoomByIdentifier(chatRoomId) @@ -66,11 +60,8 @@ class EditGroupNostrProfileViewModel( groupNostrProfile = chatRepository.groupNostrProfile(chatRoomId), // The same condition the group detail screen gates the entry // point on. - // Not a confederation's room: its profile changes through its groups, from - // its own screen (docs/confederation-profile.md, D5). canSign = GroupStatementCapability.roomIsOpen(localChatRoom) && - frostSigningRepository.canSign(chatRoomId) && - !chatRepository.canSignAsConfederation(chatRoomId), + frostSigningRepository.canSign(chatRoomId), ) } } diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/GroupNostrProfileViewModel.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/GroupNostrProfileViewModel.kt index 01d16f85..b7a0ed79 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/GroupNostrProfileViewModel.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/GroupNostrProfileViewModel.kt @@ -44,7 +44,7 @@ class GroupNostrProfileViewModel( localChatRoom = localChatRoom, groupNostrProfile = chatRepository.groupNostrProfile(chatRoomId), canSign = GroupStatementCapability.roomIsOpen(localChatRoom) && - chatRepository.canSign(chatRoomId) && !chatRepository.canSignAsConfederation(chatRoomId), + chatRepository.canSign(chatRoomId), ) } } diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/GroupPostsViewModel.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/GroupPostsViewModel.kt index 164582a7..1714bc0e 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/GroupPostsViewModel.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/GroupPostsViewModel.kt @@ -39,8 +39,7 @@ class GroupPostsViewModel( localChatRoom = localChatRoom, groupPosts = chatRepository.groupPosts(chatRoomId), groupNostrProfile = chatRepository.groupNostrProfile(chatRoomId), - canSign = GroupStatementCapability.roomIsOpen(localChatRoom) && - (chatRepository.canSign(chatRoomId) || chatRepository.canSignAsConfederation(chatRoomId)), + canSign = GroupStatementCapability.roomIsOpen(localChatRoom) && chatRepository.canSign(chatRoomId), ) } } diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/AddGroupPostUIState.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/AddGroupPostUIState.kt index 3fa81c34..fdb4dc3e 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/AddGroupPostUIState.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/AddGroupPostUIState.kt @@ -23,6 +23,8 @@ sealed interface AddGroupPostUIState { * share-holder can open the session that would sign it. */ val canSign: Boolean = false, + /** Whose name the byline falls back to: a confederation's, when it is the one to sign. Null for the room's. */ + val postingAs: String? = null, ): AddGroupPostUIState data class Error( 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 73908a7a..c250e758 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 @@ -77,18 +77,12 @@ sealed interface ChatRoomDetailUIState { val confederationProposalCount: Int = 0, /** The group's inbox, for its row; null where this device has nothing of it to show. */ val inbox: InboxRowSummary? = null, - /** This room's confederation, by its groups and who holds their roles. docs/confederation-profile.md, D9. */ - val confederationRoom: ConfederationRoomInfo? = null, /** The formed confederations this group is a member of, as (id, name): each opens its own screen. */ val memberConfederations: List> = emptyList(), - /** The confederation whose room this is, by name: its membership is fixed until it can sign. */ - val confederationName: String? = null, /** What the group's direct messages show here, or nothing. docs/group-threshold-ecdh.md. */ val groupDmRow: GroupDmRow? = null, - /** Whether this device holds a role in that confederation, and so can propose what it signs. */ - val canSignAsConfederation: Boolean = false, /** * Whether this device could put a profile or a post to the group's quorum: * a Marmot room it has not left, not disbanded, where it holds a share of @@ -194,16 +188,3 @@ sealed interface ChatRoomDetailUIState { ): ChatRoomDetailUIState data object Loading: ChatRoomDetailUIState } - -/** - * A confederation's own room, said in its groups (docs/confederation-profile.md, D9): each group with - * the people who hold its roles, each person's groups, and the member group this device opens the - * confederation's screen from. - */ -data class ConfederationRoomInfo( - val confederationId: String, - val name: String, - val groups: List>>, - val groupsOfMember: Map>, - val homeGroupId: String?, -) diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/ConfederationUIState.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/ConfederationUIState.kt index 98977442..bf27b6c6 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/ConfederationUIState.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/ConfederationUIState.kt @@ -1,5 +1,8 @@ package mobi.giza.compose.ui.view.state +import com.vitorpamplona.quartz.nip01Core.core.Event +import mobi.giza.compose.database.model.ConfederationSigningStage +import mobi.giza.compose.nostr.GroupPost import com.vitorpamplona.quartz.nip01Core.core.HexKey import mobi.giza.compose.database.model.intermdiate.LocalChatRoom import mobi.giza.compose.nostr.GroupNostrProfile @@ -27,14 +30,23 @@ sealed interface ConfederationUIState { val pendingSessionId: String? = null, /** The proposal the confederation was formed from, where this device holds it. */ val formingProposalId: HexKey? = null, - /** Whether this device holds the confederation's own room. */ - val holdsRoom: Boolean = false, + /** The posts it has signed that this device holds, newest first. */ + val posts: List = emptyList(), + /** Whether this person holds a seat, and so can propose what it signs (docs/confederation-room-removal.md, D9). */ + val holdsSeat: Boolean = false, + /** Whether this device holds the charter it has signed. */ + val charterSigned: Boolean = false, + /** This person's attempts at it signing something, running first, then the last few ended. */ + val attempts: List = emptyList(), /** How to name each group. */ val names: Map = emptyMap(), ) : ConfederationUIState { val canEdit: Boolean get() = problem == null && pendingSessionId == null } + /** One attempt at the confederation signing something: what, how far it is, and whether it waits on this person. */ + data class Attempt(val id: String, val event: Event?, val stage: ConfederationSigningStage, val awaitingYou: Boolean) + /** A member group, with the admins who hold its roles where this device knows them. */ data class Group(val publicKey: HexKey, val name: String, val roleHolders: List) diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/ConfederationCeremonyJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/ConfederationCeremonyJvmTest.kt index 6a66d774..4e194781 100644 --- a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/ConfederationCeremonyJvmTest.kt +++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/ConfederationCeremonyJvmTest.kt @@ -380,7 +380,6 @@ class ConfederationCeremonyJvmTest { assertEquals(devices.keys, group.currentAdminIdentities()) assertEquals(Quorum.minimumAdmins(2), GovernanceGate.minimumAdmins(group), "born governed: fixed until the confederation can sign") assertEquals(emptyList(), created.notAdded) - assertEquals("Atlas", runBlocking { repository(host).confederationOfRoom(confederation.id) }) assertEquals(host.person, runBlocking { host.db.confederationCeremonyDao().getConfederation(confederation.id)!!.roomCreator }, "it holds its own group") } diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/ConfederationSigningJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/ConfederationSigningJvmTest.kt index 53325b7e..bf7261ea 100644 --- a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/ConfederationSigningJvmTest.kt +++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/ConfederationSigningJvmTest.kt @@ -550,19 +550,52 @@ class ConfederationSigningJvmTest { // ---- docs/confederation-profile.md, Phase 7: rooms that say what they are ------------------ - @Test - fun `the confederation's room says which group each of its people holds roles for`() = runBlocking { - val polisMember = devices.getValue(npub(secret(22))) - polisMember.db.chatRoomDao().upsert(ChatRoom(id = groups[1], userPublicKey = polisMember.person, subject = "#Polis", description = null, mlsGroupState = "00")) - val repository = mobi.giza.compose.database.repository.DatabaseChatRepository(polisMember.db, kotlinx.coroutines.CoroutineScope(kotlinx.coroutines.Dispatchers.Unconfined)) + // ---- docs/confederation-room-removal.md, Phase 6: the confederation's screen takes over ---------- - val info = assertNotNull(repository.confederationRoomInfo(confederation.id)) - assertEquals("Atlas", info.name) - assertEquals(listOf("Agora", "Polis", "Ekklesia").sorted(), info.groups.map { it.first }.sorted()) - info.groups.forEach { (_, holders) -> assertEquals(3, holders.size) } - assertEquals(listOf("Polis"), info.groupsOfMember[npub(secret(22))]) - assertEquals(groups[1], info.homeGroupId, "the confederation's screen opens from the member group this device is in") - assertEquals(null, repository.confederationRoomInfo(groups[1]), "a member group's own room is not the confederation's") + @Test + fun `a post is asked of each role holder in their own group's room, and the ask is theirs`() = runBlocking { + val attempt = propose() + pump() + val polis = devices.getValue(npub(secret(21))) + val asked = polis.db.chatMessageDao().getChatMessagesByChatRoomId(groups[1]).map { it.chatMessage } + .single { it.messageType == mobi.giza.compose.database.model.ChatMessage.TYPE_CONFEDERATION_SIGNING_ASKED } + assertEquals(attempt.id, asked.frostSigningSessionId, "the line opens the attempt") + assertTrue(asked.isUserMessage, "an ask is to this device's owner") + assertEquals(polis.person, asked.senderPublicKey) + assertTrue(mobi.giza.compose.database.model.ChatMessage.TYPE_CONFEDERATION_SIGNING_ASKED in mobi.giza.compose.notifications.NotificationClassifier.NEEDS_YOU) + val proposerLines = proposer.db.chatMessageDao().getChatMessagesByChatRoomId(groups[0]).map { it.chatMessage.messageType } + assertTrue(mobi.giza.compose.database.model.ChatMessage.TYPE_CONFEDERATION_SIGNING_PROPOSED in proposerLines, "the proposer is told, not asked: $proposerLines") + assertTrue(mobi.giza.compose.database.model.ChatMessage.TYPE_CONFEDERATION_SIGNING_ASKED !in proposerLines) + } + + @Test + fun `a signed post is owed to relays by every device that signed it`() = runBlocking { + val attempt = propose() + pump() + approve(attempt.id, people - 11) + pump() + val signed = Event.fromJson(attempts(attempt.id).getValue(proposer.person)!!.signedEventJson!!) + devices.values.forEach { d -> + assertTrue(d.db.confederationDao().observeUnpublished().first().any { it.id == signed.id }, "${d.person.take(6)} owes it") + } + } + + @Test + fun `the confederation's screen lists what is waiting on you first, then what is running, then the last few ended`() { + fun attempt(id: Char, stage: ConfederationSigningStage, approved: Boolean, at: Long) = mobi.giza.compose.database.model.ConfederationSigningAttempt( + id = id.toString().repeat(64), confederationId = confederation.id, proposerPublicKey = proposer.person, userPublicKey = proposer.person, + eventJson = "{}", stage = stage, approvedAt = if (approved) Instant.fromEpochSeconds(at) else null, + createdAt = Instant.fromEpochSeconds(at), updatedAt = Instant.fromEpochSeconds(at), + ) + val shown = mobi.giza.compose.ui.view.model.ConfederationViewModel.attemptsToShow( + listOf(attempt('a', ConfederationSigningStage.NONCES, approved = true, at = 30)) + + attempt('b', ConfederationSigningStage.SELECTING, approved = false, at = 10) + + (0 until 7).map { attempt('c' + it, ConfederationSigningStage.COMPLETE, approved = true, at = 100L + it) } + ) + assertEquals(listOf('b', 'a'), shown.take(2).map { it.id.first() }, "waiting on you, then running") + assertTrue(shown[0].awaitingYou) + assertEquals(2 + mobi.giza.compose.ui.view.model.ConfederationViewModel.ENDED_SHOWN, shown.size) + assertEquals('c' + 6, shown[2].id.first(), "the newest ended first") } @Test diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/composable/ConfederationProfileScreensJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/composable/ConfederationProfileScreensJvmTest.kt index e21d5d90..9a667dd0 100644 --- a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/composable/ConfederationProfileScreensJvmTest.kt +++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/composable/ConfederationProfileScreensJvmTest.kt @@ -67,6 +67,10 @@ class ConfederationProfileScreensJvmTest { readsChanges: Boolean = true, problem: ProfileChangeProblem? = null, changes: List = emptyList(), + posts: List = emptyList(), + holdsSeat: Boolean = false, + charterSigned: Boolean = false, + attempts: List = emptyList(), ) = ConfederationUIState.Loaded( localChatRoom = localChatRoom, confederationId = atlas, @@ -81,6 +85,10 @@ class ConfederationProfileScreensJvmTest { readsChanges = readsChanges, problem = problem, names = mapOf(agora to "This group", polis to "Polis"), + posts = posts, + holdsSeat = holdsSeat, + charterSigned = charterSigned, + attempts = attempts, ) // ---- the confederation's screen ---------------------------------------------------------------- @@ -113,6 +121,48 @@ class ConfederationProfileScreensJvmTest { onNodeWithText("Edit profile").assertIsNotEnabled() } + // ---- docs/confederation-room-removal.md, Phase 6: posts, the charter, and signing ------------------ + + private val post = mobi.giza.compose.nostr.GroupPost( + mobi.giza.compose.database.model.GroupSignedEvent( + id = "p".repeat(64), chatRoomId = atlas, publicKey = atlas, kind = 1, tags = emptyArray(), + content = "The first words of a group of groups", signature = "0".repeat(128), + createdAt = kotlin.time.Instant.fromEpochSeconds(1_790_000_000), + ) + ) + + private val asked = ConfederationUIState.Attempt( + id = "s".repeat(64), + event = com.vitorpamplona.quartz.nip01Core.core.Event("e".repeat(64), atlas, 1, 1, emptyArray(), "Words for the record", ""), + stage = mobi.giza.compose.database.model.ConfederationSigningStage.SELECTING, + awaitingYou = true, + ) + + @Test + fun `someone who holds a seat sees the posts, can add one, can propose the charter, and sees what waits on them`() = + renderConfederation(loaded(posts = listOf(post), holdsSeat = true, attempts = listOf(asked))) { + onNodeWithText("The first words of a group of groups").assertIsDisplayed() + onNodeWithText("Add post").assertIsEnabled() + onNodeWithText("Propose the charter").assertIsDisplayed() + onNodeWithText("Waiting for your answer").assertIsDisplayed() + onAllNodesWithText("Open the confederation's room").assertCountEquals(0) + } + + @Test + fun `a member who holds no seat reads the posts and the charter, and is offered nothing to sign`() = + renderConfederation(loaded(readsChanges = false, charterSigned = true)) { + onNodeWithText("The confederation has posted nothing yet").assertIsDisplayed() + onNodeWithText("The confederation has signed its charter, naming its groups").assertIsDisplayed() + onAllNodesWithText("Add post").assertCountEquals(0) + onAllNodesWithText("Propose the charter").assertCountEquals(0) + onAllNodesWithText("Signing").assertCountEquals(0) + } + + @Test + fun `with no charter and no seat, it says there is none`() = renderConfederation(loaded()) { + onNodeWithText("The confederation has no charter yet").assertIsDisplayed() + } + // ---- a change ---------------------------------------------------------------------------------- private fun changeState(change: ConfederationProfileStatements.Change, pending: String? = null) = ConfederationProfileChangeUIState.Loaded( diff --git a/docs/confederation-room-removal.md b/docs/confederation-room-removal.md index b64395c1..ab2da834 100644 --- a/docs/confederation-room-removal.md +++ b/docs/confederation-room-removal.md @@ -30,6 +30,7 @@ Written against `9db986c1`, on 2026-11-23. **Being built**, one commit a phase. | 2 | done, with Phase 5 folded in. Every signing message is signed by its author's key and travels in a 30398 envelope (`ConfederationSigningEvents.CARRIED`), here already rather than from Phase 4, since an MLS inner event has no column for a signature. Each message also names its confederation. `process` reads only envelopes; `receive` verifies each event, drops one from a person with no seat or about another confederation, and files the rest. A voucher, being the group's signed event, goes in an envelope as itself and is checked against its group's npub, so 30396 is never sent and one that arrives is dropped. A `Sender` (the room and the key) replaces the room parameter through the manager. `decline` signs too, so it takes the key. `ConfederationSigningJvmTest` 17/17 (two new: a changed message, and one signed by an outsider, are dropped). jvmTest 1,988 | | 3 | done. Every message, and a group's voucher, also goes into the room of every group its author holds a seat in that the device holds, beside the confederation's room, which is still the channel that works. An envelope now names the room it was written into (`ConfederationSigningEvents.ROOM_TAG`): the same events written into two rooms made one envelope id, and the second room's row overwrote the first's, so a message went to one room only. `process` already took envelopes from any room, by their confederation tag. `ConfederationPeople.withGroupRooms` gives the fixture each group's room, inbox key and signed 10044, with members it can demote or remove. `ConfederationSigningJvmTest` 19/19 (every role holder's messages in their own group's room and no other; a member who holds no seat answers nothing), `ConfederationSharedSeatsSigningJvmTest` 3/3 (someone seated in all three groups writes into all three rooms). jvmTest 1,991 | | 4 | done. `ConfederationBridge`: a message heard in a group's room -- or written there by this device's owner -- is owed out by each of the group's current admins who holds its inbox key, at `k × 20` seconds by their place, but only when its author holds a seat in that group or it is that group's voucher, so nothing carried in bounces back out. Owed out is one 30398 rumor per group, confederation and sweep, sealed as the admin to every member group's announced inbox key and owed through `GroupInboxPublication` under the group's room; owed in is one envelope into the room, only where the group has a seated member who is not its admin. Seeing a copy back (through the group's inbox for out, in the room for in) marks it done on every other admin's device. `ConfederationCarry` keeps the turns, folded into schema 52, and is forgotten after the signing floor. `GroupInboxManager.receive` takes the identity's key, which `LiveSubscriptionManager` passes, and hands a 30398 to `ConfederationSigningManager.receiveFromInbox`; without a key it only files what came. **The switch:** `propose` takes the confederation's id; nothing in signing looks up a `ChatRoom` for the confederation, nor writes to one. Two writes that had a key onto the room moved here from later phases: the signing's lines go into each seat group's room (D9's half, from Phase 6), and `complete` no longer files a `GroupSignedEvent` under the confederation (from Phase 7; Phase 1 already filed it in `ConfederationEvent`). `ConfederationProfileFollowThrough` needs no room. The fixtures carry no confederation room: `ConfederationSigningJvmTest`'s pump ferries group rooms, runs the admins' turns and delivers inbox wraps, holding back an envelope or a wrap by what it carries (opened with the fixture's inbox secrets); `ConfederationTestGroups.pumpConfederation` does the same over real inboxes. `ConfederationSigningJvmTest` 24/24 (new: no room anywhere; each group's messages cross once, carried by its first admin; with the first away, nothing of Agora's crosses until the next admin's turn twenty seconds on; a founder Agora has demoted signs for their seat through Agora's room; one Agora has removed hears nothing and the others sign). Not built as planned: "an admin who changes a bundle" -- Phase 2's tests already drop a changed event on whatever path it comes, so withholding was tested instead. jvmTest 1,996 | +| 6 | done. `ConfederationScreen` gains **Posts** (its signed kind:1s from `ConfederationEvent`, and **Add post** for someone who holds a seat), **Charter** (signed, or **Propose the charter** for a seat-holder, or "no charter yet"), and **Signing** for a seat-holder: their attempts, the ones waiting on them first, then what is running, then the last five ended, each opening `ConfederationSigningScreen`. **Open the confederation's room** goes. The composer is `AddGroupPostRoute` with a `confederationId`, which proposes through `ChatRepository.proposeAsConfederation(confederationId, …)` and bylines the confederation, rather than a new screen. A post or charter the person must answer is a new line, `TYPE_CONFEDERATION_SIGNING_ASKED`, theirs and in `NotificationClassifier.NEEDS_YOU`; the proposer's own and a profile's, which nobody is asked, stay `…_PROPOSED` and quiet. A signed post is owed to relays by every device that signed it (D10). From the room screens: the confederation's card, its members' group labels, `ConfederationRoomInfo`, `confederationRoomInfo`, `confederationOfRoom`, `ChatRepository.proposeCharter`, `ConfederationRepository.holdsRoomOf`, and the confederation branches of the posts, profile and edit-profile view models; four strings, and the ceremony room's banner no longer says "works in its own room". `ConfederationSigningJvmTest` 26/26 (the room-info case replaced: an ask in each role holder's group room that is theirs; a post owed by every signer; the signing list's order), `ConfederationProfileScreensJvmTest` (a seat-holder's posts, add, charter and waiting attempt; a member without a seat offered nothing to sign; no charter said so). jvmTest 2,001; m3, brand, wallet and Marmot audits pass | ---