Skip to content

Commit f24d4fc

Browse files
Merge pull request #2346 from spadgett/ben-cleared-notifications
Automatic merge from submit-queue. Fix issue #2302: marking all notifications read can resurrect cleared notifications This is the same as #2318, but rebased on current master. @benjaminapetersen I've left you as the commit author
2 parents 417b53a + 57d0abd commit f24d4fc

File tree

2 files changed

+73
-51
lines changed

2 files changed

+73
-51
lines changed

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
};

dist/scripts/scripts.js

+44-40
Original file line numberDiff line numberDiff line change
@@ -14582,44 +14582,48 @@ _.remove(t.notifications, {
1458214582
uid: e.uid,
1458314583
namespace: e.namespace
1458414584
});
14585-
}), delete v[r.project][e.uid];
14585+
});
1458614586
}, P = function(e) {
14587-
return _.map(e, function(e) {
14588-
return {
14587+
v[r.project] && delete v[r.project][e.uid], g[r.project] && delete g[r.project][e.uid], j(e);
14588+
}, R = function() {
14589+
g[r.project] = {}, v[r.project] = {};
14590+
}, I = function(e) {
14591+
return _.reduce(e, function(e, t) {
14592+
return e[t.metadata.uid] = {
1458914593
actions: null,
14590-
uid: e.metadata.uid,
14591-
trackByID: e.metadata.uid,
14592-
unread: !c.isRead(e.metadata.uid),
14593-
type: e.type,
14594-
lastTimestamp: e.lastTimestamp,
14595-
firstTimestamp: e.firstTimestamp,
14596-
event: e
14597-
};
14598-
});
14599-
}, R = function(e) {
14594+
uid: t.metadata.uid,
14595+
trackByID: t.metadata.uid,
14596+
unread: !c.isRead(t.metadata.uid),
14597+
type: t.type,
14598+
lastTimestamp: t.lastTimestamp,
14599+
firstTimestamp: t.firstTimestamp,
14600+
event: t
14601+
}, e;
14602+
}, {});
14603+
}, E = function(e) {
1460014604
return _.reduce(e, function(e, t) {
1460114605
return c.isImportantAPIEvent(t) && !c.isCleared(t.metadata.uid) && (e[t.metadata.uid] = t), e;
1460214606
}, {});
14603-
}, I = function(e, t) {
14607+
}, T = function(e, t) {
1460414608
var n = r.project;
1460514609
return _.assign({}, e[n], t[n]);
14606-
}, E = function(e) {
14610+
}, N = function(e) {
1460714611
return _.orderBy(e, [ "event.lastTimestamp", "event.firstTimestamp" ], [ "desc", "desc" ]);
14608-
}, T = function() {
14612+
}, D = function() {
1460914613
o.$evalAsync(function() {
14610-
p.notificationGroups = [ C(r.project, E(I(g, v))) ], k();
14614+
p.notificationGroups = [ C(r.project, N(T(g, v))) ], k();
1461114615
});
14612-
}, N = function() {
14616+
}, A = function() {
1461314617
_.each(f, function(e) {
1461414618
e();
1461514619
}), f = [];
14616-
}, D = function() {
14620+
}, $ = function() {
1461714621
u && (s.unwatch(u), u = null);
14618-
}, A = function() {
14622+
}, B = function() {
1461914623
l && l(), l = null;
14620-
}, $ = function(e) {
14621-
g[r.project] = P(R(e.by("metadata.name"))), T();
14622-
}, B = function(e, t) {
14624+
}, L = function(e) {
14625+
g[r.project] = I(E(e.by("metadata.name"))), D();
14626+
}, U = function(e, t) {
1462314627
var n = t.namespace || r.project, a = t.id ? n + "/" + t.id : _.uniqueId("notification_") + Date.now();
1462414628
t.showInDrawer && !c.isCleared(a) && (v[n] = v[n] || {}, v[n][a] = {
1462514629
actions: t.actions,
@@ -14633,18 +14637,18 @@ isHTML: t.isHTML,
1463314637
details: t.details,
1463414638
namespace: n,
1463514639
links: t.links
14636-
}, T());
14637-
}, L = function(e, t) {
14638-
D(), e && (u = s.watch("events", {
14640+
}, D());
14641+
}, O = function(e, t) {
14642+
$(), e && (u = s.watch("events", {
1463914643
namespace: e
1464014644
}, _.debounce(t, 400), {
1464114645
skipDigest: !0
1464214646
}));
14643-
}, U = _.once(function(e, t) {
14644-
A(), l = o.$on("NotificationsService.onNotificationAdded", t);
14645-
}), O = function() {
14647+
}, F = _.once(function(e, t) {
14648+
B(), l = o.$on("NotificationsService.onNotificationAdded", t);
14649+
}), x = function() {
1464614650
S(r.project).then(function() {
14647-
L(r.project, $), U(r.project, B), y(r.project), T();
14651+
O(r.project, L), F(r.project, U), y(r.project), D();
1464814652
});
1464914653
};
1465014654
angular.extend(p, {
@@ -14661,22 +14665,22 @@ p.drawerHidden = !0;
1466114665
onMarkAllRead: function(e) {
1466214666
_.each(e.notifications, function(e) {
1466314667
e.unread = !1, c.markRead(e.uid);
14664-
}), T(), o.$emit("NotificationDrawerWrapper.onMarkAllRead");
14668+
}), D(), o.$emit("NotificationDrawerWrapper.onMarkAllRead");
1466514669
},
1466614670
onClearAll: function(e) {
1466714671
_.each(e.notifications, function(e) {
1466814672
e.unread = !1, c.markRead(e.uid), c.markCleared(e.uid);
14669-
}), g[r.project] = {}, v[r.project] = {}, T(), o.$emit("NotificationDrawerWrapper.onMarkAllRead");
14673+
}), R(), D(), o.$emit("NotificationDrawerWrapper.onMarkAllRead");
1467014674
},
1467114675
notificationGroups: [],
1467214676
headingInclude: "views/directives/notifications/header.html",
1467314677
notificationBodyInclude: "views/directives/notifications/notification-body.html",
1467414678
customScope: {
1467514679
clear: function(e, t, n) {
14676-
c.markCleared(e.uid), n.notifications.splice(t, 1), k();
14680+
c.markRead(e.uid), c.markCleared(e.uid), n.notifications.splice(t, 1), P(e), D();
1467714681
},
1467814682
markRead: function(e) {
14679-
e.unread = !1, c.markRead(e.uid), k();
14683+
e.unread = !1, c.markRead(e.uid), D();
1468014684
},
1468114685
close: function() {
1468214686
p.drawerHidden = !0;
@@ -14687,21 +14691,21 @@ e.onClick(), p.drawerHidden = !0;
1468714691
countUnreadNotifications: k
1468814692
}
1468914693
});
14690-
var F = function() {
14691-
r.project && O(), f.push(o.$on("$routeChangeSuccess", function(e, t, n) {
14692-
b(t, n) && (p.customScope.projectName = r.project, O());
14694+
var V = function() {
14695+
r.project && x(), f.push(o.$on("$routeChangeSuccess", function(e, t, n) {
14696+
b(t, n) && (p.customScope.projectName = r.project, x());
1469314697
})), f.push(o.$on("NotificationDrawerWrapper.toggle", function() {
1469414698
p.drawerHidden = !p.drawerHidden;
1469514699
})), f.push(o.$on("NotificationDrawerWrapper.hide", function() {
1469614700
p.drawerHidden = !0;
1469714701
})), f.push(o.$on("NotificationDrawerWrapper.clear", function(e, t) {
14698-
c.markCleared(t.uid), j(t), p.countUnreadNotifications();
14702+
c.markCleared(t.uid), P(t), p.countUnreadNotifications();
1469914703
}));
1470014704
};
1470114705
p.$onInit = function() {
14702-
d || m || F();
14706+
d || m || V();
1470314707
}, p.$onDestroy = function() {
14704-
A(), D(), N();
14708+
B(), $(), A();
1470514709
};
1470614710
} ]
1470714711
});

0 commit comments

Comments
 (0)