fix(marmot): a received kind:1210 or kind:1009 is not a bubble
docs/marmot-v2.md, Phase 7, the line the phase's commit missed: "a received kind:1210 or kind:1009 gets no bubble". Both are kinds the current profile defines as not-chat. A 1210 is a group system row -- member added, member left -- and the profile is explicit that one arriving over the wire is one member's assertion rather than a fact; this device derives its own from the commit it applied (`TYPE_MEMBER_ADDED` and its siblings, written by `processGroupMembershipChanges`), so the received one adds nothing it can trust. A 1009 is an in-place edit, which the app does not apply. Until now either fell off the end of `applyInnerEvent`'s `when` into `unsupported()`, which is the raw-JSON bubble, so a White Noise member leaving a room would have put their client's system row into the transcript as a block of JSON under the caption this device wrote for the same fact. Both kinds now return null: no line. The bubble stays for every other unknown kind, which is narrower than the plan's "neither does any other unknown kind". Two reasons. The `TextNoteEvent` arm reaches `unsupported()` deliberately -- a kind:1 the room did not sign is a member's own note travelling through the room and has always rendered as this -- and the bubble is the only trace an unrecognised payload leaves; retiring it would make the next new kind a silent drop, which is the failure mode the chronicle note complains about from the other side. The Phase 9 table records the narrowing. `MarmotSystemRowJvmTest` holds both: the two kinds make no row, and kind 31337 is still the bubble. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
daac3962fa
commit
437fd3e18b
2 files changed
+68
No files matched your search
@@ -16,6 +16,7 @@ import to.curare.compose.managers.GroupKeyStateManager
|
||||
import to.curare.compose.managers.SubgroupManager
|
||||
import to.curare.compose.extensions.toHex
|
||||
import com.vitorpamplona.quartz.marmot.GroupEventResult
|
||||
import com.vitorpamplona.quartz.marmot.foundation.appEvents.MarmotAppEvent
|
||||
import com.vitorpamplona.quartz.marmot.mip03GroupMessages.GroupEvent
|
||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
@@ -1695,6 +1696,15 @@ data class ChatMessage(
|
||||
)
|
||||
}
|
||||
|
||||
// v2's two non-chat kinds. A kind:1210 that arrives is one member's
|
||||
// assertion about what the group's state became, and this device
|
||||
// derives that for itself from the commit it applied (see
|
||||
// [TYPE_MEMBER_ADDED]); a kind:1009 is an edit the app does not
|
||||
// apply. Neither is a line, and neither is a raw-JSON bubble from
|
||||
// a White Noise member. Every other unknown kind keeps the bubble,
|
||||
// which is the only trace an unrecognised payload leaves.
|
||||
MarmotAppEvent.KIND_SYSTEM, MarmotAppEvent.KIND_EDIT -> null
|
||||
|
||||
else -> unsupported()
|
||||
}
|
||||
}
|
||||
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
package to.curare.compose.database.model
|
||||
|
||||
import androidx.room3.Room
|
||||
import com.vitorpamplona.quartz.marmot.foundation.appEvents.MarmotAppEvent
|
||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||
import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerSync
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import to.curare.compose.database.CurareDatabase
|
||||
import to.curare.compose.database.builder.getRoomDatabase
|
||||
import kotlin.test.AfterTest
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertNull
|
||||
import kotlin.time.Instant
|
||||
|
||||
/**
|
||||
* A kind:1210 or kind:1009 from another client is not a line. docs/marmot-v2.md,
|
||||
* Phase 7: the system row is derived from the state this device holds, never
|
||||
* received, and an edit is not applied; an unknown kind of any other number is
|
||||
* still the raw-JSON bubble it always was, because that bubble is the only trace
|
||||
* an unrecognised payload leaves.
|
||||
*/
|
||||
class MarmotSystemRowJvmTest {
|
||||
|
||||
private val db: CurareDatabase = getRoomDatabase(Room.inMemoryDatabaseBuilder<CurareDatabase>())
|
||||
|
||||
@AfterTest
|
||||
fun closeDb() = db.close()
|
||||
|
||||
private val member = KeyPair()
|
||||
|
||||
private fun inner(kind: Int, content: String): Event =
|
||||
NostrSignerSync(member).sign<Event>(createdAt = 1_700_000_000L, kind = kind, tags = emptyArray(), content = content)
|
||||
|
||||
private suspend fun apply(event: Event) = ChatMessage.applyInnerEvent(
|
||||
database = db,
|
||||
groupId = "room",
|
||||
event = event,
|
||||
marmotGroupEventId = null,
|
||||
marmotInnerEventId = event.id,
|
||||
senderPublicKey = event.pubKey,
|
||||
isUserMessage = false,
|
||||
createdAt = Instant.fromEpochSeconds(event.createdAt),
|
||||
)
|
||||
|
||||
@Test
|
||||
fun `a received system row and a received edit make no line`() = runBlocking {
|
||||
assertNull(apply(inner(MarmotAppEvent.KIND_SYSTEM, """{"type":"member_added","account":"abcd"}""")))
|
||||
assertNull(apply(inner(MarmotAppEvent.KIND_EDIT, "the corrected text")))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `any other unknown kind is still the bubble`() = runBlocking {
|
||||
val row = apply(inner(31337, "whatever this is"))
|
||||
assertEquals("unsupported", row?.messageType)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user