diff --git a/spec/unit/relations.spec.ts b/spec/unit/relations.spec.ts index 1b479ebbef8..2472bd8f688 100644 --- a/spec/unit/relations.spec.ts +++ b/spec/unit/relations.spec.ts @@ -130,4 +130,49 @@ describe("Relations", function() { await relationsCreated; } }); + + it("should ignore m.replace for state events", async () => { + const userId = "@bob:example.com"; + const room = new Room("room123", null, userId); + const relations = new Relations("m.replace", "m.room.topic", room); + + // Create an instance of a state event with rel_type m.replace + const originalTopic = new MatrixEvent({ + "sender": userId, + "type": "m.room.topic", + "event_id": "$orig", + "room_id": room.roomId, + "content": { + "topic": "orig", + }, + "state_key": "", + }); + const badlyEditedTopic = new MatrixEvent({ + "sender": userId, + "type": "m.room.topic", + "event_id": "$orig", + "room_id": room.roomId, + "content": { + "topic": "topic", + "m.new_content": { + "topic": "edit", + }, + "m.relates_to": { + "event_id": "$orig", + "rel_type": "m.replace", + }, + }, + "state_key": "", + }); + + await relations.setTargetEvent(originalTopic); + expect(originalTopic.replacingEvent()).toBe(null); + expect(originalTopic.getContent().topic).toBe("orig"); + + await relations.addEvent(badlyEditedTopic); + expect(originalTopic.replacingEvent()).toBe(null); + expect(originalTopic.getContent().topic).toBe("orig"); + expect(badlyEditedTopic.replacingEvent()).toBe(null); + expect(badlyEditedTopic.getContent().topic).toBe("topic"); + }); }); diff --git a/src/models/event.ts b/src/models/event.ts index f28176b94f0..e65aa7b053c 100644 --- a/src/models/event.ts +++ b/src/models/event.ts @@ -1336,6 +1336,10 @@ export class MatrixEvent extends TypedEventEmitter