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

make most things work other than Room.timeline firing

This commit is contained in:
Matthew Hodgson
2016-08-30 01:11:47 +01:00
parent 58031ab21d
commit 7514aea813
2 changed files with 34 additions and 6 deletions

View File

@@ -43,8 +43,9 @@ var EventTimeline = require("./event-timeline");
* <p>In order that we can find events from their ids later, we also maintain a * <p>In order that we can find events from their ids later, we also maintain a
* map from event_id to timeline and index. * map from event_id to timeline and index.
*/ */
function EventTimelineList(roomId, opts) { function EventTimelineList(roomId, room, opts) {
this.roomId = roomId; this.roomId = roomId;
this.room = room;
this._timelineSupport = Boolean(opts.timelineSupport); this._timelineSupport = Boolean(opts.timelineSupport);
this._liveTimeline = new EventTimeline(this.roomId); this._liveTimeline = new EventTimeline(this.roomId);
@@ -407,7 +408,7 @@ EventTimelineList.prototype.addEventToTimeline = function(event, timeline, toSta
liveEvent: !toStartOfTimeline && timeline == this._liveTimeline, liveEvent: !toStartOfTimeline && timeline == this._liveTimeline,
filter: this._filter, filter: this._filter,
}; };
this.emit("Room.timeline", event, this, Boolean(toStartOfTimeline), false, data); this.emit("Room.timeline", event, this.room, Boolean(toStartOfTimeline), false, data);
}; };
EventTimelineList.prototype.replaceOrAddEvent = function(localEvent, oldEventId, newEventId) { EventTimelineList.prototype.replaceOrAddEvent = function(localEvent, oldEventId, newEventId) {
@@ -462,8 +463,9 @@ EventTimelineList.prototype.removeEvent = function(eventId) {
delete this._eventIdToTimeline[eventId]; delete this._eventIdToTimeline[eventId];
var data = { var data = {
timeline: timeline, timeline: timeline,
filter: this._filter,
}; };
this.emit("Room.timeline", removed, this, undefined, true, data); this.emit("Room.timeline", removed, this.room, undefined, true, data);
} }
return removed; return removed;
}; };

View File

@@ -162,7 +162,8 @@ function Room(roomId, opts) {
// all our per-room timeline lists. the first one is the unfiltered ones; // all our per-room timeline lists. the first one is the unfiltered ones;
// the subsequent ones are the filtered ones in no particular order. // the subsequent ones are the filtered ones in no particular order.
this._timelineLists = [ new EventTimelineList(roomId, opts) ]; this._timelineLists = [ new EventTimelineList(roomId, this, opts) ];
this._fixUpLegacyTimelineFields(); this._fixUpLegacyTimelineFields();
// any filtered timeline lists we're maintaining for this room // any filtered timeline lists we're maintaining for this room
@@ -242,6 +243,28 @@ Room.prototype._fixUpLegacyTimelineFields = function() {
this.currentState = this._timelineLists[0].getLiveTimeline().getState(EventTimeline.FORWARDS); this.currentState = this._timelineLists[0].getLiveTimeline().getState(EventTimeline.FORWARDS);
}; };
/**
* Get the timeline which contains the given event from the unfiltered set, if any
*
* @param {string} eventId event ID to look for
* @return {?module:models/event-timeline~EventTimeline} timeline containing
* the given event, or null if unknown
*/
Room.prototype.getTimelineForEvent = function(eventId) {
return this._timelineLists[0].getTimelineForEvent(eventId);
};
/**
* Get an event which is stored in our unfiltered timeline set
*
* @param {string} eventId event ID to look for
* @return {?module:models/event~MatrixEvent} the given event, or undefined if unknown
*/
Room.prototype.findEventById = function(eventId) {
return this._timelineLists[0].findEventById(eventId);
}
/** /**
* Get one of the notification counts for this room * Get one of the notification counts for this room
* @param {String} type The type of notification count to get. default: 'total' * @param {String} type The type of notification count to get. default: 'total'
@@ -356,7 +379,10 @@ Room.prototype.getCanonicalAlias = function() {
Room.prototype.addEventsToTimeline = function(events, toStartOfTimeline, Room.prototype.addEventsToTimeline = function(events, toStartOfTimeline,
timeline, paginationToken) { timeline, paginationToken) {
for (var i = 0; i < this._timelineLists.length; i++) { for (var i = 0; i < this._timelineLists.length; i++) {
this._timelineLists[0] this._timelineLists[0].addEventsToTimeline(
events, toStartOfTimeline,
timeline, paginationToken
);
} }
}; };
@@ -423,7 +449,7 @@ Room.prototype.addEventsToTimeline = function(events, toStartOfTimeline,
*/ */
Room.prototype.addFilteredTimelineList = function(filter) { Room.prototype.addFilteredTimelineList = function(filter) {
var timelineList = new EventTimelineList( var timelineList = new EventTimelineList(
this.roomId, { this.roomId, this, {
filter: filter, filter: filter,
} }
); );