diff --git a/src/matrix/kstate.js b/src/matrix/kstate.js index d131889..b0fe947 100644 --- a/src/matrix/kstate.js +++ b/src/matrix/kstate.js @@ -109,6 +109,14 @@ function diffKState(actual, target) { } else if (key === "m.room.create/") { // 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) { // diff if (!isDeepStrictEqual(actual[key], target[key])) { diff --git a/src/matrix/kstate.test.js b/src/matrix/kstate.test.js index 1b67ad5..ff65e9c 100644 --- a/src/matrix/kstate.test.js +++ b/src/matrix/kstate.test.js @@ -235,30 +235,38 @@ test("diffKState: kstate keys must contain a slash separator", t => { t.pass() }) -test("diffKState: don't add hide_ui when not present", t => { - test("diffKState: detects new properties", t => { - t.deepEqual( - diffKState({ - }, { - "chat.schildi.hide_ui/read_receipts/": {} - }), - { +test("diffKState: topic does not change if the topic key has not changed", t => { + t.deepEqual(diffKState({ + "m.room.topic/": { + topic: "hello", + "m.topic": { + "m.text": "hello" } - ) - }) + } + }, { + "m.room.topic/": { + topic: "hello" + } + }), + {}) }) -test("diffKState: overwriten hide_ui when present", t => { - test("diffKState: detects new properties", t => { - t.deepEqual( - diffKState({ - "chat.schildi.hide_ui/read_receipts/": {hidden: true} - }, { - "chat.schildi.hide_ui/read_receipts/": {} - }), - { - "chat.schildi.hide_ui/read_receipts/": {} +test("diffKState: topic changes if the topic key has changed", t => { + t.deepEqual(diffKState({ + "m.room.topic/": { + topic: "hello", + "m.topic": { + "m.text": "hello" } - ) + } + }, { + "m.room.topic/": { + topic: "hello you" + } + }), + { + "m.room.topic/": { + topic: "hello you" + } }) })