diff --git a/lib/models/room.js b/lib/models/room.js index cbcce5afb..80ca543c3 100644 --- a/lib/models/room.js +++ b/lib/models/room.js @@ -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. */