Emit 'Room' event when the Room is fully populated rather than newly created.

This commit is contained in:
Kegan Dougal
2015-06-19 16:05:13 +01:00
parent 2f78ceb6fc
commit 18db0d8c02
+13 -7
View File
@@ -1014,6 +1014,7 @@ MatrixClient.prototype.startClient = function(historyLen) {
room.recalculate(self.credentials.userId);
self.store.storeRoom(room);
self.emit("Room", room);
}
}
@@ -1088,14 +1089,20 @@ function _pollForEvents(client) {
var roomIds = utils.keys(roomIdToEvents);
for (i = 0; i < roomIds.length; i++) {
var room = self.store.getRoom(roomIds[i]);
var shouldStoreRoom = false;
if (!room) {
// TODO: whine about this. We got an event for a room
// we don't know about (we should really be doing a
// roomInitialSync at this point to pull in state).
room = createNewRoom(self, roomIds[i]);
shouldStoreRoom = true;
}
room.addEvents(roomIdToEvents[roomIds[i]], "replace");
room.recalculate(self.credentials.userId);
if (shouldStoreRoom) {
self.store.storeRoom(room);
// TODO: Should be doing roomInitialSync here to pull in
// all state before emitting this(!)
self.emit("Room", room);
}
}
}
if (data) {
@@ -1152,7 +1159,6 @@ function createNewUser(client, userId) {
function createNewRoom(client, roomId) {
var room = new Room(roomId);
reEmit(client, room, ["Room.name", "Room.timeline"]);
client.emit("Room", room); // emit created room event
// we need to also re-emit room state and room member events, so hook it up
// to the client now. We need to add a listener for RoomState.members in
@@ -1209,10 +1215,10 @@ module.exports.MatrixClient = MatrixClient;
*/
/**
* Fires whenever a new Room is created. This Room will not be fully populated
* yet (e.g. no members). <strong>This event is experimental and may change.</strong>
* Fires whenever a new Room is added. <strong>This event is experimental and
* may change.</strong>
* @event module:client~MatrixClient#"Room"
* @param {Room} room The newly created room.
* @param {Room} room The newly created, fully populated room.
* @example
* matrixClient.on("Room", function(room){
* var roomId = room.roomId;