diff --git a/lib/models/room.js b/lib/models/room.js index 2ea0205d9..15cdf602e 100644 --- a/lib/models/room.js +++ b/lib/models/room.js @@ -321,6 +321,24 @@ Room.prototype.getUsersReadUpTo = function(event) { }); }; +/** + * Get the ID of the event that a given user has read up to, or null if we + * have received no read receipts from them. + * @param {String} userId The user ID to get read receipt event ID for + * @return {String} ID of the latest event that the given user has read, or null. + * an empty list. + */ +Room.prototype.getEventReadUpTo = function(userId) { + if ( + this._receipts["m.read"] === undefined || + this._receipts["m.read"][userId] === undefined + ) { + return null; + } + + return this._receipts["m.read"][userId].eventId; +}; + /** * Get a list of receipts for the given event. * @param {MatrixEvent} event the event to get receipts for