diff --git a/composeApp/src/commonMain/kotlin/to/curare/compose/database/model/ChatMessage.kt b/composeApp/src/commonMain/kotlin/to/curare/compose/database/model/ChatMessage.kt index 2f26d063..558cfc3f 100644 --- a/composeApp/src/commonMain/kotlin/to/curare/compose/database/model/ChatMessage.kt +++ b/composeApp/src/commonMain/kotlin/to/curare/compose/database/model/ChatMessage.kt @@ -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() } } diff --git a/composeApp/src/jvmTest/kotlin/to/curare/compose/database/model/MarmotSystemRowJvmTest.kt b/composeApp/src/jvmTest/kotlin/to/curare/compose/database/model/MarmotSystemRowJvmTest.kt new file mode 100644 index 00000000..e1049ac9 --- /dev/null +++ b/composeApp/src/jvmTest/kotlin/to/curare/compose/database/model/MarmotSystemRowJvmTest.kt @@ -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()) + + @AfterTest + fun closeDb() = db.close() + + private val member = KeyPair() + + private fun inner(kind: Int, content: String): Event = + NostrSignerSync(member).sign(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) + } +}