From 34c8faa497d8bfb19a65be9f92c0dcf91914df05 Mon Sep 17 00:00:00 2001 From: Kgothatso Ngako Date: Sat, 21 Nov 2026 20:47:28 +0200 Subject: [PATCH] fix: the broadcast screen sends only the group's profile and posts (group-nostr-profile, Phase 7) The screen takes a signed event's id as a navigation argument, and this device still holds group-signed events of other kinds: the wallet removal kept every GroupSignedEvent row, a Bennu-era wallet statement among them, whose xpub on a public relay is the group's whole history on chain. Curare's screen refused the wallet's kind; this refuses every kind but 0 and 1, before anything reaches the relays. Co-Authored-By: Claude Opus 5.5 --- .../BroadcastGroupSignedEventViewModel.kt | 17 ++++++++ .../view/model/BroadcastLeavesNoRowJvmTest.kt | 41 +++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/BroadcastGroupSignedEventViewModel.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/BroadcastGroupSignedEventViewModel.kt index 61de7b49..2b02d19a 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/BroadcastGroupSignedEventViewModel.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/BroadcastGroupSignedEventViewModel.kt @@ -1,5 +1,7 @@ package mobi.giza.compose.ui.view.model +import com.vitorpamplona.quartz.nip10Notes.TextNoteEvent +import com.vitorpamplona.quartz.nip01Core.metadata.MetadataEvent import androidx.compose.runtime.MutableState import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateListOf @@ -167,6 +169,18 @@ class BroadcastGroupSignedEventViewModel( "This device doesn't hold that signed event" ) + // Only what the group says publicly: its profile and its posts. The + // id arrives as a navigation argument, and this device still holds + // events of other kinds the group signed -- a Bennu-era wallet's, + // kept by the wallet removal, whose xpub on a public relay would be + // the group's whole history on chain to anyone. Curare's screen + // refused the wallet's kind; this refuses everything that is not + // one of the two. docs/group-nostr-profile-and-posts.md, D7. + signedEvent.kind !in BROADCASTABLE_KINDS -> + BroadcastGroupSignedEventUIState.Error( + "Only the group's profile and its posts are sent from here" + ) + else -> BroadcastGroupSignedEventUIState.Loaded( localChatRoom = localChatRoom, signedEvent = signedEvent, @@ -280,6 +294,9 @@ class BroadcastGroupSignedEventViewModel( */ val BROADCAST_TIMEOUT = (RelayPool.PUBLISH_TIMEOUT * 2).milliseconds + /** The kinds this screen will put on a relay: the group's profile and posts. */ + val BROADCASTABLE_KINDS: Set = setOf(MetadataEvent.KIND, TextNoteEvent.KIND) + /** * Sends [signedEvent] to [targets] and says what each relay answered. * diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/view/model/BroadcastLeavesNoRowJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/view/model/BroadcastLeavesNoRowJvmTest.kt index 6320373b..53798e97 100644 --- a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/view/model/BroadcastLeavesNoRowJvmTest.kt +++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/view/model/BroadcastLeavesNoRowJvmTest.kt @@ -33,6 +33,7 @@ import mobi.giza.compose.network.dto.RelayDTO import mobi.giza.compose.network.relays.EventPublishTransport import mobi.giza.compose.network.relays.NostrPublishResult import mobi.giza.compose.network.sockets.NostrIncomingMessage +import mobi.giza.compose.nostr.RetiredKinds import mobi.giza.compose.ui.view.state.BroadcastGroupSignedEventUIState /** @@ -141,4 +142,44 @@ class BroadcastLeavesNoRowJvmTest { "a queued broadcast", ) } + + /** + * A wallet's statement the group signed in its Bennu days is still on this device + * (the wallet removal kept every `GroupSignedEvent`), and its xpub on a public + * relay would be the group's whole history on chain. The screen names only the + * profile and posts, but the id is a navigation argument. + */ + @Test + fun `a signed event of any other kind is not offered to the relays`(): Unit = runBlocking { + val ownerEventId = "0e".repeat(32) + database.nostrEventDao().upsert( + NostrEvent(id = ownerEventId, pubKey = member, kind = 0, tags = emptyArray(), content = "{}", sig = "0".repeat(128)) + ) + database.profileDao().upsert(Profile(publicKey = member, nostrEventId = ownerEventId)) + database.chatRoomDao().upsert( + ChatRoom(id = chatRoomId, userPublicKey = member, subject = "Translation room", description = null, mlsGroupState = "state") + ) + val statement = profile.copy(id = "5".repeat(64), kind = RetiredKinds.ANNOUNCEMENTS.first(), content = "{}") + database.groupSignedEventDao().record(statement) + + val transport = Transport() + val viewModel = BroadcastGroupSignedEventViewModel( + chatRoomId = chatRoomId, + signedEventId = statement.id, + activeUserPublicKey = member, + relayHint = null, + initialBroadcastGroupSignedEventUIState = BroadcastGroupSignedEventUIState.Loading, + chatRepository = DatabaseChatRepository(database, CoroutineScope(Dispatchers.Default)), + publishTransport = transport, + ) + + viewModel.initiateBroadcastGroupSignedEvent() + val state = withTimeout(5_000) { + while (viewModel.broadcastGroupSignedEventUIState is BroadcastGroupSignedEventUIState.Loading) delay(10) + viewModel.broadcastGroupSignedEventUIState + } + + assertIs(state) + assertNull(transport.sent, "nothing was handed to the relays") + } }