From 16992aa1fba852260346c76c24906a351cd0324d Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Tue, 29 Sep 2015 01:28:14 +0200 Subject: [PATCH] Sync notification count when clicking on them or marking all as read Refs #500. --- framework/core/js/forum/src/components/Notification.js | 1 + framework/core/js/forum/src/components/NotificationList.js | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/framework/core/js/forum/src/components/Notification.js b/framework/core/js/forum/src/components/Notification.js index 52b61829c..05b5f1d84 100644 --- a/framework/core/js/forum/src/components/Notification.js +++ b/framework/core/js/forum/src/components/Notification.js @@ -77,6 +77,7 @@ export default class Notification extends Component { * Mark the notification as read. */ markAsRead() { + app.session.user.pushAttributes({unreadNotificationsCount: app.session.user.unreadNotificationsCount() - 1}); this.props.notification.save({isRead: true}); } } diff --git a/framework/core/js/forum/src/components/NotificationList.js b/framework/core/js/forum/src/components/NotificationList.js index e7732e91a..3d24a1168 100644 --- a/framework/core/js/forum/src/components/NotificationList.js +++ b/framework/core/js/forum/src/components/NotificationList.js @@ -110,7 +110,7 @@ export default class NotificationList extends Component { * been loaded. */ load() { - if (app.cache.notifications && !app.session.user.unreadNotificationsCount()) { + if (app.cache.notifications && !app.session.user.newNotificationsCount()) { return; } @@ -118,7 +118,7 @@ export default class NotificationList extends Component { m.redraw(); app.store.find('notifications').then(notifications => { - app.session.user.pushAttributes({unreadNotificationsCount: 0}); + app.session.user.pushAttributes({newNotificationsCount: 0}); app.cache.notifications = notifications.sort((a, b) => b.time() - a.time()); this.loading = false; @@ -132,6 +132,8 @@ export default class NotificationList extends Component { markAllAsRead() { if (!app.cache.notifications) return; + app.session.user.pushAttributes({unreadNotificationsCount: 0}); + app.cache.notifications.forEach(notification => { if (!notification.isRead()) { notification.save({isRead: true});