diff --git a/lib/models/room.js b/lib/models/room.js index 5b002613e..42948459b 100644 --- a/lib/models/room.js +++ b/lib/models/room.js @@ -119,9 +119,30 @@ function Room(roomId, opts) { // data: // }] }; + this._notificationCounts = {}; } utils.inherits(Room, EventEmitter); +/** + * Get one of the notification counst for this room + * @param {String} type The type of notification count to get. default: 'total' + * @return {Number} The notification count, or undefined if there is no count + * for this type. + */ +Room.prototype.getUnreadNotificationCount = function(type) { + type = type || 'total'; + return this._notificationCounts[type]; +} + +/** + * Set one of the notification counst for this room + * @param {String} type The type of notification count to set. + * @param {Number} type The new count + */ +Room.prototype.setUnreadNotificationCount = function(type, count) { + this._notificationCounts[type] = count; +} + /** * Get the avatar URL for a room if one was set. * @param {String} baseUrl The homeserver base URL. See diff --git a/lib/sync.js b/lib/sync.js index 59b90c4bc..52188899f 100644 --- a/lib/sync.js +++ b/lib/sync.js @@ -470,6 +470,14 @@ SyncApi.prototype._sync = function(syncOptions, attempt) { // we do this first so it's correct when any of the events fire room.unread_notifications = joinObj.unread_notifications || {}; + if (joinObj.unread_notifications) { + room.setUnreadNotificationCount( + 'total', joinObj.unread_notifications['notification_count'] + ); + room.setUnreadNotificationCount( + 'highlight', joinObj.unread_notifications['highlight_count'] + ); + } joinObj.timeline = joinObj.timeline || {};