1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-28 05:03:59 +03:00

Address a number of review comments.

Make sure that room state is copied correctly when resetting the live
timeline.

Also comments and bits.
This commit is contained in:
Richard van der Hoff
2016-01-26 18:09:15 +00:00
parent 48d1bc3158
commit a01501b42c
5 changed files with 178 additions and 92 deletions

View File

@@ -5,6 +5,8 @@
*/
var RoomState = require("./room-state");
var utils = require("../utils");
var MatrixEvent = require("./event").MatrixEvent;
/**
* Construct a new EventTimeline
@@ -31,7 +33,9 @@ function EventTimeline(roomId) {
this._events = [];
this._baseIndex = -1;
this._startState = new RoomState(roomId);
this._startState.paginationToken = null;
this._endState = new RoomState(roomId);
this._endState.paginationToken = null;
this._prevTimeline = null;
this._nextTimeline = null;
@@ -54,8 +58,14 @@ EventTimeline.prototype.initialiseState = function(stateEvents) {
throw new Error("Cannot initialise state after events are added");
}
// do we need to copy here? sync thinks we do but I can't see why
this._startState.setStateEvents(stateEvents);
// we deep-copy the events here, in case they get changed later - we don't
// want changes to the start state leaking through to the end state.
var oldStateEvents = utils.map(
utils.deepCopy(
stateEvents.map(function(mxEvent) { return mxEvent.event; })
), function(ev) { return new MatrixEvent(ev); });
this._startState.setStateEvents(oldStateEvents);
this._endState.setStateEvents(stateEvents);
};
@@ -72,7 +82,9 @@ EventTimeline.prototype.getRoomId = function() {
*
* <p>This is an index which is incremented when events are prepended to the
* timeline. An individual event therefore stays at the same index in the array
* relative to the base index.
* relative to the base index (although note that a given event's index may
* well be less than the base index, thus giving that event a negative relative
* index).
*
* @return {number}
*/