1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-12-05 17:02:07 +03:00

use relation handling in timelineset for replacements

This commit is contained in:
Bruno Windels
2019-05-16 14:35:50 +01:00
parent 07572d1e8d
commit 33e9eb371e
2 changed files with 6 additions and 20 deletions

View File

@@ -747,19 +747,24 @@ EventTimelineSet.prototype.aggregateRelations = function(event) {
relationsWithRelType = relationsForEvent[relationType] = {};
}
let relationsWithEventType = relationsWithRelType[eventType];
const relatesToEvent = this.findEventById(relatesToEventId);
if (!relationsWithEventType) {
relationsWithEventType = relationsWithRelType[eventType] = new Relations(
relationType,
eventType,
this.room,
);
const relatesToEvent = this.findEventById(relatesToEventId);
if (relatesToEvent) {
relatesToEvent.emit("Event.relationsCreated", relationType, eventType);
}
}
relationsWithEventType.addEvent(event, relatesToEvent);
if (relationType === "m.replace" && relatesToEvent) {
const replacement = relationsWithEventType.getLastReplacement();
relatesToEvent.makeReplaced(replacement);
}
};
/**

View File

@@ -1032,25 +1032,6 @@ Room.prototype._addLiveEvent = function(event, duplicateStrategy) {
// this may be needed to trigger an update.
}
if (this._opts.unstableClientRelationReplacements && event.isRelation("m.replace")) {
const relatesTo = event.getRelation();
const replacedId = relatesTo && relatesTo.event_id;
const replacedEvent = this.getUnfilteredTimelineSet().findEventById(replacedId);
if (replacedEvent && event.getSender() === replacedEvent.getSender()) {
const doAndEmitReplacement = () => {
replacedEvent.makeReplaced(event);
this.emit("Room.replaceEvent", replacedEvent, this);
};
if (event.isBeingDecrypted()) {
event.once("Event.decrypted", doAndEmitReplacement);
} else {
doAndEmitReplacement();
}
}
}
if (event.getUnsigned().transaction_id) {
const existingEvent = this._txnToEvent[event.getUnsigned().transaction_id];
if (existingEvent) {