diff --git a/lib/models/event-timeline-set.js b/lib/models/event-timeline-set.js index d9435348e..5cdec4c21 100644 --- a/lib/models/event-timeline-set.js +++ b/lib/models/event-timeline-set.js @@ -58,7 +58,7 @@ function EventTimelineSet(roomId, room, opts) { this.room = room; this._timelineSupport = Boolean(opts.timelineSupport); - this._liveTimeline = new EventTimeline(this.roomId); + this._liveTimeline = new EventTimeline(this); // just a list - *not* ordered. this._timelines = [this._liveTimeline]; @@ -136,7 +136,7 @@ EventTimelineSet.prototype.resetLiveTimeline = function(backPaginationToken) { if (!this._timelineSupport) { // if timeline support is disabled, forget about the old timelines - newTimeline = new EventTimeline(this.roomId); + newTimeline = new EventTimeline(this); this._timelines = [newTimeline]; this._eventIdToTimeline = {}; } else { @@ -202,7 +202,7 @@ EventTimelineSet.prototype.addTimeline = function() { " it."); } - var timeline = new EventTimeline(this.roomId); + var timeline = new EventTimeline(this); this._timelines.push(timeline); return timeline; }; diff --git a/lib/models/event-timeline.js b/lib/models/event-timeline.js index 6d70b0687..3a12f26db 100644 --- a/lib/models/event-timeline.js +++ b/lib/models/event-timeline.js @@ -25,16 +25,17 @@ var MatrixEvent = require("./event").MatrixEvent; *

Once a timeline joins up with its neighbour, they are linked together into a * doubly-linked list. * - * @param {string} roomId the ID of the room where this timeline came from + * @param {EventTimelineSet} eventTimelineSet the set of timelines this is part of * @constructor */ -function EventTimeline(roomId) { - this._roomId = roomId; +function EventTimeline(eventTimelineSet) { + this._eventTimelineSet = eventTimelineSet; + this._roomId = eventTimelineSet.roomId; this._events = []; this._baseIndex = 0; - this._startState = new RoomState(roomId); + this._startState = new RoomState(this._roomId); this._startState.paginationToken = null; - this._endState = new RoomState(roomId); + this._endState = new RoomState(this._roomId); this._endState.paginationToken = null; this._prevTimeline = null; @@ -43,7 +44,7 @@ function EventTimeline(roomId) { // this is used by client.js this._paginationRequests = {'b': null, 'f': null}; - this._name = roomId + ":" + new Date().toISOString(); + this._name = this._roomId + ":" + new Date().toISOString(); } /** @@ -91,6 +92,14 @@ EventTimeline.prototype.getRoomId = function() { return this._roomId; }; +/** + * Get the filter for this timeline's timelineSet (if any) + * @return {Filter}} filter + */ +EventTimeline.prototype.getFilter = function() { + return this._eventTimelineSet.getFilter(); +}; + /** * Get the base index. * diff --git a/spec/unit/event-timeline.spec.js b/spec/unit/event-timeline.spec.js index 86a4b785b..9a7aba2ae 100644 --- a/spec/unit/event-timeline.spec.js +++ b/spec/unit/event-timeline.spec.js @@ -16,7 +16,7 @@ describe("EventTimeline", function() { beforeEach(function() { utils.beforeEach(this); - timeline = new EventTimeline(roomId); + timeline = new EventTimeline({ roomId : roomId }); }); describe("construction", function() { diff --git a/spec/unit/timeline-window.spec.js b/spec/unit/timeline-window.spec.js index 9c706d75f..f33e9451c 100644 --- a/spec/unit/timeline-window.spec.js +++ b/spec/unit/timeline-window.spec.js @@ -18,7 +18,7 @@ function createTimeline(numEvents, baseIndex) { if (numEvents === undefined) { numEvents = 3; } if (baseIndex === undefined) { baseIndex = 1; } - var timeline = new EventTimeline(ROOM_ID); + var timeline = new EventTimeline({ roomId : ROOM_ID }); // add the events after the baseIndex first addEventsToTimeline(timeline, numEvents - baseIndex, false);