1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-12-01 04:43:29 +03:00

reemit Room.timeline events correctly

This commit is contained in:
Matthew Hodgson
2016-08-30 01:13:32 +01:00
parent 7514aea813
commit 0848d4ed10

View File

@@ -163,6 +163,7 @@ 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._fixUpLegacyTimelineFields();
@@ -453,6 +454,7 @@ Room.prototype.addFilteredTimelineList = function(filter) {
filter: filter,
}
);
reEmit(this, timelineList, [ "Room.timeline" ]);
this._filteredTimelineLists[filter.filterId] = timelineList;
this._timelineLists.push(timelineList);
};
@@ -1194,6 +1196,25 @@ function calculateRoomName(room, userId, ignoreRoomNameEvent) {
}
}
// FIXME: copypasted from sync.js
function reEmit(reEmitEntity, emittableEntity, eventNames) {
utils.forEach(eventNames, function(eventName) {
// setup a listener on the entity (the Room, User, etc) for this event
emittableEntity.on(eventName, function() {
// take the args from the listener and reuse them, adding the
// event name to the arg list so it works with .emit()
// Transformation Example:
// listener on "foo" => function(a,b) { ... }
// Re-emit on "thing" => thing.emit("foo", a, b)
var newArgs = [eventName];
for (var i = 0; i < arguments.length; i++) {
newArgs.push(arguments[i]);
}
reEmitEntity.emit.apply(reEmitEntity, newArgs);
});
});
}
/**
* The Room class.
*/