diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/managers/SubgroupManager.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/managers/SubgroupManager.kt index efc43853..0683905c 100644 --- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/managers/SubgroupManager.kt +++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/managers/SubgroupManager.kt @@ -547,6 +547,14 @@ object SubgroupManager { val keyState: GroupKeyState?, ) { /** Whether this device can open the subgroup, rather than only know of it. */ + /** + * What the parent decided about the subgroup's wallet when it certified + * it -- `docs/subgroup-wallet-policy.md`. Founding history like [name]: + * decided once, and never changed by anything after. + */ + val walletPolicy: WalletPolicyReading? + get() = SubgroupBirthCertificateEvent.parseWalletPolicy(certificate.tags) + val isJoined: Boolean get() = room != null } diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/ChatRoomDetailScreen.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/ChatRoomDetailScreen.kt index b01ee84b..ab551a42 100644 --- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/ChatRoomDetailScreen.kt +++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/ChatRoomDetailScreen.kt @@ -1,5 +1,9 @@ package com.machankura.bennu.compose.ui.composable +import bennu.composeapp.generated.resources.unguarded_wallet +import bennu.composeapp.generated.resources.guarded_wallet +import com.machankura.bennu.compose.nostr.subgroup.WalletPolicyReading +import com.machankura.bennu.compose.nostr.subgroup.SubgroupWalletPolicy import com.machankura.bennu.compose.wallet.GroupWalletRollout import com.machankura.bennu.compose.ui.composable.navigation.routes.GroupWalletRoute import com.machankura.bennu.compose.nostr.wallet.GroupWalletStatementEvent @@ -315,14 +319,21 @@ fun ChatRoomDetailScreen( Text(text = stringResource(Res.string.parent_group)) }, supportingContent = { - Text( - text = parentChatRoomId - .take(16) - .inComparableGroups(), - fontFamily = FontFamily.Monospace, - maxLines = 1, - overflow = TextOverflow.MiddleEllipsis - ) + Column { + Text( + text = parentChatRoomId + .take(16) + .inComparableGroups(), + fontFamily = FontFamily.Monospace, + maxLines = 1, + overflow = TextOverflow.MiddleEllipsis + ) + // What the parent decided about + // this room's wallet at its birth. + // Nothing for one that decided + // nothing, as before policies. + walletPolicyLabel(chatRoomDetailUIState.walletPolicy)?.let { Text(it) } + } } ) } @@ -1215,24 +1226,40 @@ private fun SubgroupCard( ) }, supportingContent = { - Text( - text = when { - subgroup.isJoined -> stringResource( - Res.string.run_by_members, - subgroup.adminPublicKeys.size.toString() - ) - // The room does not exist anywhere yet: the parent has - // certified it and nobody has created it. Between steps 2 - // and 4 of docs/subgroups.md this is every member's view. - subgroup.keyState == null -> stringResource(Res.string.certified_not_yet_created) - else -> stringResource(Res.string.created_you_are_not_a_member) - } - ) + Column { + Text( + text = when { + subgroup.isJoined -> stringResource( + Res.string.run_by_members, + subgroup.adminPublicKeys.size.toString() + ) + // The room does not exist anywhere yet: the parent has + // certified it and nobody has created it. Between steps 2 + // and 4 of docs/subgroups.md this is every member's view. + subgroup.keyState == null -> stringResource(Res.string.certified_not_yet_created) + else -> stringResource(Res.string.created_you_are_not_a_member) + } + ) + // What the parent decided about its wallet, from the certificate: + // founding history, like the name the row falls back to. + walletPolicyLabel(subgroup.walletPolicy)?.let { Text(it) } + } } ) } } +/** + * *Guarded wallet* or *Unguarded wallet* for a policy a parent decided, and + * null for one it left to the subgroup -- `docs/subgroup-wallet-policy.md`. + */ +@Composable +private fun walletPolicyLabel(policy: WalletPolicyReading?): String? = when (policy) { + WalletPolicyReading.Decided(SubgroupWalletPolicy.GUARDED) -> stringResource(Res.string.guarded_wallet) + WalletPolicyReading.Decided(SubgroupWalletPolicy.UNGUARDED) -> stringResource(Res.string.unguarded_wallet) + else -> null +} + /** One labelled value of a key state, whole and comparable. */ @Composable private fun GroupKeyStateField( diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/ChatRoomDetailViewModel.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/ChatRoomDetailViewModel.kt index ac4802d0..cd42521c 100644 --- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/ChatRoomDetailViewModel.kt +++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/ChatRoomDetailViewModel.kt @@ -92,6 +92,7 @@ class ChatRoomDetailViewModel( signedGroupKeyStateEvent = chatRepository.signedGroupKeyStateEvent(chatRoomId), subgroups = chatRepository.subgroupsOf(chatRoomId), parentChatRoomId = chatRepository.parentOf(chatRoomId), + walletPolicy = chatRepository.walletPolicyOf(chatRoomId), groupNostrProfile = chatRepository.groupNostrProfile(chatRoomId), groupRelayLists = chatRepository.groupRelayLists(chatRoomId), groupPosts = chatRepository.groupPosts(chatRoomId), diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/ChatRoomDetailUIState.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/ChatRoomDetailUIState.kt index 60729548..5bcc371d 100755 --- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/ChatRoomDetailUIState.kt +++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/ChatRoomDetailUIState.kt @@ -1,5 +1,6 @@ package com.machankura.bennu.compose.ui.view.state +import com.machankura.bennu.compose.nostr.subgroup.WalletPolicyReading import com.machankura.bennu.compose.nostr.wallet.GroupWallet import com.vitorpamplona.quartz.nip01Core.core.HexKey import com.machankura.bennu.compose.database.model.GroupKeyState @@ -50,6 +51,12 @@ sealed interface ChatRoomDetailUIState { * really is a subgroup. */ val parentChatRoomId: HexKey? = null, + /** + * What [parentChatRoomId] decided about this room's wallet at its birth, + * or null for a room with no certificate. Shown on the parent row, + * because it is a fact about where the room came from. + */ + val walletPolicy: WalletPolicyReading? = null, /** * The kind:0 the group signed about itself, or null while it has signed * none. diff --git a/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/managers/SubgroupManagerJvmTest.kt b/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/managers/SubgroupManagerJvmTest.kt index 5c8397b3..e267a70c 100644 --- a/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/managers/SubgroupManagerJvmTest.kt +++ b/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/managers/SubgroupManagerJvmTest.kt @@ -137,6 +137,30 @@ class SubgroupManagerJvmTest { assertNull(subgroup.keyState) } + @Test + fun `a listed child carries what its parent decided about its wallet`(): Unit = runBlocking { + seedRoom(parentRoomId) + record( + certificate( + tags = SubgroupBirthCertificateEvent.assembleTags( + subgroupChatRoomId = childRoomId, + parentChatRoomId = parentRoomId, + thresholdPublicKey = childMaterial.thresholdPublicKey.value.toHex(), + adminPublicKeys = listOf(user, alice, bob), + name = "Translation team", + path = path, + walletPolicy = SubgroupWalletPolicy.UNGUARDED, + ) + ) + ) + record(certificate(subgroupMaterial = siblingMaterial)) + + val subgroups = SubgroupManager.subgroupsOf(db, parentRoomId).associateBy { it.chatRoomId } + + assertEquals(WalletPolicyReading.Decided(SubgroupWalletPolicy.UNGUARDED), subgroups.getValue(childRoomId).walletPolicy) + assertEquals(WalletPolicyReading.Undecided, subgroups.getValue(siblingRoomId).walletPolicy, "a certificate from before policies") + } + @Test fun `a child whose room this device holds reports it`(): Unit = runBlocking { seedRoom(parentRoomId)