Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/notification.js

Issue 29370562: [adblockpluscore] Issue 4762 - Added "relentless" notification that shows up in intervals (Closed)
Patch Set: Addressed review comments Created Jan. 6, 2017, 2:08 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/notification.js
diff --git a/lib/notification.js b/lib/notification.js
index 51ed5091da72b4ceb6a87d21cd60a6e7fd1af124..6f7d4c2b200787afccacc3cd3160b0906295f5db 100644
--- a/lib/notification.js
+++ b/lib/notification.js
@@ -33,7 +33,8 @@ var EXPIRATION_INTERVAL = 1 * MILLIS_IN_DAY;
var TYPE = {
information: 0,
question: 1,
- critical: 2
+ relentless: 2,
+ critical: 3
};
var showListeners = [];
@@ -208,9 +209,21 @@ var Notification = exports.Notification =
{
if (typeof notification.type === "undefined" || notification.type !== "critical")
{
- let shown = Prefs.notificationdata.shown;
- if (shown instanceof Array && shown.indexOf(notification.id) != -1)
- continue;
+ let shown;
+ if (typeof Prefs.notificationdata.shown == "object")
+ shown = Prefs.notificationdata.shown[notification.id];
+
+ if (typeof shown != "undefined")
+ {
+ if (typeof notification.interval == "number")
+ {
+ if (shown + notification.interval > Date.now())
+ continue;
+ }
+ else if (shown)
+ continue;
+ }
+
if (Prefs.notifications_ignoredcategories.indexOf("*") != -1)
continue;
}
@@ -287,14 +300,22 @@ var Notification = exports.Notification =
*/
markAsShown: function(id)
{
- var data = Prefs.notificationdata;
+ let now = Date.now();
+ let data = Prefs.notificationdata;
- if (!(data.shown instanceof Array))
- data.shown = [];
- if (data.shown.indexOf(id) != -1)
- return;
+ if (data.shown instanceof Array)
+ {
+ let newShown = {};
+ for (let old_id of data.shown)
+ newShown[old_id] = now;
+ data.shown = newShown;
+ }
+
+ if (!(typeof data.shown == "object"))
Sebastian Noack 2017/01/06 14:17:02 How about |typeof != "object"|?
wspee 2017/01/06 14:35:54 Done.
+ data.shown = {};
+
+ data.shown[id] = now;
- data.shown.push(id);
saveNotificationData();
},
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld