diff --git a/lib/models/event-timeline-list.js b/lib/models/event-timeline-list.js index 3db20c82e..8e59114cb 100644 --- a/lib/models/event-timeline-list.js +++ b/lib/models/event-timeline-list.js @@ -43,8 +43,9 @@ var EventTimeline = require("./event-timeline"); *

In order that we can find events from their ids later, we also maintain a * map from event_id to timeline and index. */ -function EventTimelineList(roomId, opts) { +function EventTimelineList(roomId, room, opts) { this.roomId = roomId; + this.room = room; this._timelineSupport = Boolean(opts.timelineSupport); this._liveTimeline = new EventTimeline(this.roomId); @@ -407,7 +408,7 @@ EventTimelineList.prototype.addEventToTimeline = function(event, timeline, toSta liveEvent: !toStartOfTimeline && timeline == this._liveTimeline, filter: this._filter, }; - this.emit("Room.timeline", event, this, Boolean(toStartOfTimeline), false, data); + this.emit("Room.timeline", event, this.room, Boolean(toStartOfTimeline), false, data); }; EventTimelineList.prototype.replaceOrAddEvent = function(localEvent, oldEventId, newEventId) { @@ -462,8 +463,9 @@ EventTimelineList.prototype.removeEvent = function(eventId) { delete this._eventIdToTimeline[eventId]; var data = { timeline: timeline, + filter: this._filter, }; - this.emit("Room.timeline", removed, this, undefined, true, data); + this.emit("Room.timeline", removed, this.room, undefined, true, data); } return removed; }; diff --git a/lib/models/room.js b/lib/models/room.js index 9edbfd317..cbcce5afb 100644 --- a/lib/models/room.js +++ b/lib/models/room.js @@ -162,7 +162,8 @@ function Room(roomId, opts) { // all our per-room timeline lists. the first one is the unfiltered ones; // the subsequent ones are the filtered ones in no particular order. - this._timelineLists = [ new EventTimelineList(roomId, opts) ]; + this._timelineLists = [ new EventTimelineList(roomId, this, opts) ]; + this._fixUpLegacyTimelineFields(); // any filtered timeline lists we're maintaining for this room @@ -242,6 +243,28 @@ Room.prototype._fixUpLegacyTimelineFields = function() { this.currentState = this._timelineLists[0].getLiveTimeline().getState(EventTimeline.FORWARDS); }; +/** + * Get the timeline which contains the given event from the unfiltered set, if any + * + * @param {string} eventId event ID to look for + * @return {?module:models/event-timeline~EventTimeline} timeline containing + * the given event, or null if unknown + */ + +Room.prototype.getTimelineForEvent = function(eventId) { + return this._timelineLists[0].getTimelineForEvent(eventId); +}; + +/** + * Get an event which is stored in our unfiltered timeline set + * + * @param {string} eventId event ID to look for + * @return {?module:models/event~MatrixEvent} the given event, or undefined if unknown + */ +Room.prototype.findEventById = function(eventId) { + return this._timelineLists[0].findEventById(eventId); +} + /** * Get one of the notification counts for this room * @param {String} type The type of notification count to get. default: 'total' @@ -356,7 +379,10 @@ Room.prototype.getCanonicalAlias = function() { Room.prototype.addEventsToTimeline = function(events, toStartOfTimeline, timeline, paginationToken) { for (var i = 0; i < this._timelineLists.length; i++) { - this._timelineLists[0] + this._timelineLists[0].addEventsToTimeline( + events, toStartOfTimeline, + timeline, paginationToken + ); } }; @@ -423,7 +449,7 @@ Room.prototype.addEventsToTimeline = function(events, toStartOfTimeline, */ Room.prototype.addFilteredTimelineList = function(filter) { var timelineList = new EventTimelineList( - this.roomId, { + this.roomId, this, { filter: filter, } );