diff --git a/lib/models/room.js b/lib/models/room.js index b3958782d..6983efcc7 100644 --- a/lib/models/room.js +++ b/lib/models/room.js @@ -94,6 +94,13 @@ utils.inherits(Room, EventEmitter); */ Room.prototype.addEventsToTimeline = function(events, toStartOfTimeline) { var stateContext = toStartOfTimeline ? this.oldState : this.currentState; + + function checkForRedaction(redactEvent) { + return function(e) { + return e.getId() === redactEvent.event.redacts; + }; + } + for (var i = 0; i < events.length; i++) { if (toStartOfTimeline && this._redactions.indexOf(events[i].getId()) >= 0) { continue; // do not add the redacted event. @@ -112,9 +119,9 @@ Room.prototype.addEventsToTimeline = function(events, 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); + var removed = utils.removeElement( + this.timeline, checkForRedaction(events[i]) + ); if (!removed && toStartOfTimeline) { // redactions will trickle in BEFORE the event redacted so make // a note of the redacted event; we'll check it later. diff --git a/lib/utils.js b/lib/utils.js index 55edd993b..913d5815a 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -148,7 +148,7 @@ module.exports.findElement = function(array, fn, reverse) { * function signature fn(element, index, array). Return true to * remove this element and break. * @param {boolean} reverse True to search in reverse order. - * @return True if an element was removed. + * @return {boolean} True if an element was removed. */ module.exports.removeElement = function(array, fn, reverse) { var i;