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

fix things until they almost work again...

This commit is contained in:
Matthew Hodgson
2016-08-30 00:36:52 +01:00
parent c1c2ca3ec1
commit 58031ab21d
2 changed files with 120 additions and 49 deletions

View File

@@ -44,9 +44,10 @@ var EventTimeline = require("./event-timeline");
* map from event_id to timeline and index.
*/
function EventTimelineList(roomId, opts) {
this.roomId = roomId;
this._timelineSupport = Boolean(opts.timelineSupport);
this._liveTimeline = new EventTimeline(this.roomId);
this._fixUpLegacyTimelineFields();
// just a list - *not* ordered.
this._timelines = [this._liveTimeline];
@@ -86,8 +87,6 @@ EventTimelineList.prototype.getLiveTimeline = function(filterId) {
* <p>This is used when /sync returns a 'limited' timeline.
*
* @param {string=} backPaginationToken token for back-paginating the new timeline
*
* @fires module:client~MatrixClient#event:"Room.timelineReset"
*/
EventTimelineList.prototype.resetLiveTimeline = function(backPaginationToken) {
var newTimeline;
@@ -119,23 +118,6 @@ EventTimelineList.prototype.resetLiveTimeline = function(backPaginationToken) {
newTimeline.setPaginationToken(backPaginationToken, EventTimeline.BACKWARDS);
this._liveTimeline = newTimeline;
this._fixUpLegacyTimelineFields();
this.emit("Room.timelineReset", this);
};
/**
* Fix up this.timeline, this.oldState and this.currentState
*
* @private
*/
EventTimelineList.prototype._fixUpLegacyTimelineFields = function() {
// maintain this.timeline as a reference to the live timeline,
// and this.oldState and this.currentState as references to the
// state at the start and end of that timeline. These are more
// for backwards-compatibility than anything else.
this.timeline = this._liveTimeline.getEvents();
this.oldState = this._liveTimeline.getState(EventTimeline.BACKWARDS);
this.currentState = this._liveTimeline.getState(EventTimeline.FORWARDS);
};
/**
@@ -217,6 +199,11 @@ EventTimelineList.prototype.addEventsToTimeline = function(events, toStartOfTime
);
}
if (this._filter) {
var events = this._filter.filterRoomTimeline(events);
if (!events) return;
}
var direction = toStartOfTimeline ? EventTimeline.BACKWARDS :
EventTimeline.FORWARDS;
var inverseDirection = toStartOfTimeline ? EventTimeline.FORWARDS :
@@ -423,6 +410,16 @@ EventTimelineList.prototype.addEventToTimeline = function(event, timeline, toSta
this.emit("Room.timeline", event, this, Boolean(toStartOfTimeline), false, data);
};
EventTimelineList.prototype.replaceOrAddEvent = function(localEvent, oldEventId, newEventId) {
var existingTimeline = this._eventIdToTimeline[oldEventId];
if (existingTimeline) {
delete this._eventIdToTimeline[oldEventId];
this._eventIdToTimeline[newEventId] = existingTimeline;
} else {
this.addEventToTimeline(localEvent, this._liveTimeline, false);
}
};
/**
* Helper method to set sender and target properties, private to Room and EventTimelineList
*/