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

change TimelineWindow to take a timelineSet rather than a Room

This commit is contained in:
Matthew Hodgson
2016-09-04 13:57:56 +01:00
parent 4ff2ad9fac
commit 2daa1b6007
5 changed files with 73 additions and 46 deletions

View File

@@ -19,6 +19,7 @@ limitations under the License.
var q = require("q");
var EventTimeline = require("./models/event-timeline");
var EventTimelineSet = require("./models/event-timeline-set");
/**
* @private
@@ -56,7 +57,7 @@ var DEFAULT_PAGINATE_LOOP_LIMIT = 5;
* @param {MatrixClient} client MatrixClient to be used for context/pagination
* requests.
*
* @param {Room} room The room to track
* @param {EventTimelineSet} timelineSet The timelineSet to track
*
* @param {Object} [opts] Configuration options for this window
*
@@ -66,10 +67,10 @@ var DEFAULT_PAGINATE_LOOP_LIMIT = 5;
*
* @constructor
*/
function TimelineWindow(client, room, opts) {
function TimelineWindow(client, timelineSet, opts) {
opts = opts || {};
this._client = client;
this._room = room;
this._timelineSet = timelineSet;
// these will be TimelineIndex objects; they delineate the 'start' and
// 'end' of the window.
@@ -113,7 +114,7 @@ TimelineWindow.prototype.load = function(initialEventId, initialWindowSize) {
// TODO: ideally we'd spot getEventTimeline returning a resolved promise and
// skip straight to the find-event loop.
if (initialEventId) {
return this._client.getEventTimeline(this._room, initialEventId)
return this._client.getEventTimeline(this._timelineSet, initialEventId)
.then(function(tl) {
// make sure that our window includes the event
for (var i = 0; i < tl.getEvents().length; i++) {
@@ -126,7 +127,7 @@ TimelineWindow.prototype.load = function(initialEventId, initialWindowSize) {
});
} else {
// start with the most recent events
var tl = this._room.getLiveTimeline();
var tl = this._timelineSet.getLiveTimeline();
initFields(tl, tl.getEvents().length);
return q();
}