Skip to content

Commit 57d0abd

Browse files
benjaminapetersenspadgett
authored andcommitted
Fix issue #2302: marking all notifications read can resurrect cleared notifications
1 parent d9e3c8a commit 57d0abd

File tree

2 files changed

+73
-51
lines changed

2 files changed

+73
-51
lines changed

Diff for: app/scripts/directives/notifications/notificationDrawerWrapper.js

+29-11
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@
8686
return _.filter(notifications, 'unread');
8787
};
8888

89-
9089
var countUnreadNotifications = function() {
9190
_.each(drawer.notificationGroups, function(group) {
9291
group.totalUnread = unread(group.notifications).length;
@@ -99,12 +98,29 @@
9998
_.each(drawer.notificationGroups, function(group) {
10099
_.remove(group.notifications, { uid: notification.uid, namespace: notification.namespace });
101100
});
102-
delete notificationsMap[$routeParams.project][notification.uid];
101+
};
102+
103+
var remove = function(notification) {
104+
// remove the notification from the underlying maps.
105+
// this ensures no ghost notifications linger.
106+
if(notificationsMap[$routeParams.project]) {
107+
delete notificationsMap[$routeParams.project][notification.uid];
108+
}
109+
if(apiEventsMap[$routeParams.project]) {
110+
delete apiEventsMap[$routeParams.project][notification.uid];
111+
}
112+
// then remove it from the map that is rendered to UI.
113+
removeNotificationFromGroup(notification);
114+
};
115+
116+
var removeAllForProject = function() {
117+
apiEventsMap[$routeParams.project] = {};
118+
notificationsMap[$routeParams.project] = {};
103119
};
104120

105121
var formatAPIEvents = function(apiEvents) {
106-
return _.map(apiEvents, function(event) {
107-
return {
122+
return _.reduce(apiEvents, function(result, event) {
123+
result[event.metadata.uid] = {
108124
actions: null,
109125
uid: event.metadata.uid,
110126
trackByID: event.metadata.uid,
@@ -114,7 +130,8 @@
114130
firstTimestamp: event.firstTimestamp,
115131
event: event
116132
};
117-
});
133+
return result;
134+
}, {});
118135
};
119136

120137
var filterAPIEvents = function(events) {
@@ -246,9 +263,9 @@
246263
notification.unread = false;
247264
EventsService.markRead(notification.uid);
248265
EventsService.markCleared(notification.uid);
266+
249267
});
250-
apiEventsMap[$routeParams.project] = {};
251-
notificationsMap[$routeParams.project] = {};
268+
removeAllForProject();
252269
render();
253270
$rootScope.$emit('NotificationDrawerWrapper.onMarkAllRead');
254271
},
@@ -257,14 +274,16 @@
257274
notificationBodyInclude: 'views/directives/notifications/notification-body.html',
258275
customScope: {
259276
clear: function(notification, index, group) {
277+
EventsService.markRead(notification.uid);
260278
EventsService.markCleared(notification.uid);
261279
group.notifications.splice(index, 1);
262-
countUnreadNotifications();
280+
remove(notification);
281+
render();
263282
},
264283
markRead: function(notification) {
265284
notification.unread = false;
266285
EventsService.markRead(notification.uid);
267-
countUnreadNotifications();
286+
render();
268287
},
269288
close: function() {
270289
drawer.drawerHidden = true;
@@ -277,7 +296,6 @@
277296
}
278297
});
279298

