You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-25 05:23:13 +03:00
Ignore m.replace relations on state events, they're invalid (#2306)
* Ignore m.replace relations on state events, they're invalid * Add tests * Fix test Co-authored-by: Kerry <kerrya@element.io>
This commit is contained in:
committed by
GitHub
parent
ac08e52410
commit
ba06e430c4
@@ -130,4 +130,49 @@ describe("Relations", function() {
|
|||||||
await relationsCreated;
|
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");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1336,6 +1336,10 @@ export class MatrixEvent extends TypedEventEmitter<EmittedEvents, MatrixEventHan
|
|||||||
if (this.isRedacted() && newEvent) {
|
if (this.isRedacted() && newEvent) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// don't allow state events to be replaced using this mechanism as per MSC2676
|
||||||
|
if (this.isState()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (this._replacingEvent !== newEvent) {
|
if (this._replacingEvent !== newEvent) {
|
||||||
this._replacingEvent = newEvent;
|
this._replacingEvent = newEvent;
|
||||||
this.emit(MatrixEventEvent.Replaced, this);
|
this.emit(MatrixEventEvent.Replaced, this);
|
||||||
|
|||||||
Reference in New Issue
Block a user