feat: a subgroup certified as #name is shown as &name (group-name-prefix, Phase 4)

The parent's subgroup list and the TYPE_SUBGROUP_CERTIFIED line read the
certificate's name through MarmotGroupName.of, so a certificate signed before
the change matches the room it names. The proposal summary stays verbatim:
it shows what the signer is about to approve.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kgothatso NgakoandClaude Opus 5.5 committed 2026-11-23 02:09:21 +02:00
1 parent 3f54640227
commit 342127bc20
5 files changed
+90 -5

No files matched your search

@@ -40,6 +40,7 @@ import mobi.giza.compose.extensions.toHex
import mobi.giza.compose.managers.ChronicleManager
import mobi.giza.compose.managers.GroupKeyStateManager
import mobi.giza.compose.managers.SubgroupManager
import mobi.giza.compose.managers.MarmotGroupName
import mobi.giza.compose.nostr.MarmotDirectMessage
import mobi.giza.compose.nostr.chronicle.ChronicleEvent
import mobi.giza.compose.nostr.chronicle.ChronicleRequestEvent
@@ -1416,7 +1417,9 @@ data class ChatMessage(
// The name is the one the parent certified, which is the only one
// that was ever put to this room -- the child may since have been
// renamed, and this line is a record of what was agreed rather
// than a view of what is.
// than a view of what is. It is written under today's mark,
// though: a certificate signed as `#name` before
// docs/group-name-prefix.md certified the name, not the `#`.
SubgroupBirthCertificateEvent.KIND -> {
SubgroupManager.record(
database = database,
@@ -1424,7 +1427,7 @@ data class ChatMessage(
innerEvent = event
) ?: return null
val name = SubgroupBirthCertificateEvent.parseName(event.tags)
val name = SubgroupBirthCertificateEvent.parseName(event.tags)?.let(MarmotGroupName::of)
val admins = SubgroupBirthCertificateEvent.parseAdminPublicKeys(event.tags).size
ChatMessage(
@@ -444,7 +444,11 @@ object SubgroupManager {
chatRoomId = chatRoomId,
parentChatRoomId = parentChatRoomId,
certificate = signed,
name = SubgroupBirthCertificateEvent.parseName(event.tags),
// Under today's mark: a certificate signed before
// docs/group-name-prefix.md says `#name`, and the room it
// names is `&name` on this device. What was agreed is the
// name, not the punctuation.
name = SubgroupBirthCertificateEvent.parseName(event.tags)?.let(MarmotGroupName::of),
adminPublicKeys = SubgroupBirthCertificateEvent.parseAdminPublicKeys(event.tags),
room = database.chatRoomDao().findChatRoomById(chatRoomId),
keyState = database.groupKeyStateDao().getByChatRoomId(chatRoomId),
@@ -69,6 +69,11 @@ object ProposedEvent {
SubgroupBirthCertificateEvent.KIND -> Summary(
label = "A new subgroup of this group",
detail = listOfNotNull(
// Verbatim, not through `MarmotGroupName.of`: this is what the
// signer is about to approve, and a certificate proposed before
// docs/group-name-prefix.md says `#name`. The summary of a
// signature shows the bytes being signed, even where the rest
// of the app would show the name under today's mark (D5).
SubgroupBirthCertificateEvent.parseName(event.tags),
SubgroupBirthCertificateEvent.parseAdminPublicKeys(event.tags)
.size
@@ -31,6 +31,11 @@ class ProposedEventTest {
assertEquals("An article", summary.detail)
}
/**
* `#Translation` on purpose: a certificate proposed before docs/group-name-prefix.md. The
* summary is of what the signer approves, so it shows the name as signed, `#` and all,
* where the rest of the app would show `&Translation` (D5).
*/
@Test
fun `a birth certificate says who and what, and nothing of a wallet`() {
val parent = "1".repeat(64)
@@ -2,10 +2,12 @@ package mobi.giza.compose.managers
import androidx.room3.Room
import com.vitorpamplona.crypto.curve25519.Ed25519
import com.vitorpamplona.marmot.GroupEventResult
import com.vitorpamplona.marmot.groups.MarmotGroupPolicy
import com.vitorpamplona.marmot.groups.currentMarmotData
import com.vitorpamplona.marmot.mip01Groups.MarmotGroupData
import com.vitorpamplona.mls.group.MlsGroup
import com.vitorpamplona.quartz.marmot.mip03GroupMessages.GroupEvent
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.core.hexToByteArray
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
@@ -31,11 +33,13 @@ import kotlin.time.Instant
import kotlinx.coroutines.runBlocking
import mobi.giza.compose.database.GizaDatabase
import mobi.giza.compose.database.builder.getRoomDatabase
import mobi.giza.compose.database.model.ChatMessage
import mobi.giza.compose.database.model.ChatRoom
import mobi.giza.compose.database.model.DkgParticipantMessage
import mobi.giza.compose.database.model.DkgSession
import mobi.giza.compose.database.model.GroupKeyState
import mobi.giza.compose.database.model.GroupSignedEvent
import mobi.giza.compose.database.model.MarmotGroupEvent
import mobi.giza.compose.database.model.NostrEvent
import mobi.giza.compose.database.model.Participant
import mobi.giza.compose.database.model.Profile
@@ -122,7 +126,7 @@ class SubgroupManagerJvmTest {
assertEquals(childRoomId, subgroup.chatRoomId)
assertEquals(parentRoomId, subgroup.parentChatRoomId)
assertEquals("Translation team", subgroup.name)
assertEquals("&Translation team", subgroup.name)
assertEquals(listOf(user, alice, bob), subgroup.adminPublicKeys)
// The whole point of reading certificates rather than rooms: this device
@@ -133,6 +137,70 @@ class SubgroupManagerJvmTest {
assertNull(subgroup.keyState)
}
/**
* A certificate signed before docs/group-name-prefix.md says `#name`, and can never say
* anything else. Where the app says what the subgroup is called -- the parent's list and
* the line in its room -- that is the room's name under today's mark. `#` on purpose.
*/
@Test
fun `a certificate signed under the old mark is listed and announced under the new one`(): Unit = runBlocking {
seedRoom(parentRoomId)
val signed = certificate(name = "#Translation team")
record(signed)
assertEquals("&Translation team", SubgroupManager.subgroupsOf(db, parentRoomId).single().name)
// The kind:445 it arrived in, stored as sync stores one, so the inner event the line
// is written from has a group event to hang off.
val groupEventId = "ab".repeat(32)
db.nostrEventDao().upsert(
NostrEvent(
id = groupEventId,
pubKey = alice,
kind = GroupEvent.KIND,
tags = arrayOf(arrayOf("h", parentRoomId)),
content = "ciphertext",
sig = "0".repeat(128),
)
)
db.marmotGroupEventDao().upsert(
MarmotGroupEvent(
id = groupEventId,
userPublicKey = user,
publicKey = alice,
chatRoomId = parentRoomId,
signature = "0".repeat(128),
encryptedContent = "ciphertext",
expiresAt = null,
createdAt = Instant.fromEpochSeconds(signed.createdAt),
)
)
val line = assertNotNull(
ChatMessage.fromGroupEventResult(
database = db,
activeKeyPair = KeyPair(),
groupEvent = GroupEvent(
id = groupEventId,
pubKey = alice,
createdAt = signed.createdAt,
tags = arrayOf(arrayOf("h", parentRoomId)),
content = "ciphertext",
sig = "0".repeat(128),
),
groupEventResult = GroupEventResult.ApplicationMessage(
groupId = parentRoomId,
innerEventJson = signed.toJson(),
senderLeafIndex = 1,
epoch = 1,
),
senderIdentity = alice,
)
)
assertEquals(ChatMessage.TYPE_SUBGROUP_CERTIFIED, line.messageType)
assertEquals("The group made &Translation team a subgroup, run by 3 of its members", line.content)
}
@Test
fun `a child whose room this device holds reports it`(): Unit = runBlocking {
seedRoom(parentRoomId)
@@ -200,7 +268,7 @@ class SubgroupManagerJvmTest {
val subgroups = SubgroupManager.subgroupsOf(db, parentRoomId)
assertEquals(1, subgroups.size)
assertEquals("Second name", subgroups.single().name)
assertEquals("&Second name", subgroups.single().name)
assertEquals(
"Second name",
SubgroupBirthCertificateEvent.parseName(