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

Side by Side 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.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « defaults/prefs.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 } 184 }
185 185
186 let notifications = localData.concat(remoteData); 186 let notifications = localData.concat(remoteData);
187 if (notifications.length === 0) 187 if (notifications.length === 0)
188 return null; 188 return null;
189 189
190 let {addonName, addonVersion, application, applicationVersion, platform, pla tformVersion} = require("info"); 190 let {addonName, addonVersion, application, applicationVersion, platform, pla tformVersion} = require("info");
191 let notificationToShow = null; 191 let notificationToShow = null;
192 for (let notification of notifications) 192 for (let notification of notifications)
193 { 193 {
194 if ((typeof notification.type === "undefined" || notification.type !== "cr itical") 194 if (typeof notification.type === "undefined" || notification.type !== "cri tical")
195 && Prefs.notificationdata.shown.indexOf(notification.id) !== -1) 195 {
196 continue; 196 if (Prefs.notificationdata.shown.indexOf(notification.id) !== -1
197 || Prefs.notifications_ignoredcategories.indexOf("*") !== -1)
198 continue;
199 }
197 200
198 if (typeof url === "string" || notification.urlFilters instanceof Array) 201 if (typeof url === "string" || notification.urlFilters instanceof Array)
199 { 202 {
200 if (typeof url === "string" && notification.urlFilters instanceof Array) 203 if (typeof url === "string" && notification.urlFilters instanceof Array)
201 { 204 {
202 let matcher = new Matcher(); 205 let matcher = new Matcher();
203 for (let urlFilter of notification.urlFilters) 206 for (let urlFilter of notification.urlFilters)
204 matcher.add(Filter.fromText(urlFilter)); 207 matcher.add(Filter.fromText(urlFilter));
205 if (!matcher.matchesAny(url, "DOCUMENT", url)) 208 if (!matcher.matchesAny(url, "DOCUMENT", url))
206 continue; 209 continue;
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 * @param {String} id notification ID 328 * @param {String} id notification ID
326 * @param {Boolean} approved indicator whether notification has been approved or not 329 * @param {Boolean} approved indicator whether notification has been approved or not
327 */ 330 */
328 triggerQuestionListeners: function(id, approved) 331 triggerQuestionListeners: function(id, approved)
329 { 332 {
330 if (!(id in listeners)) 333 if (!(id in listeners))
331 return; 334 return;
332 let questionListeners = listeners[id]; 335 let questionListeners = listeners[id];
333 for (let listener of questionListeners) 336 for (let listener of questionListeners)
334 listener(approved); 337 listener(approved);
338 },
339
340 /**
341 * Toggles whether notifications of a specific category should be ignored
342 * @param {String} category notification category identifier
343 * @param {Boolean} [forceValue] force specified value
344 */
345 toggleIgnoreCategory: function(category, forceValue)
346 {
347 let categories = Prefs.notifications_ignoredcategories;
348 let index = categories.indexOf(category);
349 if (index == -1 && forceValue !== false)
350 {
351 categories.push(category);
352 Prefs.notifications_showui = true;
353 }
354 else if (index != -1 && forceValue !== true)
355 categories.splice(index, 1);
356
357 // HACK: JSON values aren't saved unless they are assigned a different objec t.
358 Prefs.notifications_ignoredcategories = JSON.parse(JSON.stringify(categories ));
335 } 359 }
336 }; 360 };
337 Notification.init(); 361 Notification.init();
OLDNEW
« 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