From 142ee81e6698ff0f191525a4af8c45dac4f2b71a Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 3 Nov 2015 11:43:52 +0000 Subject: [PATCH] Emit events for read receipts --- lib/client.js | 2 +- lib/models/room.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/client.js b/lib/client.js index 1c597c2cb..69f288d63 100644 --- a/lib/client.js +++ b/lib/client.js @@ -2466,7 +2466,7 @@ function createNewUser(client, userId) { function createNewRoom(client, roomId) { var room = new Room(roomId); - reEmit(client, room, ["Room.name", "Room.timeline"]); + reEmit(client, room, ["Room.name", "Room.timeline", "Room.receipt"]); // 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 diff --git a/lib/models/room.js b/lib/models/room.js index 15cdf602e..908e4ef15 100644 --- a/lib/models/room.js +++ b/lib/models/room.js @@ -399,6 +399,10 @@ Room.prototype.addReceipt = function(event) { }); }); }); + + // send events after we've regenerated the cache, otherwise things that + // listened for the event would read from a stale cache + this.emit("Room.receipt", event, this); }; function setEventMetadata(event, stateContext, toStartOfTimeline) { @@ -527,3 +531,14 @@ module.exports = Room; * var newName = room.name; * }); */ + +/** + * Fires whenever a receipt is received for a room + * @event module:client~MatrixClient#"Room.receipt" + * @param {event} event The receipt event + * @param {Room} room The room whose Room.name was updated. + * @example + * matrixClient.on("Room.receipt", function(event, room){ + * var receiptContent = event.getContent(); + * }); + */