From 1fd13942fa80bfdae7f1dafb5834721431817584 Mon Sep 17 00:00:00 2001 From: Kgothatso Ngako Date: Mon, 23 Nov 2026 14:00:18 +0200 Subject: [PATCH] feat: the ceremony's lines open it from the group rooms, and the ceremony room's banner goes (confederation-dkg-inboxes, Phase 6) A key ceremony's started, finished and failed lines, in each of a person's seat groups' rooms, open the ceremony by its proposal. The banner that led from the ceremony's NIP-17 room goes, with the composer gate on a finished one, proposalOfRoom and four strings. The ceremony's screen says, under a step, when this device's own group holds a message of it that no admin has yet carried to the others: "Sent; waiting for an admin of Agora to pass it on". Co-Authored-By: Claude Opus 5.5 --- .../composeResources/values/strings.xml | 5 +- .../database/dao/ConfederationCeremonyDao.kt | 8 + .../compose/database/model/ChatMessage.kt | 7 + .../repository/DatabaseChatRepository.kt | 16 - .../DatabaseConfederationRepository.kt | 5 + .../managers/ConfederationRitualManager.kt | 13 - .../giza/compose/repository/ChatRepository.kt | 6 - .../repository/ConfederationRepository.kt | 6 + .../ui/composable/ChatRoomMessagingScreen.kt | 344 ++++++++---------- .../composable/ConfederationRitualScreen.kt | 16 +- .../composable/widgets/chat/ChatTranscript.kt | 17 + .../view/model/ChatRoomMessagingViewModel.kt | 7 +- .../model/ConfederationRitualViewModel.kt | 19 +- .../ui/view/state/ChatRoomMessagingUIState.kt | 22 -- .../view/state/ConfederationRitualUIState.kt | 7 +- .../managers/ConfederationCeremonyJvmTest.kt | 27 ++ .../composable/ConfederationScreensJvmTest.kt | 11 + docs/confederation-dkg-inboxes.md | 2 + 18 files changed, 260 insertions(+), 278 deletions(-) diff --git a/composeApp/src/commonMain/composeResources/values/strings.xml b/composeApp/src/commonMain/composeResources/values/strings.xml index a54e5e0f..c80f5639 100644 --- a/composeApp/src/commonMain/composeResources/values/strings.xml +++ b/composeApp/src/commonMain/composeResources/values/strings.xml @@ -745,14 +745,12 @@ Abandon the key ceremony This device holds no key ceremony for this proposal The others have started the key ceremony. It cannot go on until you join. - This room runs a confederation's key ceremony. - This room runs a confederation's key ceremony, and it cannot go on until you join. - Open the key ceremony Host keys Contributions Authorizations Shares stored Waiting on %1$s + Sent; waiting for an admin of %1$s to pass it on Done The confederation's key is made The ceremony ended: %1$s @@ -820,7 +818,6 @@ The confederation has signed its charter, naming its groups The confederation has no charter yet 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/ConfederationCeremonyDao.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/dao/ConfederationCeremonyDao.kt index e64a7a1d..ec47cf44 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/dao/ConfederationCeremonyDao.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/dao/ConfederationCeremonyDao.kt @@ -146,6 +146,14 @@ interface ConfederationCeremonyDao { @Query("SELECT * FROM ConfederationCarry WHERE doneAt IS NULL AND dueAt <= :now ORDER BY dueAt ASC") suspend fun getDueCarries(now: kotlin.time.Instant): List + /** + * A ceremony's messages that this device's groups owe the other groups' inboxes and that nobody has + * been seen carrying yet (docs/confederation-dkg-inboxes.md, Phase 6): what its screen says is + * still waiting to cross. + */ + @Query("SELECT * FROM ConfederationCarry WHERE scope = 'CEREMONY' AND confederationId = :proposalId AND direction = 'OUT' AND doneAt IS NULL") + fun observeCeremonyCarriesWaiting(proposalId: HexKey): Flow> + @Query("SELECT * FROM ConfederationCarry WHERE groupRoomId = :groupRoomId") suspend fun getCarries(groupRoomId: String): List 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 8e5037e3..ddda5d36 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 @@ -599,6 +599,13 @@ data class ChatMessage( TYPE_CONFEDERATION_PROFILE_PUBLISHED, ) + /** A confederation's key ceremony, said in each seat group's room; each opens the ceremony by its proposal. */ + val CONFEDERATION_CEREMONY_TYPES = setOf( + TYPE_CONFEDERATION_CEREMONY_STARTED, + TYPE_CONFEDERATION_CEREMONY_COMPLETE, + TYPE_CONFEDERATION_CEREMONY_FAILED, + ) + val CONFEDERATION_TYPES = CONFEDERATION_PROFILE_TYPES + setOf( TYPE_CONFEDERATION_PROPOSED, TYPE_CONFEDERATION_ACCEPTED, 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 126a5972..93b9c623 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 @@ -402,22 +402,6 @@ class DatabaseChatRepository( 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? { - val proposalId = ConfederationRitualManager.proposalOfRoom(database, chatRoomId) ?: return null - val joined = database.confederationCeremonyDao().getLatestForProposal(proposalId)?.approvedAt != null - val formed = database.confederationCeremonyDao().getConfederationForProposal(proposalId) - ?.takeIf { ConfederationFormation.verifies(it) } - ?.let { confederation -> - mobi.giza.compose.ui.view.state.FormedConfederation(confederation.id, confederation.name, homeGroupOf(confederation.id)) - } - return mobi.giza.compose.ui.view.state.KeyCeremonyLink(proposalId = proposalId, joined = joined, formed = formed) - } - - /** A member group of [confederationId] this device holds the room of: where its screen is opened from. */ - private suspend fun homeGroupOf(confederationId: String): String? = - mobi.giza.compose.managers.ConfederationProfileManager.membership(database, confederationId)?.groups - ?.firstOrNull { database.chatRoomDao().findChatRoomById(it) != null } - 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 fe803c69..593a9b78 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 @@ -63,6 +63,11 @@ class DatabaseConfederationRepository( override fun observeCeremonyMessages(sessionId: String): Flow> = database.confederationCeremonyDao().observeMessages(sessionId) + override fun observeWaitingToCross(proposalId: HexKey): Flow>> = + database.confederationCeremonyDao().observeCeremonyCarriesWaiting(proposalId).map { rows -> + rows.mapNotNull { row -> com.vitorpamplona.quartz.nip01Core.core.Event.fromJsonOrNull(row.eventJson)?.let { row.groupRoomId to it.kind } } + } + override fun ceremonyPlan(ceremony: ConfederationCeremony): ConfederationRosterBuilder.Plan? = ConfederationRitualManager.planOf(ceremony) diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/ConfederationRitualManager.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/ConfederationRitualManager.kt index 601a2012..2c0fd65f 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/ConfederationRitualManager.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/ConfederationRitualManager.kt @@ -220,19 +220,6 @@ object ConfederationRitualManager { is Either.Right -> eligibility(database, built.value, userPublicKey) } - /** - * The proposal whose key ceremony runs in [chatRoomId], or null when it carries none this device - * holds the proposal for. Read from the ceremony messages filed there, sent or received: the - * room is made by the first one to arrive, so on a device whose owner has not joined, those - * messages are all the room has to say what it is for. - */ - suspend fun proposalOfRoom(database: GizaDatabase, chatRoomId: String): HexKey? = - database.giftWrapPayloadDao() - .getByChatRoomAndKinds(chatRoomId, ConfederationRitualEvents.ALL.toList()) - .mapNotNull { ConfederationRitualEvents.parseProposalId(it.tags) } - .distinct() - .lastOrNull { database.confederationDao().getEvent(it) != null } - /** * Joins the key ceremony for [proposalId] as [userPublicKey]: the one thing a member is asked, * offered to every admin of every group once every group has accepted (D7). Makes the ceremony 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 145bced8..d48d6301 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/repository/ChatRepository.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/repository/ChatRepository.kt @@ -154,12 +154,6 @@ interface ChatRepository { */ suspend fun inboxSummary(localChatRoom: LocalChatRoom): mobi.giza.compose.ui.view.state.InboxRowSummary? = null - /** - * The confederation key ceremony that runs in [chatRoomId], if it is one's room, and whether this - * device has joined it. The room is made by the first ceremony message to arrive, before its owner - * has joined, and it is where they look for the ceremony. - */ - suspend fun keyCeremonyOfRoom(chatRoomId: String): mobi.giza.compose.ui.view.state.KeyCeremonyLink? = null /** * The formed confederations the group of [chatRoomId] is a member of, as (id, name), by record or 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 88384d71..721f69d0 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/repository/ConfederationRepository.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/repository/ConfederationRepository.kt @@ -80,6 +80,12 @@ interface ConfederationRepository { fun observeCeremonyMessages(sessionId: String): Flow> + /** + * A ceremony's messages this device's groups have yet to carry across: each the group it is owed + * from and its kind (docs/confederation-dkg-inboxes.md, Phase 6). + */ + fun observeWaitingToCross(proposalId: HexKey): Flow>> = flowOf(emptyList()) + /** The roster's plan a ceremony runs over, or null if its basis no longer reads. */ fun ceremonyPlan(ceremony: ConfederationCeremony): ConfederationRosterBuilder.Plan? diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ChatRoomMessagingScreen.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ChatRoomMessagingScreen.kt index 73542e25..54eb4c2e 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ChatRoomMessagingScreen.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ChatRoomMessagingScreen.kt @@ -58,12 +58,6 @@ import mobi.giza.compose.ui.composable.navigation.routes.ConfederationRoute import mobi.giza.compose.ui.composable.navigation.routes.ChatRoomDetailRoute import mobi.giza.compose.ui.composable.navigation.routes.DkgRitualRoute import mobi.giza.compose.ui.composable.navigation.routes.ConfederationRitualRoute -import mobi.giza.compose.ui.view.state.KeyCeremonyLink -import mobi.giza.compose.resources.open_the_key_ceremony -import mobi.giza.compose.resources.open_the_confederation -import mobi.giza.compose.resources.the_key_ceremony_for_is_complete -import mobi.giza.compose.resources.this_room_runs_a_key_ceremony -import mobi.giza.compose.resources.this_room_waits_for_you_to_join import mobi.giza.compose.ui.composable.navigation.routes.ProposalListRoute import mobi.giza.compose.ui.composable.navigation.routes.proposalDestination import mobi.giza.compose.ui.composable.navigation.routes.Route @@ -204,28 +198,6 @@ fun ChatRoomMessagingScreen( Column( modifier = Modifier.padding(innerPadding).readableContent().fillMaxSize() ) { - // A confederation's key ceremony runs in this room. The room is made by the - // first message to arrive, before its owner has joined, and the join is not - // in the transcript, so this is the way from here to it. - chatRoomDetailUIState.keyCeremony?.let { link -> - KeyCeremonyBanner( - link = link, - onOpen = { - // Once the ceremony has made the confederation, the way from here - // is to it (docs/confederation-profile.md, D10). - val formed = link.formed - val home = formed?.homeGroupId - onNavigateToRoute.invoke( - if (formed != null && home != null) { - ConfederationRoute(activeUserPublicKey = activeUserPublicKey, chatRoomId = home, confederationId = formed.confederationId) - } else { - ConfederationRitualRoute(activeUserPublicKey = activeUserPublicKey, proposalId = link.proposalId) - } - ) - }, - ) - } - if (disappearingSettings != null && chatRoomDetailUIState.localChatRoom.chatRoom.mlsGroupState == null) { DisappearingNotice(chatRoomId, activeUserPublicKey, disappearingSettings) { onNavigateToRoute.invoke(DisappearingMessagesRoute(activeUserPublicKey, chatRoomId)) @@ -256,6 +228,9 @@ fun ChatRoomMessagingScreen( ConfederationRoute(activeUserPublicKey = activeUserPublicKey, chatRoomId = chatRoomId, confederationId = confederationId) ) }, + onOpenKeyCeremony = { proposalId -> + onNavigateToRoute.invoke(ConfederationRitualRoute(activeUserPublicKey = activeUserPublicKey, proposalId = proposalId)) + }, onOpenSigning = { sessionId -> onNavigateToRoute.invoke( proposalDestination( @@ -297,168 +272,163 @@ fun ChatRoomMessagingScreen( // the ime inset already covers the navigation bar area this row is // separately reserving. Getting the combination right wants a device // with a keyboard open, not a compiler. - // A key ceremony's room once the ceremony has made its confederation: - // anything typed here would reach the founding people as people, which - // is what the confederation's groups are for (docs/confederation-profile.md, D10). - if (chatRoomDetailUIState.keyCeremony?.formed == null) { - Column( - modifier = Modifier.fillMaxWidth() - .background(BottomAppBarDefaults.containerColor) - .navigationBarsPadding() - ) { - // An armed composer has to be impossible to miss. The whole risk - // of this feature is somebody sending to the room what they meant - // for one person, or the reverse, and by the time either is on the - // wire it cannot be taken back. Hence three signals at once: the - // chip, the placeholder, and the tinted field. - val directMessageRecipient = chatMessageListViewModel.directMessageRecipient + Column( + modifier = Modifier.fillMaxWidth() + .background(BottomAppBarDefaults.containerColor) + .navigationBarsPadding() + ) { + // An armed composer has to be impossible to miss. The whole risk + // of this feature is somebody sending to the room what they meant + // for one person, or the reverse, and by the time either is on the + // wire it cannot be taken back. Hence three signals at once: the + // chip, the placeholder, and the tinted field. + val directMessageRecipient = chatMessageListViewModel.directMessageRecipient - if (directMessageRecipient != null) { - Row( - modifier = Modifier - .fillMaxWidth() - .background(MaterialTheme.colorScheme.primaryContainer) - .padding(horizontal = MaterialTheme.spacing.containerPadding, vertical = MaterialTheme.spacing.space75), - horizontalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.itemGap), - verticalAlignment = Alignment.CenterVertically + if (directMessageRecipient != null) { + Row( + modifier = Modifier + .fillMaxWidth() + .background(MaterialTheme.colorScheme.primaryContainer) + .padding(horizontal = MaterialTheme.spacing.containerPadding, vertical = MaterialTheme.spacing.space75), + horizontalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.itemGap), + verticalAlignment = Alignment.CenterVertically + ) { + Icon( + Icons.Default.Lock, + contentDescription = Decorative, + modifier = Modifier.size(16.dp), + tint = MaterialTheme.colorScheme.onPrimaryContainer + ) + + Text( + modifier = Modifier.weight(1f), + text = stringResource(Res.string.private_to, chatMessageListViewModel.nameFor(directMessageRecipient.participantPublicKey)), + color = MaterialTheme.colorScheme.onPrimaryContainer, + style = MaterialTheme.typography.labelMedium + ) + + // The one way back to the room, and it has to be one tap. + IconButton( + onClick = { chatMessageListViewModel.cancelDirectMessage() } ) { Icon( - Icons.Default.Lock, - contentDescription = Decorative, - modifier = Modifier.size(16.dp), + Icons.Default.Close, + contentDescription = "Send to the whole group instead", tint = MaterialTheme.colorScheme.onPrimaryContainer ) - - Text( - modifier = Modifier.weight(1f), - text = stringResource(Res.string.private_to, chatMessageListViewModel.nameFor(directMessageRecipient.participantPublicKey)), - color = MaterialTheme.colorScheme.onPrimaryContainer, - style = MaterialTheme.typography.labelMedium - ) - - // The one way back to the room, and it has to be one tap. - IconButton( - onClick = { chatMessageListViewModel.cancelDirectMessage() } - ) { - Icon( - Icons.Default.Close, - contentDescription = "Send to the whole group instead", - tint = MaterialTheme.colorScheme.onPrimaryContainer - ) - } } } + } - Box( - modifier = Modifier.fillMaxWidth() - ) { - OutlinedTextField( - modifier = Modifier.fillMaxWidth(), - state = textFieldState, - colors = OutlinedTextFieldDefaults.colors( - focusedBorderColor = Color.Transparent, - unfocusedBorderColor = Color.Transparent, - disabledBorderColor = Color.Transparent, - focusedContainerColor = if (directMessageRecipient != null) { - MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.3f) - } else { - Color.Transparent - }, - unfocusedContainerColor = if (directMessageRecipient != null) { - MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.3f) - } else { - Color.Transparent - } - ), - placeholder = { - Text( - text = if (directMessageRecipient != null) { - stringResource(Res.string.private_message_to, chatMessageListViewModel.nameFor(directMessageRecipient.participantPublicKey)) - } else { - stringResource(Res.string.say_what_now) - } - ) + Box( + modifier = Modifier.fillMaxWidth() + ) { + OutlinedTextField( + modifier = Modifier.fillMaxWidth(), + state = textFieldState, + colors = OutlinedTextFieldDefaults.colors( + focusedBorderColor = Color.Transparent, + unfocusedBorderColor = Color.Transparent, + disabledBorderColor = Color.Transparent, + focusedContainerColor = if (directMessageRecipient != null) { + MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.3f) + } else { + Color.Transparent }, - trailingIcon = { - if (textFieldState.text.isEmpty()) { - IconButton( - onClick = { - - } - ) { - Icon( - Icons.Default.Mic, - contentDescription = "Voice" - ) - } - + unfocusedContainerColor = if (directMessageRecipient != null) { + MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.3f) + } else { + Color.Transparent + } + ), + placeholder = { + Text( + text = if (directMessageRecipient != null) { + stringResource(Res.string.private_message_to, chatMessageListViewModel.nameFor(directMessageRecipient.participantPublicKey)) } else { - IconButton( - onClick = { - chatMessageListViewModel.sendMessage( - textFieldState = textFieldState - ) - } - ) { - Icon( - Icons.AutoMirrored.Filled.Send, - contentDescription = "Send" + stringResource(Res.string.say_what_now) + } + ) + }, + trailingIcon = { + if (textFieldState.text.isEmpty()) { + IconButton( + onClick = { + + } + ) { + Icon( + Icons.Default.Mic, + contentDescription = "Voice" + ) + } + + } else { + IconButton( + onClick = { + chatMessageListViewModel.sendMessage( + textFieldState = textFieldState ) } + ) { + Icon( + Icons.AutoMirrored.Filled.Send, + contentDescription = "Send" + ) } } - ) - } - - // Row( - // modifier = Modifier.padding(4.dp), - // horizontalArrangement = Arrangement.spacedBy(4.dp) - // ) { - // IconButton( - // onClick = { - // - // } - // ) { - // Icon( - // Icons.Default.InsertEmoticon, - // contentDescription = "Add emoji" - // ) - // } - // - // IconButton( - // onClick = { - // - // } - // ) { - // Icon( - // Icons.Default.AlternateEmail, - // contentDescription = "Mention profile" - // ) - // } - // - // IconButton( - // onClick = { - // - // } - // ) { - // Icon( - // Icons.Default.Collections, - // contentDescription = "Attach media" - // ) - // } - // - // IconButton( - // onClick = { - // - // } - // ) { - // Icon( - // Icons.Default.LocationOn, - // contentDescription = "Send location" - // ) - // } - // } + } + ) } + + // Row( + // modifier = Modifier.padding(4.dp), + // horizontalArrangement = Arrangement.spacedBy(4.dp) + // ) { + // IconButton( + // onClick = { + // + // } + // ) { + // Icon( + // Icons.Default.InsertEmoticon, + // contentDescription = "Add emoji" + // ) + // } + // + // IconButton( + // onClick = { + // + // } + // ) { + // Icon( + // Icons.Default.AlternateEmail, + // contentDescription = "Mention profile" + // ) + // } + // + // IconButton( + // onClick = { + // + // } + // ) { + // Icon( + // Icons.Default.Collections, + // contentDescription = "Attach media" + // ) + // } + // + // IconButton( + // onClick = { + // + // } + // ) { + // Icon( + // Icons.Default.LocationOn, + // contentDescription = "Send location" + // ) + // } + // } } } } @@ -574,27 +544,3 @@ private fun ChatRoomMessagingScreenPreview() { } } -/** Where a key ceremony's room leads: to the ceremony, and, until its owner joins, to the join. */ -@Composable -private fun KeyCeremonyBanner(link: KeyCeremonyLink, onOpen: () -> Unit) { - val container = if (link.joined) MaterialTheme.colorScheme.surfaceContainerHigh else MaterialTheme.colorScheme.secondaryContainer - val content = if (link.joined) MaterialTheme.colorScheme.onSurface else MaterialTheme.colorScheme.onSecondaryContainer - Surface(modifier = Modifier.fillMaxWidth(), color = container, contentColor = content) { - Row( - modifier = Modifier.padding(start = MaterialTheme.spacing.containerPadding, end = MaterialTheme.spacing.compactPadding), - horizontalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.itemGap), - verticalAlignment = Alignment.CenterVertically, - ) { - Icon(Icons.Default.Key, contentDescription = Decorative) - Text( - modifier = Modifier.weight(1f).padding(vertical = MaterialTheme.spacing.compactPadding), - text = link.formed?.let { stringResource(Res.string.the_key_ceremony_for_is_complete, it.name) } - ?: stringResource(if (link.joined) Res.string.this_room_runs_a_key_ceremony else Res.string.this_room_waits_for_you_to_join), - style = MaterialTheme.typography.bodyMedium, - ) - TextButton(onClick = onOpen) { - Text(stringResource(if (link.formed?.homeGroupId != null) Res.string.open_the_confederation else Res.string.open_the_key_ceremony)) - } - } - } -} diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ConfederationRitualScreen.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ConfederationRitualScreen.kt index 43577ba3..ce0c178f 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ConfederationRitualScreen.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ConfederationRitualScreen.kt @@ -40,6 +40,7 @@ import mobi.giza.compose.resources.ceremony_step_done import mobi.giza.compose.resources.ceremony_step_host_keys import mobi.giza.compose.resources.ceremony_step_shares_stored import mobi.giza.compose.resources.ceremony_waiting_on +import mobi.giza.compose.resources.confederation_ritual_waiting_to_cross import mobi.giza.compose.resources.could_not_join_the_key_ceremony import mobi.giza.compose.resources.the_others_have_started_without_you import mobi.giza.compose.resources.confederation_groups @@ -200,10 +201,17 @@ fun ConfederationRitualScreen( }, headlineContent = { Text(stepLabel(step.kind)) }, supportingContent = { - Text( - if (done) stringResource(Res.string.ceremony_step_done) - else stringResource(Res.string.ceremony_waiting_on, step.waitingOn.joinToString()) - ) + Column { + Text( + if (done) stringResource(Res.string.ceremony_step_done) + else stringResource(Res.string.ceremony_waiting_on, step.waitingOn.joinToString()) + ) + // What this device's own groups have yet to carry to the others + // (docs/confederation-dkg-inboxes.md, Phase 6). + if (step.waitingToCross.isNotEmpty()) { + Text(stringResource(Res.string.confederation_ritual_waiting_to_cross, step.waitingToCross.joinToString())) + } + } }, ) } 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 092d8d39..cd861a51 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 @@ -132,6 +132,8 @@ fun ChatTranscript( onOpenConfederationChange: (changeId: String) -> Unit = {}, /** Opens a confederation, from the line saying it has a new profile. */ onOpenConfederation: (confederationId: String) -> Unit = {}, + /** Opens a confederation's key ceremony, by its proposal: docs/confederation-dkg-inboxes.md, Phase 6. */ + onOpenKeyCeremony: (proposalId: String) -> Unit = {}, /** Opens the room's proposals, all of them, whatever their state. */ onOpenProposals: () -> Unit, ) { @@ -405,6 +407,21 @@ fun ChatTranscript( // A proposal for a confederation to sign something, or the profile it // ended in: each opens what it is about. docs/confederation-profile.md, D8. + // A confederation's key ceremony, said in each seat group's room now that + // it has none of its own: it opens the ceremony, which says where it + // stands. docs/confederation-dkg-inboxes.md, Phase 6. + if (localChatMessage.chatMessage.messageType in ChatMessage.CONFEDERATION_CEREMONY_TYPES) { + val proposalId = localChatMessage.chatMessage.frostSigningSessionId + RitualNotice( + localChatMessage = localChatMessage, + isAnswered = true, + isSettled = true, + onClick = proposalId?.let { { onOpenKeyCeremony(it) } }, + opens = null, + ) + return@items + } + if (localChatMessage.chatMessage.messageType in ChatMessage.CONFEDERATION_PROFILE_TYPES) { val target = localChatMessage.chatMessage.frostSigningSessionId RitualNotice( diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/ChatRoomMessagingViewModel.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/ChatRoomMessagingViewModel.kt index ad81b6d1..ac68138e 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/ChatRoomMessagingViewModel.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/ChatRoomMessagingViewModel.kt @@ -54,12 +54,7 @@ class ChatRoomMessagingViewModel( // Initiate new chat... and navigate to new chat... ChatRoomMessagingUIState.InitiatingNewChat } else { - ChatRoomMessagingUIState.Loaded( - localChatRoom = localChatRoom, - keyCeremony = runCatching { chatRepository.keyCeremonyOfRoom(chatRoomId) } - .onFailure { logger.e("Could not read the key ceremony of $chatRoomId", it) } - .getOrNull(), - ) + ChatRoomMessagingUIState.Loaded(localChatRoom = localChatRoom) } } } diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/ConfederationRitualViewModel.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/ConfederationRitualViewModel.kt index 7a3e7fc5..374e9d5f 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/ConfederationRitualViewModel.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/ConfederationRitualViewModel.kt @@ -16,11 +16,13 @@ import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.flowOf +import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch import mobi.giza.compose.nostr.confederation.ConfederationRitualEvents import mobi.giza.compose.nostr.confederation.ConfederationRosterBuilder import mobi.giza.compose.database.model.ConfederationCeremony +import mobi.giza.compose.database.model.ConfederationCeremonyMessage import mobi.giza.compose.repository.ConfederationRepository import mobi.giza.compose.ui.view.state.ConfederationRitualUIState import mobi.giza.compose.ui.view.state.ConfederationRitualUIState.Step @@ -47,10 +49,12 @@ class ConfederationRitualViewModel( viewModelScope.launch(Dispatchers.IO) { confederationRepository.observeCeremony(proposalId) .flatMapLatest { ceremony -> - if (ceremony == null) flowOf(null to emptyList()) - else confederationRepository.observeCeremonyMessages(ceremony.id).combine(flowOf(ceremony)) { m, c -> c to m } + if (ceremony == null) flowOf(Triple, List>>(null, emptyList(), emptyList())) + else confederationRepository.observeCeremonyMessages(ceremony.id) + .combine(confederationRepository.observeWaitingToCross(proposalId)) { m, w -> Triple(ceremony, m, w) } + .map { (c, m, w) -> Triple, List>>(c, m, w) } } - .collectLatest { (ceremony, messages) -> + .collectLatest { (ceremony, messages, toCross) -> if (ceremony == null) { // Nothing is made on a device until its owner joins, so a device that heard // the others start holds no ceremony: offer the join here, where they look. @@ -76,6 +80,7 @@ class ConfederationRitualViewModel( val names = namesOf(plan) val sent = { kind: Int -> messages.filter { it.kind == kind }.map { it.senderPublicKey }.toSet() } val waiting = { kind: Int -> plan.people.filterNot { it in sent(kind) }.map { names.getValue(it) } } + val crossing = { kind: Int -> toCross.filter { it.second == kind }.map { it.first }.distinct().map { names[it] ?: it.take(8) } } val acting = (state.value as? ConfederationRitualUIState.Loaded)?.isActing == true state.value = ConfederationRitualUIState.Loaded( ceremony = ceremony, @@ -83,10 +88,10 @@ class ConfederationRitualViewModel( groups = rolesOf(plan, names), threshold = plan.proposal.threshold, steps = listOf( - Step(StepKind.HOST_KEYS, waiting(ConfederationRitualEvents.HOST_KEYS)), - Step(StepKind.CONTRIBUTIONS, waiting(ConfederationRitualEvents.DEALINGS)), - Step(StepKind.AUTHORIZATIONS, waiting(ConfederationRitualEvents.AUTHORIZATIONS)), - Step(StepKind.SHARES_STORED, waiting(ConfederationRitualEvents.ACKNOWLEDGMENTS)), + Step(StepKind.HOST_KEYS, waiting(ConfederationRitualEvents.HOST_KEYS), crossing(ConfederationRitualEvents.HOST_KEYS)), + Step(StepKind.CONTRIBUTIONS, waiting(ConfederationRitualEvents.DEALINGS), crossing(ConfederationRitualEvents.DEALINGS)), + Step(StepKind.AUTHORIZATIONS, waiting(ConfederationRitualEvents.AUTHORIZATIONS), crossing(ConfederationRitualEvents.AUTHORIZATIONS)), + Step(StepKind.SHARES_STORED, waiting(ConfederationRitualEvents.ACKNOWLEDGMENTS), crossing(ConfederationRitualEvents.ACKNOWLEDGMENTS)), ), awaitingJoin = ceremony.isRunning && ceremony.approvedAt == null, isActing = acting, diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/ChatRoomMessagingUIState.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/ChatRoomMessagingUIState.kt index b4866e0c..91bc838b 100755 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/ChatRoomMessagingUIState.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/ChatRoomMessagingUIState.kt @@ -1,13 +1,10 @@ package mobi.giza.compose.ui.view.state -import com.vitorpamplona.quartz.nip01Core.core.HexKey import mobi.giza.compose.database.model.intermdiate.LocalChatRoom sealed interface ChatRoomMessagingUIState { data class Loaded( val localChatRoom: LocalChatRoom, - /** The confederation key ceremony this room carries, if it is one's room. */ - val keyCeremony: KeyCeremonyLink? = null, ): ChatRoomMessagingUIState data class Error( @@ -16,22 +13,3 @@ sealed interface ChatRoomMessagingUIState { data object Loading: ChatRoomMessagingUIState data object InitiatingNewChat: ChatRoomMessagingUIState } - - -/** - * A confederation's key ceremony, from the room it runs in: the way to it from there, since the room - * is made by the first message to arrive, before its owner has joined (docs/confederation.md, Phase 11). - */ -data class KeyCeremonyLink( - val proposalId: HexKey, - /** Whether this device's owner has joined the latest attempt. */ - val joined: Boolean, - /** - * The confederation the ceremony made, once it has: the room has nothing more to do, and the way - * from it is to the confederation (docs/confederation-profile.md, D10). - */ - val formed: FormedConfederation? = null, -) - -/** A formed confederation, and the member group this device opens it from. */ -data class FormedConfederation(val confederationId: HexKey, val name: String, val homeGroupId: String?) diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/ConfederationRitualUIState.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/ConfederationRitualUIState.kt index 27661de3..0b7f1a4a 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/ConfederationRitualUIState.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/ConfederationRitualUIState.kt @@ -20,7 +20,12 @@ sealed interface ConfederationRitualUIState { enum class StepKind { HOST_KEYS, CONTRIBUTIONS, AUTHORIZATIONS, SHARES_STORED } - data class Step(val kind: StepKind, val waitingOn: List) + /** + * [waitingToCross]: the groups, by name, of this device's own that hold a message of this step in + * their room that no admin has yet carried to the other groups (docs/confederation-dkg-inboxes.md, + * Phase 6). A device cannot see what another group has not carried, so these are only ever its own. + */ + data class Step(val kind: StepKind, val waitingOn: List, val waitingToCross: List = emptyList()) /** * No ceremony on this device yet, and its owner can join one: nothing is made here until they 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 02002456..6fe3192c 100644 --- a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/ConfederationCeremonyJvmTest.kt +++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/ConfederationCeremonyJvmTest.kt @@ -623,6 +623,33 @@ class ConfederationCeremonyJvmTest { } } + // ---- docs/confederation-dkg-inboxes.md, Phase 6: where a person sees it ----------------------- + + @Test + fun `the ceremony's lines are in each of a person's groups' rooms, each naming the proposal it opens`() { + setUp(listOf(listOf(11, 12, 13), listOf(11, 22, 23), listOf(31, 32, 33))) + joinAll() + pump() + runBlocking { + val shared = network.device(11) + listOf(groups[0], groups[1]).forEach { group -> + val lines = shared.db.chatMessageDao().getChatMessagesByChatRoomId(group).map { it.chatMessage } + .filter { it.messageType in mobi.giza.compose.database.model.ChatMessage.CONFEDERATION_CEREMONY_TYPES } + assertEquals( + setOf(mobi.giza.compose.database.model.ChatMessage.TYPE_CONFEDERATION_CEREMONY_STARTED, mobi.giza.compose.database.model.ChatMessage.TYPE_CONFEDERATION_CEREMONY_COMPLETE), + lines.map { it.messageType }.toSet(), + "started and finished, in ${group.take(6)}", + ) + lines.forEach { assertEquals(network.proposalId, it.frostSigningSessionId, "the line opens the ceremony by its proposal") } + } + assertEquals( + emptyList(), + shared.db.chatMessageDao().getChatMessagesByChatRoomId(groups[2]).filter { it.chatMessage.messageType in mobi.giza.compose.database.model.ChatMessage.CONFEDERATION_CEREMONY_TYPES }, + "nothing in a room this device does not hold a seat for", + ) + } + } + // ---- docs/confederation-room-removal.md, Phase 7: no room of its own ------------------------- private fun formed(): mobi.giza.compose.database.model.Confederation { diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/composable/ConfederationScreensJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/composable/ConfederationScreensJvmTest.kt index a4585189..b5f82488 100644 --- a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/composable/ConfederationScreensJvmTest.kt +++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/composable/ConfederationScreensJvmTest.kt @@ -313,6 +313,17 @@ class ConfederationScreensJvmTest { onNodeWithText("Abandon the key ceremony").assertIsDisplayed() } + @Test + fun `a step this device's own group has not yet carried says it is waiting to be passed on`() = renderRitual( + ritual(ConfederationCeremonyStage.COLLECTING_HOST_KEYS, approved = true).let { loaded -> + loaded.copy(steps = loaded.steps.mapIndexed { i, step -> if (i == 0) step.copy(waitingToCross = listOf("Agora")) else step }) + } + ) { + onNodeWithText("Waiting on Bo").assertIsDisplayed() + onNodeWithText("Sent; waiting for an admin of Agora to pass it on").assertIsDisplayed() + onAllNodesWithText("waiting for an admin of", substring = true).assertCountEquals(1) + } + @Test fun `an ended ceremony says why`() = renderRitual(ritual(ConfederationCeremonyStage.FAILED, approved = true, failure = "Abandoned by a participant")) { onNodeWithText("The ceremony ended: Abandoned by a participant").assertIsDisplayed() diff --git a/docs/confederation-dkg-inboxes.md b/docs/confederation-dkg-inboxes.md index 121083de..fcd0cd6b 100644 --- a/docs/confederation-dkg-inboxes.md +++ b/docs/confederation-dkg-inboxes.md @@ -458,6 +458,8 @@ The two refusals are read in the composable and shown where `join`'s exception i - `ChatRoomMessagingViewModel`'s tests lose the banner case. - `m3Audit` stays at budget. +**Done.** As planned, but for three things. The lines themselves were written in Phase 5. The two refusals stay sentences from `ConfederationRitualManager`, as every other reason a join is refused is, and are shown where `join`'s exception already is: only the new waiting line went into the catalogue. And no test renders `ChatTranscript`, here or before. So the ceremony's lines are checked where they are written: started and finished, in each of a person's seat groups' rooms, each carrying the proposal's id, and nothing in a room the person holds no seat for. Their opening is the new `onOpenKeyCeremony`, wired to `ConfederationRitualRoute`. Removed: `ChatRepository.keyCeremonyOfRoom`, `KeyCeremonyLink`, `FormedConfederation`, `KeyCeremonyBanner`, the composer gate that hid a finished ceremony room's composer (confederation-profile.md D10), `ConfederationRitualManager.proposalOfRoom`, `DatabaseChatRepository.homeGroupOf`, and four strings: `this_room_runs_a_key_ceremony`, `this_room_waits_for_you_to_join`, `open_the_key_ceremony` and `the_key_ceremony_for_is_complete`. The waiting line reads `ConfederationRepository.observeWaitingToCross`, which reads the ceremony's carries not yet done. `ConfederationCeremonyJvmTest` 28/28, `ConfederationScreensJvmTest` 15/15. Full `jvmTest` 2,035, all passing; `m3Audit` at budget; `compileDebugKotlinAndroid` builds. + ### Phase 7: the ceremony rooms already on devices (report D9) Added to `ConfederationCeremonyInboxMigration.onPostMigrate`, still 54. The column is gone by the time