280-
281299
var initWatches = function() {
282300
if($routeParams.project) {
283301
reset();
@@ -307,7 +325,7 @@
307325
// event to signal the drawer to clear a notification
308326
rootScopeWatches.push($rootScope.$on('NotificationDrawerWrapper.clear', function(event, notification) {
309327
EventsService.markCleared(notification.uid);
310-
removeNotificationFromGroup(notification);
328+
remove(notification);
311329
drawer.countUnreadNotifications();
312330
}));
313331
};

Diff for: dist/scripts/scripts.js

+44-40
Original file line numberDiff line numberDiff line change
@@ -14581,44 +14581,48 @@ _.remove(t.notifications, {
1458114581
uid: e.uid,
1458214582
namespace: e.namespace
1458314583
});
14584-
}), delete v[r.project][e.uid];
14584+
});
1458514585
}, P = function(e) {
14586-
return _.map(e, function(e) {
14587-
return {
14586+
v[r.project] && delete v[r.project][e.uid], g[r.project] && delete g[r.project][e.uid], j(e);
14587+
}, R = function() {
14588+
g[r.project] = {}, v[r.project] = {};
14589+
}, I = function(e) {
14590+
return _.reduce(e, function(e, t) {
14591+
return e[t.metadata.uid] = {
1458814592
actions: null,
14589-
uid: e.metadata.uid,
14590-
trackByID: e.metadata.uid,
14591-
unread: !c.isRead(e.metadata.uid),
14592-
type: e.type,
14593-
lastTimestamp: e.lastTimestamp,
14594-
firstTimestamp: e.firstTimestamp,
14595-
event: e
14596-
};
14597-
});
14598-
}, R = function(e) {
14593+
uid: t.metadata.uid,
14594+
trackByID: t.metadata.uid,
14595+
unread: !c.isRead(t.metadata.uid),
14596+
type: t.type,
14597+
lastTimestamp: t.lastTimestamp,
14598+
firstTimestamp: t.firstTimestamp,
14599+
event: t
14600+
}, e;
14601+
}, {});
14602+
}, E = function(e) {
1459914603
return _.reduce(e, function(e, t) {
1460014604
return c.isImportantAPIEvent(t) && !c.isCleared(t.metadata.uid) && (e[t.metadata.uid] = t), e;
1460114605
}, {});
14602-
}, I = function(e, t) {
14606+
}, T = function(e, t) {
1460314607
var n = r.project;
1460414608
return _.assign({}, e[n], t[n]);
14605-
}, E = function(e) {
14609+
}, N = function(e) {
1460614610
return _.orderBy(e, [ "event.lastTimestamp", "event.firstTimestamp" ], [ "desc", "desc" ]);
14607-
}, T = function() {
14611+
}, D = function() {
1460814612
o.$evalAsync(function() {
14609-
p.notificationGroups = [ C(r.project, E(I(g, v))) ], k();
14613+
p.notificationGroups = [ C(r.project, N(T(g, v))) ], k();
1461014614
});
14611-
}, N = function() {
14615+
}, A = function() {
1461214616
_.each(f, function(e) {
1461314617
e();
1461414618
}), f = [];
14615-
}, D = function() {
14619+
}, $ = function() {
1461614620
u && (s.unwatch(u), u = null);
14617-
}, A = function() {
14621+
}, B = function() {
1461814622
l && l(), l = null;
14619-
}, $ = function(e) {
14620-
g[r.project] = P(R(e.by("metadata.name"))), T();
14621-
}, B = function(e, t) {
14623+
}, L = function(e) {
14624+
g[r.project] = I(E(e.by("metadata.name"))), D();
14625+
}, U = function(e, t) {
1462214626
var n = t.namespace || r.project, a = t.id ? n + "/" + t.id : _.uniqueId("notification_") + Date.now();
1462314627
t.showInDrawer && !c.isCleared(a) && (v[n] = v[n] || {}, v[n][a] = {
1462414628
actions: t.actions,
@@ -14632,18 +14636,18 @@ isHTML: t.isHTML,
1463214636
details: t.details,
1463314637
namespace: n,
1463414638
links: t.links
14635-
}, T());
14636-
}, L = function(e, t) {
14637-
D(), e && (u = s.watch("events", {
14639+
}, D());
14640+
}, O = function(e, t) {
14641+
$(), e && (u = s.watch("events", {
1463814642
namespace: e
1463914643
}, _.debounce(t, 400), {
1464014644
skipDigest: !0
1464114645
}));
14642-
}, U = _.once(function(e, t) {
14643-
A(), l = o.$on("NotificationsService.onNotificationAdded", t);
14644-
}), O = function() {
14646+
}, F = _.once(function(e, t) {
14647+
B(), l = o.$on("NotificationsService.onNotificationAdded", t);
14648+
}), x = function() {
1464514649
S(r.project).then(function() {
14646-
L(r.project, $), U(r.project, B), y(r.project), T();
14650+
O(r.project, L), F(r.project, U), y(r.project), D();
1464714651
});
1464814652
};
1464914653
angular.extend(p, {
@@ -14660,22 +14664,22 @@ p.drawerHidden = !0;
1466014664
onMarkAllRead: function(e) {
1466114665
_.each(e.notifications, function(e) {
1466214666
e.unread = !1, c.markRead(e.uid);
14663-
}), T(), o.$emit("NotificationDrawerWrapper.onMarkAllRead");
14667+
}), D(), o.$emit("NotificationDrawerWrapper.onMarkAllRead");
1466414668
},
1466514669
onClearAll: function(e) {
1466614670
_.each(e.notifications, function(e) {
1466714671
e.unread = !1, c.markRead(e.uid), c.markCleared(e.uid);
14668-
}), g[r.project] = {}, v[r.project] = {}, T(), o.$emit("NotificationDrawerWrapper.onMarkAllRead");
14672+
}), R(), D(), o.$emit("NotificationDrawerWrapper.onMarkAllRead");
1466914673
},
1467014674
notificationGroups: [],
1467114675
headingInclude: "views/directives/notifications/header.html",
1467214676
notificationBodyInclude: "views/directives/notifications/notification-body.html",
1467314677
customScope: {
1467414678
clear: function(e, t, n) {
14675-
c.markCleared(e.uid), n.notifications.splice(t, 1), k();
14679+
c.markRead(e.uid), c.markCleared(e.uid), n.notifications.splice(t, 1), P(e), D();
1467614680
},
1467714681
markRead: function(e) {
14678-
e.unread = !1, c.markRead(e.uid), k();
14682+
e.unread = !1, c.markRead(e.uid), D();
1467914683
},
1468014684
close: function() {
1468114685
p.drawerHidden = !0;
@@ -14686,21 +14690,21 @@ e.onClick(), p.drawerHidden = !0;
1468614690
countUnreadNotifications: k
1468714691
}
1468814692
});
14689-
var F = function() {
14690-
r.project && O(), f.push(o.$on("$routeChangeSuccess", function(e, t, n) {
14691-
b(t, n) && (p.customScope.projectName = r.project, O());
14693+
var V = function() {
14694+
r.project && x(), f.push(o.$on("$routeChangeSuccess", function(e, t, n) {
14695+
b(t, n) && (p.customScope.projectName = r.project, x());
1469214696
})), f.push(o.$on("NotificationDrawerWrapper.toggle", function() {
1469314697
p.drawerHidden = !p.drawerHidden;
1469414698
})), f.push(o.$on("NotificationDrawerWrapper.hide", function() {
1469514699
p.drawerHidden = !0;
1469614700
})), f.push(o.$on("NotificationDrawerWrapper.clear", function(e, t) {
14697-
c.markCleared(t.uid), j(t), p.countUnreadNotifications();
14701+
c.markCleared(t.uid), P(t), p.countUnreadNotifications();
1469814702
}));
1469914703
};
1470014704
p.$onInit = function() {
14701-
d || m || F();
14705+
d || m || V();
1470214706
}, p.$onDestroy = function() {
14703-
A(), D(), N();
14707+
B(), $(), A();
1470414708
};
1470514709
} ]
1470614710
});

0 commit comments

Comments
 (0)