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

mark original event as replaced instead of replacing the event object

this is more in line with what happens on the server-side,
and also doesn't break existing reply relations.
This commit is contained in:
Bruno Windels
2019-05-15 11:47:00 +01:00
parent 0e53f9052f
commit db7a402e9b
4 changed files with 36 additions and 92 deletions

View File

@@ -1032,22 +1032,15 @@ Room.prototype._addLiveEvent = function(event, duplicateStrategy) {
// this may be needed to trigger an update.
}
if (this._opts.unstableClientRelationReplacements && event.isReplacement()) {
const replacedEventId = event.getOriginalId();
const replacedEvent = replacedEventId &&
this.getUnfilteredTimelineSet().tryReplaceEvent(replacedEventId, event);
if (this._opts.unstableClientRelationReplacements && event.isRelation("m.replace")) {
const relatesTo = event.getContent()["m.relates_to"];
const replacedId = relatesTo && relatesTo.event_id;
const replacedEvent = this.getUnfilteredTimelineSet().findEventById(replacedId);
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);
replacedEvent.makeReplaced(event);
this.emit("Room.replaceEvent", replacedEvent, this);
}
// we don't add the event because the event type would get rendered
return;
}
if (event.getUnsigned().transaction_id) {
@@ -1101,7 +1094,7 @@ Room.prototype._addLiveEvent = function(event, duplicateStrategy) {
* unique transaction id.
*/
Room.prototype.addPendingEvent = function(event, txnId) {
if (event.isReplacement()) {
if (event.isRelation("m.replace")) {
return;
}