diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/managers/GuardianManager.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/managers/GuardianManager.kt index fdd64988..cc09f6d8 100644 --- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/managers/GuardianManager.kt +++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/managers/GuardianManager.kt @@ -210,6 +210,10 @@ object GuardianManager { * Tells every room in [rooms] about [statement], as [userPublicKey]: one * notice each, queued for the outbound pipeline the way every inner event * is. Returns how many were queued. + * + * Each notice names its room in an `h` tag. Without it, one statement told + * to a grandchild's parent and grandparent in the same second is one id -- + * and one row, the last room's -- so the parent was never told. */ suspend fun share( database: BennuDatabase, @@ -219,9 +223,9 @@ object GuardianManager { createdAt: Long = Clock.System.now().epochSeconds, ): Int { val content = statement.toJson() - val tags = emptyArray>() rooms.forEach { room -> + val tags = arrayOf(arrayOf("h", room.chatRoom.id)) val id = EventHasher.hashId(userPublicKey, createdAt, GuardedWalletNoticeEvent.KIND, tags, content) database.marmotInnerEventDao().upsert( MarmotInnerEvent( diff --git a/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/managers/GuardianSigningJvmTest.kt b/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/managers/GuardianSigningJvmTest.kt index bffa294e..f0a984e3 100644 --- a/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/managers/GuardianSigningJvmTest.kt +++ b/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/managers/GuardianSigningJvmTest.kt @@ -369,6 +369,23 @@ class GuardianSigningJvmTest { assertEquals(listOf(statement.id), GuardianManager.guardedWalletsOf(member.db, roomId).map { it.statement.id }) } + @Test + fun `a grandchild's statement told to its parent and grandparent at once reaches both`(): Unit = runBlocking { + val member = device(members[0], signerIndex = 0) + val grandparentRoomId = "9".repeat(64) + member.db.chatRoomDao().upsert(ChatRoom(id = grandparentRoomId, userPublicKey = member.publicKey, subject = "Assembly", description = null, mlsGroupState = "00")) + val rooms = listOf(roomId, grandparentRoomId).map { assertNotNull(member.db.chatRoomDao().findChatRoomById(it)) } + + // One statement, one sharer, one second: only the room tells the two notices apart. + assertEquals(2, GuardianManager.share(member.db, guardedStatement(), rooms, member.publicKey, createdAt = 1_700_000_100)) + + val told = listOf(roomId, grandparentRoomId).associateWith { room -> + member.db.marmotInnerEventDao().getByChatRoomAndKinds(room, listOf(GuardedWalletNoticeEvent.KIND)).single() + } + told.forEach { (room, notice) -> assertEquals(listOf(listOf("h", room)), notice.tags.map { it.toList() }) } + assertEquals(2, told.values.map { it.id }.toSet().size) + } + // ---- Spending from a guarded wallet ------------------------------------ private val chain = Chain.Regtest