From 6285033c8c53b03842f5dcb7589a74ddd01ec256 Mon Sep 17 00:00:00 2001 From: Kgothatso Ngako Date: Sun, 22 Nov 2026 23:58:12 +0200 Subject: [PATCH] feat: the confederation's room and its key ceremony's room say what they are (confederation-profile, Phase 7) The confederation's own room names its groups, each with the people who hold its roles, labels each member with the groups they hold roles for, says that admins who joined later are not in it, and opens the confederation's screen from a member group this device is in. The key ceremony's NIP-17 room, once the ceremony has made the confederation, says so and leads to the confederation, and its composer is hidden: anything typed there would reach the founding people as people. Co-Authored-By: Claude Opus 5.5 --- .../composeResources/values/strings.xml | 4 + .../repository/DatabaseChatRepository.kt | 31 +- .../giza/compose/repository/ChatRepository.kt | 3 + .../ui/composable/ChatRoomDetailScreen.kt | 30 ++ .../ui/composable/ChatRoomMessagingScreen.kt | 302 +++++++++--------- .../ui/view/model/ChatRoomDetailViewModel.kt | 1 + .../ui/view/state/ChatRoomDetailUIState.kt | 15 + .../ui/view/state/ChatRoomMessagingUIState.kt | 8 + .../managers/ConfederationSigningJvmTest.kt | 27 ++ docs/confederation-profile.md | 12 + 10 files changed, 289 insertions(+), 144 deletions(-) diff --git a/composeApp/src/commonMain/composeResources/values/strings.xml b/composeApp/src/commonMain/composeResources/values/strings.xml index 8935984b..383f0264 100644 --- a/composeApp/src/commonMain/composeResources/values/strings.xml +++ b/composeApp/src/commonMain/composeResources/values/strings.xml @@ -803,6 +803,10 @@ 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. Inbox Inbox settings 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 81677bac..85b11421 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 @@ -374,7 +374,36 @@ class DatabaseChatRepository( 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 - return mobi.giza.compose.ui.view.state.KeyCeremonyLink(proposalId = proposalId, joined = joined) + 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 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? = 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 f9420fe0..505ca564 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/repository/ChatRepository.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/repository/ChatRepository.kt @@ -161,6 +161,9 @@ 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. 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 18fdaf63..cbda1c1f 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 @@ -36,6 +36,9 @@ 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 @@ -805,6 +808,30 @@ fun ChatRoomDetailScreen( 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( @@ -1436,6 +1463,9 @@ 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/ChatRoomMessagingScreen.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ChatRoomMessagingScreen.kt index 5aca100b..72d9f3c2 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 @@ -57,6 +57,8 @@ 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 @@ -196,8 +198,16 @@ fun ChatRoomMessagingScreen( 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( - ConfederationRitualRoute(activeUserPublicKey = activeUserPublicKey, proposalId = link.proposalId) + if (formed != null && home != null) { + ConfederationRoute(activeUserPublicKey = activeUserPublicKey, chatRoomId = home, confederationId = formed.confederationId) + } else { + ConfederationRitualRoute(activeUserPublicKey = activeUserPublicKey, proposalId = link.proposalId) + } ) }, ) @@ -274,163 +284,168 @@ 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. - 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 + // 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 - 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() } + 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.Close, - contentDescription = "Send to the whole group instead", + 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.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)) + 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 { - stringResource(Res.string.say_what_now) + Color.Transparent + }, + unfocusedContainerColor = if (directMessageRecipient != null) { + MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.3f) + } else { + Color.Transparent } - ) - }, - trailingIcon = { - if (textFieldState.text.isEmpty()) { - IconButton( - onClick = { - + ), + placeholder = { + Text( + text = if (directMessageRecipient != null) { + stringResource(Res.string.private_message_to, chatMessageListViewModel.nameFor(directMessageRecipient.participantPublicKey)) + } else { + stringResource(Res.string.say_what_now) } - ) { - Icon( - Icons.Default.Mic, - contentDescription = "Voice" - ) - } + ) + }, + trailingIcon = { + if (textFieldState.text.isEmpty()) { + IconButton( + onClick = { - } else { - IconButton( - onClick = { - chatMessageListViewModel.sendMessage( - textFieldState = textFieldState + } + ) { + Icon( + Icons.Default.Mic, + contentDescription = "Voice" + ) + } + + } else { + IconButton( + onClick = { + chatMessageListViewModel.sendMessage( + textFieldState = textFieldState + ) + } + ) { + Icon( + Icons.AutoMirrored.Filled.Send, + contentDescription = "Send" ) } - ) { - 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" + // ) + // } + // } + } } } } @@ -560,11 +575,12 @@ private fun KeyCeremonyBanner(link: KeyCeremonyLink, onOpen: () -> Unit) { Icon(Icons.Default.Key, contentDescription = Decorative) Text( modifier = Modifier.weight(1f).padding(vertical = MaterialTheme.spacing.compactPadding), - text = stringResource(if (link.joined) Res.string.this_room_runs_a_key_ceremony else Res.string.this_room_waits_for_you_to_join), + 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(Res.string.open_the_key_ceremony)) + 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/view/model/ChatRoomDetailViewModel.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/ChatRoomDetailViewModel.kt index be1b2433..5e95b9b6 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 @@ -135,6 +135,7 @@ class ChatRoomDetailViewModel( 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" } } 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 97631c9d..64f672f7 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 @@ -76,6 +76,9 @@ 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(), @@ -190,3 +193,15 @@ sealed interface 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/ChatRoomMessagingUIState.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/ChatRoomMessagingUIState.kt index 3caf0000..b4866e0c 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 @@ -26,4 +26,12 @@ 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/jvmTest/kotlin/mobi/giza/compose/managers/ConfederationSigningJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/ConfederationSigningJvmTest.kt index 86654e4c..c5df5012 100644 --- a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/ConfederationSigningJvmTest.kt +++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/ConfederationSigningJvmTest.kt @@ -333,6 +333,33 @@ class ConfederationSigningJvmTest { assertFailsWith { propose(kind = TextNoteEvent.KIND, content = " ") } } + // ---- 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)) + + 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 `once formed, the key ceremony's room leads to the confederation`() = runBlocking { + val device = devices.getValue(npub(secret(11))) + val repository = mobi.giza.compose.database.repository.DatabaseChatRepository(device.db, kotlinx.coroutines.CoroutineScope(kotlinx.coroutines.Dispatchers.Unconfined)) + val link = assertNotNull(repository.keyCeremonyOfRoom(device.ceremonyDevice.room.chatRoom.id)) + val formed = assertNotNull(link.formed, "the ceremony made the confederation") + assertEquals(confederation.id, formed.confederationId) + assertEquals("Atlas", formed.name) + } + // ---- Phase 15: the charter ------------------------------------------------------------ @Test diff --git a/docs/confederation-profile.md b/docs/confederation-profile.md index 058e7252..9edb1b7a 100644 --- a/docs/confederation-profile.md +++ b/docs/confederation-profile.md @@ -631,6 +631,18 @@ above: Tests: `ConfederationScreensJvmTest` gains the labelled members and a person in two groups shown once. The messaging screen's test covers a formed ceremony room with no composer. +**Built.** `ConfederationSigningJvmTest` gains two cases (15): on a Polis admin's device the +confederation's room names its three groups, each with its three role holders, names the person's own +group beside them, and opens the confederation's screen from Polis's room; and once formed, the key +ceremony's room leads to the confederation it made. Audits at budget. Where it differs from the above: + +| what the phase said | what it turned out to be | +|---|---| +| a **Groups** card above the members | the groups go into the confederation's card the room already had ("This is the room of the confederation Atlas…"), one line a group with its role holders, then the sentence about later admins and **Open the confederation**. One card about whose room it is, rather than two | +| each member labelled with their groups | beside "Admin" and "Share" on the member's row, as one more label | +| the ceremony's room moves below active conversations | **not done.** The chat list sorts every room by its last message, and an ended ceremony's room stops getting messages, so it sinks on its own; a special order for one kind of room was more than this needed. The banner and the hidden composer are built | +| tested through the screens | through `DatabaseChatRepository.confederationRoomInfo` and `keyCeremonyOfRoom` on the nine-device harness, which is where the facts come from; the screens only lay them out | + ### Phase 8: the network run `ConfederationProfileNetworkJvmTest`, the plan end to end on `ConfederationNetworkJvmTest`'s