1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-29 16:43:09 +03:00

make EventTimeline take an EventTimelineSet

This commit is contained in:
Matthew Hodgson
2016-09-07 21:17:06 +01:00
parent 9b507f6c6c
commit 91f8df8d19
4 changed files with 20 additions and 11 deletions

View File

@@ -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;
};

View File

@@ -25,16 +25,17 @@ var MatrixEvent = require("./event").MatrixEvent;
* <p>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.
*

View File

@@ -16,7 +16,7 @@ describe("EventTimeline", function() {
beforeEach(function() {
utils.beforeEach(this);
timeline = new EventTimeline(roomId);
timeline = new EventTimeline({ roomId : roomId });
});
describe("construction", function() {

View File

@@ -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);