You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-09-01 21:21:58 +03:00
Handle redactions (both live and historic).
This commit is contained in:
@@ -35,6 +35,7 @@ function Room(roomId, storageToken) {
|
||||
this.currentState = new RoomState(roomId);
|
||||
this.summary = null;
|
||||
this.storageToken = storageToken;
|
||||
this._redactions = [];
|
||||
}
|
||||
utils.inherits(Room, EventEmitter);
|
||||
|
||||
@@ -94,6 +95,10 @@ utils.inherits(Room, EventEmitter);
|
||||
Room.prototype.addEventsToTimeline = function(events, toStartOfTimeline) {
|
||||
var stateContext = toStartOfTimeline ? this.oldState : this.currentState;
|
||||
for (var i = 0; i < events.length; i++) {
|
||||
if (toStartOfTimeline && this._redactions.indexOf(events[i].getId()) >= 0) {
|
||||
continue; // do not add the redacted event.
|
||||
}
|
||||
|
||||
setEventMetadata(events[i], stateContext, toStartOfTimeline);
|
||||
// modify state
|
||||
if (events[i].isState()) {
|
||||
@@ -105,6 +110,20 @@ Room.prototype.addEventsToTimeline = function(events, toStartOfTimeline) {
|
||||
setEventMetadata(events[i], stateContext, toStartOfTimeline);
|
||||
}
|
||||
}
|
||||
if (events[i].getType() === "m.room.redaction") {
|
||||
// try to remove the element
|
||||
var removed = utils.removeElement(this.timeline, function(e) {
|
||||
return e.getId() === events[i].event.redacts
|
||||
}, true);
|
||||
if (!removed && toStartOfTimeline) {
|
||||
// redactions will trickle in BEFORE the event redacted so make
|
||||
// a note of the redacted event; we'll check it later.
|
||||
this._redactions.push(events[i].event.redacts);
|
||||
}
|
||||
// NB: We continue to add the redaction event to the timeline so clients
|
||||
// can say "so and so redacted an event" if they wish to.
|
||||
}
|
||||
|
||||
// TODO: pass through filter to see if this should be added to the timeline.
|
||||
if (toStartOfTimeline) {
|
||||
this.timeline.unshift(events[i]);
|
||||
|
Reference in New Issue
Block a user