Skip to content
This repository was archived by the owner on May 16, 2019. It is now read-only.

Commit b50743c

Browse files
committed
Merge pull request #1283 from rmisio/notif-quick-fixes
Notif quick fixes
2 parents 8eea617 + 2815317 commit b50743c

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

js/views/notificationsVw.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ module.exports = baseVw.extend({
2222
this.fetch = this.options.initialFetch;
2323

2424
this.listenTo(this.collection, 'update', (cl, options) => {
25+
if (!options.add) return;
26+
27+
// on first notification, we'll re-render
28+
if (cl.length === 1) this.render();
29+
2530
var $notifPage = $('<div />');
2631

2732
// we're assuming the only additions will either be a batch of

js/views/pageNavVw.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,13 @@ module.exports = baseVw.extend({
9090
});
9191

9292
this.unreadNotifsViaSocket = 0;
93+
this.fetchNotifsMarkedAsRead = 0;
9394

94-
this.listenTo(this.notificationsCl, 'reset update', (cl, options) => {
95-
if (options.xhr) this.unreadNotifsViaSocket = 0;
95+
this.listenTo(this.notificationsCl, 'reset update', function(cl, options) {
96+
if (options.xhr) {
97+
this.fetchNotifsMarkedAsRead = 0;
98+
this.unreadNotifsViaSocket = 0;
99+
}
96100

97101
this.setNotificationCount(this.getUnreadNotifCount());
98102
});
@@ -164,7 +168,7 @@ module.exports = baseVw.extend({
164168

165169
this.notificationsCl.add(
166170
__.extend({}, notif, { read: false })
167-
)
171+
);
168172

169173
//prevent message spamming from one user
170174
if(!this.notificationsRecord[username]){
@@ -374,7 +378,8 @@ module.exports = baseVw.extend({
374378
},
375379

376380
getUnreadNotifCount: function() {
377-
return (this.unreadNotifsViaSocket + this.notificationsCl.getUnreadCount()) || 0;
381+
return this.unreadNotifsViaSocket + this.notificationsCl.getUnreadCount() -
382+
this.fetchNotifsMarkedAsRead || 0;
378383
},
379384

380385
onNotifMenuOpen: function() {
@@ -407,7 +412,9 @@ module.exports = baseVw.extend({
407412
});
408413
}
409414

410-
this.setNotificationCount(0);
415+
this.fetchNotifsMarkedAsRead += unread.length - this.unreadNotifsViaSocket;
416+
this.unreadNotifsViaSocket = 0;
417+
this.setNotificationCount(this.getUnreadNotifCount());
411418
},
412419

413420
onPopMenuNavClick: function(e) {

0 commit comments

Comments
 (0)