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 <noreply@anthropic.com>
This commit is contained in:
Kgothatso NgakoandClaude Opus 5.5 committed 2026-11-21 20:47:28 +02:00
1 parent aa820c20cc
commit 34c8faa497
2 files changed
+58

No files matched your search

@@ -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<Kind> = setOf(MetadataEvent.KIND, TextNoteEvent.KIND)
/**
* Sends [signedEvent] to [targets] and says what each relay answered.
*
@@ -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<BroadcastGroupSignedEventUIState.Error>(state)
assertNull(transport.sent, "nothing was handed to the relays")
}
}