1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-28 05:03:59 +03:00

handle m.replace relations in room, emit Room.replaceEvent

This commit is contained in:
Bruno Windels
2019-05-14 15:24:36 +01:00
parent 18cd017f58
commit 25e6b1cac8
2 changed files with 22 additions and 0 deletions

View File

@@ -1028,6 +1028,27 @@ Room.prototype._addLiveEvent = function(event, duplicateStrategy) {
// this may be needed to trigger an update.
}
if (event.isReplacement()) {
const replacedEventId = event.getOriginalId();
const replacedEvent = replacedEventId &&
this.getUnfilteredTimelineSet().tryReplaceEvent(replacedEventId, event);
if (replacedEvent) {
// if this was already a replacement, get the original
let originalEvent = replacedEvent;
if (originalEvent.isReplacement()) {
originalEvent = originalEvent.getReplacedEvent();
}
event.setReplacedEvent(originalEvent);
// report replacedEvent and not originalEvent because replaceEvent was in the timeline so far
this.emit("Room.replaceEvent", replacedEvent, event, this);
}
else {
console.warn(`could not find replaced event for target id ${replacedEventId} and if ${event.getId()}, body: ${event.getContent().body}`);
}
// we don't add the event because the event type would get rendered
return;
}
if (event.getUnsigned().transaction_id) {
const existingEvent = this._txnToEvent[event.getUnsigned().transaction_id];
if (existingEvent) {

View File

@@ -132,6 +132,7 @@ SyncApi.prototype.createRoom = function(roomId) {
"Room.localEchoUpdated",
"Room.accountData",
"Room.myMembership",
"Room.replaceEvent",
]);
this._registerStateListeners(room);
return room;