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

Unified Diff: lib/notification.js

Issue 5270660880269312: Issue 2192 - Added notification opt-out mechanism (Core) (Closed)
Patch Set: Created April 13, 2015, 3:42 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 | « defaults/prefs.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/notification.js
===================================================================
--- a/lib/notification.js
+++ b/lib/notification.js
@@ -191,9 +191,12 @@
let notificationToShow = null;
for (let notification of notifications)
{
- if ((typeof notification.type === "undefined" || notification.type !== "critical")
- && Prefs.notificationdata.shown.indexOf(notification.id) !== -1)
- continue;
+ if (typeof notification.type === "undefined" || notification.type !== "critical")
+ {
+ if (Prefs.notificationdata.shown.indexOf(notification.id) !== -1
+ || Prefs.notifications_ignoredcategories.indexOf("*") !== -1)
+ continue;
+ }
if (typeof url === "string" || notification.urlFilters instanceof Array)
{
@@ -332,6 +335,27 @@
let questionListeners = listeners[id];
for (let listener of questionListeners)
listener(approved);
+ },
+
+ /**
+ * Toggles whether notifications of a specific category should be ignored
+ * @param {String} category notification category identifier
+ * @param {Boolean} [forceValue] force specified value
+ */
+ toggleIgnoreCategory: function(category, forceValue)
+ {
+ let categories = Prefs.notifications_ignoredcategories;
+ let index = categories.indexOf(category);
+ if (index == -1 && forceValue !== false)
+ {
+ categories.push(category);
+ Prefs.notifications_showui = true;
+ }
+ else if (index != -1 && forceValue !== true)
+ categories.splice(index, 1);
+
+ // HACK: JSON values aren't saved unless they are assigned a different object.
+ Prefs.notifications_ignoredcategories = JSON.parse(JSON.stringify(categories));
}
};
Notification.init();
« no previous file with comments | « defaults/prefs.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld