feat(subgroup): the detail screens show what a parent decided about a wallet (Phase 8)
SubgroupManager.Subgroup.walletPolicy reads it off the certificate, and each row of a parent's subgroup list says guarded or unguarded wallet under its supporting line. A subgroup's own parent row says the same, off ChatRoomDetailUIState.walletPolicy. Founding history, shown as such; an undecided certificate says nothing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1069059174
commit
6bd47210f9
5 files changed
+88
-21
No files matched your search
+8
@@ -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
|
||||
}
|
||||
|
||||
|
||||
+48
-21
@@ -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(
|
||||
|
||||
+1
@@ -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),
|
||||
|
||||
+7
@@ -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.
|
||||
|
||||
+24
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user