Fix topic diffing from original creation

This commit is contained in:
Cadence Ember
2025-12-16 12:17:34 +13:00
parent e4d0838af5
commit 231b26113e
2 changed files with 37 additions and 21 deletions
+8
View File
@@ -109,6 +109,14 @@ function diffKState(actual, target) {
} else if (key === "m.room.create/") { } else if (key === "m.room.create/") {
// can't be modified - only for kstateToCreationContent // can't be modified - only for kstateToCreationContent
} else if (key === "m.room.topic/") {
// synapse generates different m.room.topic events on original creation
// https://github.com/element-hq/synapse/blob/0f2b29511fd88d1dc2278f41fd6e4e2f2989fcb7/synapse/handlers/room.py#L1729
// diff the `topic` to determine change
if (!(key in actual) || actual[key].topic !== target[key].topic) {
diff[key] = target[key]
}
} else if (key in actual) { } else if (key in actual) {
// diff // diff
if (!isDeepStrictEqual(actual[key], target[key])) { if (!isDeepStrictEqual(actual[key], target[key])) {
+26 -18
View File
@@ -235,30 +235,38 @@ test("diffKState: kstate keys must contain a slash separator", t => {
t.pass() t.pass()
}) })
test("diffKState: don't add hide_ui when not present", t => { test("diffKState: topic does not change if the topic key has not changed", t => {
test("diffKState: detects new properties", t => { t.deepEqual(diffKState({
t.deepEqual( "m.room.topic/": {
diffKState({ topic: "hello",
}, { "m.topic": {
"chat.schildi.hide_ui/read_receipts/": {} "m.text": "hello"
}),
{
} }
) }
}) }, {
"m.room.topic/": {
topic: "hello"
}
}),
{})
}) })
test("diffKState: overwriten hide_ui when present", t => { test("diffKState: topic changes if the topic key has changed", t => {
test("diffKState: detects new properties", t => { t.deepEqual(diffKState({
t.deepEqual( "m.room.topic/": {
diffKState({ topic: "hello",
"chat.schildi.hide_ui/read_receipts/": {hidden: true} "m.topic": {
"m.text": "hello"
}
}
}, { }, {
"chat.schildi.hide_ui/read_receipts/": {} "m.room.topic/": {
topic: "hello you"
}
}), }),
{ {
"chat.schildi.hide_ui/read_receipts/": {} "m.room.topic/": {
topic: "hello you"
} }
)
}) })
}) })