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

s/EventTimelineList/EventTimelineSet/g at vdh's req

This commit is contained in:
Matthew Hodgson
2016-09-03 22:27:29 +01:00
parent ba06e8091f
commit 4ff2ad9fac
3 changed files with 90 additions and 88 deletions

View File

@@ -25,7 +25,7 @@ var MatrixEvent = require("./event").MatrixEvent;
var utils = require("../utils");
var ContentRepo = require("../content-repo");
var EventTimeline = require("./event-timeline");
var EventTimelineList = require("./event-timeline-list");
var EventTimelineSet = require("./event-timeline-set");
// var DEBUG = false;
@@ -162,18 +162,18 @@ function Room(roomId, opts) {
// all our per-room timeline lists. the first one is the unfiltered ones;
// the subsequent ones are the filtered ones in no particular order.
this._timelineLists = [ new EventTimelineList(roomId, this, opts) ];
reEmit(this, this._timelineLists[0], [ "Room.timeline" ]);
this._timelineSets = [ new EventTimelineSet(roomId, this, opts) ];
reEmit(this, this._timelineSets[0], [ "Room.timeline" ]);
this._fixUpLegacyTimelineFields();
// any filtered timeline lists we're maintaining for this room
this._filteredTimelineLists = {
// filter_id: timelineList
this._filteredTimelineSets = {
// filter_id: timelineSet
};
// a reference to our shared notification timeline list
this._notifTimelineList = opts.notifTimelineList;
this._notifTimelineSet = opts.notifTimelineSet;
if (this._opts.pendingEventOrdering == "detached") {
this._pendingEventList = [];
@@ -205,7 +205,7 @@ Room.prototype.getPendingEvents = function() {
* @return {module:models/event-timeline~EventTimeline} live timeline
*/
Room.prototype.getLiveTimeline = function(filterId) {
return this._timelineLists[0].getLiveTimeline();
return this._timelineSets[0].getLiveTimeline();
};
@@ -221,8 +221,8 @@ Room.prototype.getLiveTimeline = function(filterId) {
Room.prototype.resetLiveTimeline = function(backPaginationToken) {
var newTimeline;
for (var i = 0; i < this._timelineLists.length; i++) {
this._timelineLists[i].resetLiveTimeline(backPaginationToken);
for (var i = 0; i < this._timelineSets.length; i++) {
this._timelineSets[i].resetLiveTimeline(backPaginationToken);
}
this._fixUpLegacyTimelineFields();
@@ -239,9 +239,9 @@ Room.prototype._fixUpLegacyTimelineFields = function() {
// 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._timelineLists[0].getLiveTimeline().getEvents();
this.oldState = this._timelineLists[0].getLiveTimeline().getState(EventTimeline.BACKWARDS);
this.currentState = this._timelineLists[0].getLiveTimeline().getState(EventTimeline.FORWARDS);
this.timeline = this._timelineSets[0].getLiveTimeline().getEvents();
this.oldState = this._timelineSets[0].getLiveTimeline().getState(EventTimeline.BACKWARDS);
this.currentState = this._timelineSets[0].getLiveTimeline().getState(EventTimeline.FORWARDS);
};
/**
@@ -253,7 +253,7 @@ Room.prototype._fixUpLegacyTimelineFields = function() {
*/
Room.prototype.getTimelineForEvent = function(eventId) {
return this._timelineLists[0].getTimelineForEvent(eventId);
return this._timelineSets[0].getTimelineForEvent(eventId);
};
/**
@@ -262,7 +262,7 @@ Room.prototype.getTimelineForEvent = function(eventId) {
* @return {module:models/event-timeline~EventTimeline} newly-created timeline
*/
Room.prototype.addTimeline = function() {
return this._timelineLists[0].addTimeline();
return this._timelineSets[0].addTimeline();
};
/**
@@ -272,7 +272,7 @@ Room.prototype.addTimeline = function() {
* @return {?module:models/event.MatrixEvent} the given event, or undefined if unknown
*/
Room.prototype.findEventById = function(eventId) {
return this._timelineLists[0].findEventById(eventId);
return this._timelineSets[0].findEventById(eventId);
};
/**
@@ -388,8 +388,8 @@ Room.prototype.getCanonicalAlias = function() {
*/
Room.prototype.addEventsToTimeline = function(events, toStartOfTimeline,
timeline, paginationToken) {
for (var i = 0; i < this._timelineLists.length; i++) {
this._timelineLists[0].addEventsToTimeline(
for (var i = 0; i < this._timelineSets.length; i++) {
this._timelineSets[0].addEventsToTimeline(
events, toStartOfTimeline,
timeline, paginationToken
);
@@ -455,28 +455,28 @@ Room.prototype.addEventsToTimeline = function(events, toStartOfTimeline,
};
/**
* Add a timelineList for this room with the given filter
* Add a timelineSet for this room with the given filter
*/
Room.prototype.addFilteredTimelineList = function(filter) {
var timelineList = new EventTimelineList(
Room.prototype.addFilteredTimelineSet = function(filter) {
var timelineSet = new EventTimelineSet(
this.roomId, this, {
filter: filter,
}
);
reEmit(this, timelineList, [ "Room.timeline" ]);
this._filteredTimelineLists[filter.filterId] = timelineList;
this._timelineLists.push(timelineList);
reEmit(this, timelineSet, [ "Room.timeline" ]);
this._filteredTimelineSets[filter.filterId] = timelineSet;
this._timelineSets.push(timelineSet);
};
/**
* Forget the timelineList for this room with the given filter
* Forget the timelineSet for this room with the given filter
*/
Room.prototype.removeFilteredTimelineList = function(filter) {
var timelineList = this._filteredTimelineLists[filter.filterId];
delete this._filteredTimelineLists[filter.filterId];
var i = this._timelineLists.indexOf(timelineList);
Room.prototype.removeFilteredTimelineSet = function(filter) {
var timelineSet = this._filteredTimelineSets[filter.filterId];
delete this._filteredTimelineSets[filter.filterId];
var i = this._timelineSets.indexOf(timelineSet);
if (i > -1) {
this._timelineLists.splice(i, 1);
this._timelineSets.splice(i, 1);
}
};
@@ -493,14 +493,14 @@ Room.prototype._addLiveEvent = function(event, duplicateStrategy) {
if (event.getType() === "m.room.redaction") {
var redactId = event.event.redacts;
for (var i = 0; i < this._timelineLists.length; i++) {
var timelineList = this._timelineLists[i];
for (var i = 0; i < this._timelineSets.length; i++) {
var timelineSet = this._timelineSets[i];
// if we know about this event, redact its contents now.
var redactedEvent = timelineList.findEventById(redactId);
var redactedEvent = timelineSet.findEventById(redactId);
if (redactedEvent) {
redactedEvent.makeRedacted(event);
// FIXME: these should be emitted from EventTimelineList probably
this.emit("Room.redaction", event, this, timelineList);
// FIXME: these should be emitted from EventTimelineSet probably
this.emit("Room.redaction", event, this, timelineSet);
// TODO: we stash user displaynames (among other things) in
// RoomMember objects which are then attached to other events
@@ -527,14 +527,14 @@ Room.prototype._addLiveEvent = function(event, duplicateStrategy) {
}
// add to our timeline lists
for (var i = 0; i < this._timelineLists.length; i++) {
this._timelineLists[i].addLiveEvent(event, duplicateStrategy);
for (var i = 0; i < this._timelineSets.length; i++) {
this._timelineSets[i].addLiveEvent(event, duplicateStrategy);
}
// add to notification timeline list, if any
if (this._notifTimelineList) {
if (this._notifTimelineSet) {
if (event.isNotification()) {
this._notifTimelineList.addLiveEvent(event, duplicateStrategy);
this._notifTimelineSet.addLiveEvent(event, duplicateStrategy);
}
}
@@ -585,11 +585,11 @@ Room.prototype.addPendingEvent = function(event, txnId) {
}
// call setEventMetadata to set up event.sender etc
// as event is shared over all timelinelists, we set up its metadata based
// on the unfiltered timelineList.
// as event is shared over all timelineSets, we set up its metadata based
// on the unfiltered timelineSet.
EventTimeline.setEventMetadata(
event,
this._timelineLists[0].getLiveTimeline().getState(EventTimeline.FORWARDS),
this._timelineSets[0].getLiveTimeline().getState(EventTimeline.FORWARDS),
false
);
@@ -598,10 +598,10 @@ Room.prototype.addPendingEvent = function(event, txnId) {
if (this._opts.pendingEventOrdering == "detached") {
this._pendingEventList.push(event);
} else {
for (var i = 0; i < this._timelineLists.length; i++) {
this._timelineLists[i].addEventToTimeline(event, this._timelineLists[i].getLiveTimeline(), false);
for (var i = 0; i < this._timelineSets.length; i++) {
this._timelineSets[i].addEventToTimeline(event, this._timelineSets[i].getLiveTimeline(), false);
}
// notifications are receive-only, so we don't need to worry about this._notifTimelineList.
// notifications are receive-only, so we don't need to worry about this._notifTimelineSet.
}
this.emit("Room.localEchoUpdated", event, this, null, null);
@@ -645,11 +645,11 @@ Room.prototype._handleRemoteEcho = function(remoteEvent, localEvent) {
// successfully sent.
localEvent.status = null;
for (var i = 0; i < this._timelineLists.length; i++) {
var timelineList = this._timelineLists[i];
for (var i = 0; i < this._timelineSets.length; i++) {
var timelineSet = this._timelineSets[i];
// if it's already in the timeline, update the timeline map. If it's not, add it.
timelineList.replaceOrAddEvent(localEvent, oldEventId, newEventId);
timelineSet.replaceOrAddEvent(localEvent, oldEventId, newEventId);
}
this.emit("Room.localEchoUpdated", localEvent, this,
@@ -705,7 +705,7 @@ Room.prototype.updatePendingEvent = function(event, newStatus, newEventId) {
// SENT races against /sync, so we have to special-case it.
if (newStatus == EventStatus.SENT) {
var timeline = this._timelineLists[0].eventIdToTimeline(newEventId);
var timeline = this._timelineSets[0].eventIdToTimeline(newEventId);
if (timeline) {
// we've already received the event via the event stream.
// nothing more to do here.
@@ -736,8 +736,8 @@ Room.prototype.updatePendingEvent = function(event, newStatus, newEventId) {
// if the event was already in the timeline (which will be the case if
// opts.pendingEventOrdering==chronological), we need to update the
// timeline map.
for (var i = 0; i < this._timelineLists.length; i++) {
this._timelineLists[i].replaceEventId(oldEventId, newEventId);
for (var i = 0; i < this._timelineSets.length; i++) {
this._timelineSets[i].replaceEventId(oldEventId, newEventId);
}
}
else if (newStatus == EventStatus.CANCELLED) {
@@ -778,12 +778,12 @@ Room.prototype.addLiveEvents = function(events, duplicateStrategy) {
}
// sanity check that the live timeline is still live
for (var i = 0; i < this._timelineLists.length; i++) {
var liveTimeline = this._timelineLists[i].getLiveTimeline();
for (var i = 0; i < this._timelineSets.length; i++) {
var liveTimeline = this._timelineSets[i].getLiveTimeline();
if (liveTimeline.getPaginationToken(EventTimeline.FORWARDS)) {
throw new Error(
"live timeline "+i+" is no longer live - it has a pagination token (" +
timelineList.getPaginationToken(EventTimeline.FORWARDS) + ")"
timelineSet.getPaginationToken(EventTimeline.FORWARDS) + ")"
);
}
if (liveTimeline.getNeighbouringTimeline(EventTimeline.FORWARDS)) {
@@ -830,8 +830,8 @@ Room.prototype.removeEvents = function(event_ids) {
*/
Room.prototype.removeEvent = function(eventId) {
var removedAny;
for (var i = 0; i < this._timelineLists.length; i++) {
var removed = this._timelineLists[i].removeEvent(eventId);
for (var i = 0; i < this._timelineSets.length; i++) {
var removed = this._timelineSets[i].removeEvent(eventId);
if (removed) {
removedAny = true;
}
@@ -992,7 +992,7 @@ Room.prototype._addReceiptsToStructure = function(event, receipts) {
// than the one we already have. (This is managed
// server-side, but because we synthesize RRs locally we
// have to do it here too.)
var ordering = self._timelineLists[0].compareEventOrdering(
var ordering = self._timelineSets[0].compareEventOrdering(
existingReceipt.eventId, eventId);
if (ordering !== null && ordering >= 0) {
return;