You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-12-23 22:42:10 +03:00
Merge pull request #68 from matrix-org/dbkr/new_unread_count_format
Update for new unread count format
This commit is contained in:
@@ -119,9 +119,30 @@ function Room(roomId, opts) {
|
||||
// data: <receipt data>
|
||||
// }]
|
||||
};
|
||||
this._notificationCounts = {};
|
||||
}
|
||||
utils.inherits(Room, EventEmitter);
|
||||
|
||||
/**
|
||||
* Get one of the notification counts 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 counts 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
|
||||
|
||||
14
lib/sync.js
14
lib/sync.js
@@ -384,7 +384,10 @@ SyncApi.prototype._sync = function(syncOptions, attempt) {
|
||||
// timeline: { events: [], prev_batch: $token, limited: true },
|
||||
// ephemeral: { events: [] },
|
||||
// account_data: { events: [] },
|
||||
// unread_notification_count: 0
|
||||
// unread_notifications: {
|
||||
// highlight_count: 0,
|
||||
// notification_count: 0,
|
||||
// }
|
||||
// }
|
||||
// },
|
||||
// leave: {
|
||||
@@ -466,7 +469,14 @@ SyncApi.prototype._sync = function(syncOptions, attempt) {
|
||||
var accountDataEvents = self._mapSyncEventsFormat(joinObj.account_data);
|
||||
|
||||
// we do this first so it's correct when any of the events fire
|
||||
room.unread_notification_count = joinObj.unread_notification_count;
|
||||
if (joinObj.unread_notifications) {
|
||||
room.setUnreadNotificationCount(
|
||||
'total', joinObj.unread_notifications.notification_count
|
||||
);
|
||||
room.setUnreadNotificationCount(
|
||||
'highlight', joinObj.unread_notifications.highlight_count
|
||||
);
|
||||
}
|
||||
|
||||
joinObj.timeline = joinObj.timeline || {};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user