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

Side by Side Diff: lib/notification.js

Issue 29501607: Issue 5459 - Add support to show a notification based on the number of ads blocked (Closed)
Patch Set: Show notification for blockedTotal* only if Prefs.show_statsinpopup Created Aug. 24, 2017, 4:35 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 | « no previous file | test/notification.js » ('j') | 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-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 showListeners.splice(index, 1); 193 showListeners.splice(index, 1);
194 }, 194 },
195 195
196 /** 196 /**
197 * Determines which notification is to be shown next. 197 * Determines which notification is to be shown next.
198 * @param {string} url URL to match notifications to (optional) 198 * @param {string} url URL to match notifications to (optional)
199 * @return {Object} notification to be shown, or null if there is none 199 * @return {Object} notification to be shown, or null if there is none
200 */ 200 */
201 _getNextToShow(url) 201 _getNextToShow(url)
202 { 202 {
203 function checkTarget(target, parameter, name, version)
204 {
205 let minVersionKey = parameter + "MinVersion";
206 let maxVersionKey = parameter + "MaxVersion";
207 return !((parameter in target && target[parameter] != name) ||
208 (minVersionKey in target &&
209 Services.vc.compare(version, target[minVersionKey]) < 0) ||
210 (maxVersionKey in target &&
211 Services.vc.compare(version, target[maxVersionKey]) > 0));
212 }
213
214 let remoteData = []; 203 let remoteData = [];
215 if (typeof Prefs.notificationdata.data == "object" && 204 if (typeof Prefs.notificationdata.data == "object" &&
216 Prefs.notificationdata.data.notifications instanceof Array) 205 Prefs.notificationdata.data.notifications instanceof Array)
217 { 206 {
218 remoteData = Prefs.notificationdata.data.notifications; 207 remoteData = Prefs.notificationdata.data.notifications;
219 } 208 }
220 209
221 let notifications = localData.concat(remoteData); 210 let notifications = localData.concat(remoteData);
222 if (notifications.length === 0) 211 if (notifications.length === 0)
223 return null; 212 return null;
224 213
225 const {addonName, addonVersion, application, 214 const {addonName, addonVersion, application,
226 applicationVersion, platform, platformVersion} = require("info"); 215 applicationVersion, platform, platformVersion} = require("info");
216
217 let targetChecks = {
218 extension: v => v == addonName,
219 extensionMinVersion:
220 v => Services.vc.compare(addonVersion, v) >= 0,
221 extensionMaxVersion:
222 v => Services.vc.compare(addonVersion, v) <= 0,
223 application: v => v == application,
224 applicationMinVersion:
225 v => Services.vc.compare(applicationVersion, v) >= 0,
226 applicationMaxVersion:
227 v => Services.vc.compare(applicationVersion, v) <= 0,
228 platform: v => v == platform,
229 platformMinVersion:
230 v => Services.vc.compare(platformVersion, v) >= 0,
231 platformMaxVersion:
232 v => Services.vc.compare(platformVersion, v) <= 0,
233 blockedTotalMin: v => Prefs.show_statsinpopup &&
234 Prefs.blocked_total >= v,
235 blockedTotalMax: v => Prefs.show_statsinpopup &&
236 Prefs.blocked_total <= v,
237 locales: v => v.includes(Utils.appLocale)
238 };
239
227 let notificationToShow = null; 240 let notificationToShow = null;
228 for (let notification of notifications) 241 for (let notification of notifications)
229 { 242 {
230 if (typeof notification.type === "undefined" || 243 if (typeof notification.type === "undefined" ||
231 notification.type !== "critical") 244 notification.type !== "critical")
232 { 245 {
233 let shown; 246 let shown;
234 if (typeof Prefs.notificationdata.shown == "object") 247 if (typeof Prefs.notificationdata.shown == "object")
235 shown = Prefs.notificationdata.shown[notification.id]; 248 shown = Prefs.notificationdata.shown[notification.id];
236 249
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 continue; 295 continue;
283 } 296 }
284 } 297 }
285 else 298 else
286 continue; 299 continue;
287 } 300 }
288 301
289 if (notification.targets instanceof Array) 302 if (notification.targets instanceof Array)
290 { 303 {
291 let match = false; 304 let match = false;
305
292 for (let target of notification.targets) 306 for (let target of notification.targets)
293 { 307 {
294 if (checkTarget(target, "extension", addonName, addonVersion) && 308 if (Object.keys(target).every(key =>
295 checkTarget(target, "application", application, 309 targetChecks.hasOwnProperty(key) &&
296 applicationVersion) && 310 targetChecks[key](target[key])))
297 checkTarget(target, "platform", platform, platformVersion))
298 { 311 {
299 match = true; 312 match = true;
300 break; 313 break;
301 } 314 }
302 } 315 }
303 if (!match) 316 if (!match)
317 {
304 continue; 318 continue;
319 }
305 } 320 }
306 321
307 if (!notificationToShow || 322 if (!notificationToShow ||
308 getNumericalSeverity(notification) > 323 getNumericalSeverity(notification) >
309 getNumericalSeverity(notificationToShow)) 324 getNumericalSeverity(notificationToShow))
310 notificationToShow = notification; 325 notificationToShow = notification;
311 } 326 }
312 327
313 return notificationToShow; 328 return notificationToShow;
314 }, 329 },
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 else if (index != -1 && forceValue !== true) 481 else if (index != -1 && forceValue !== true)
467 categories.splice(index, 1); 482 categories.splice(index, 1);
468 483
469 // HACK: JSON values aren't saved unless they are assigned a 484 // HACK: JSON values aren't saved unless they are assigned a
470 // different object. 485 // different object.
471 Prefs.notifications_ignoredcategories = 486 Prefs.notifications_ignoredcategories =
472 JSON.parse(JSON.stringify(categories)); 487 JSON.parse(JSON.stringify(categories));
473 } 488 }
474 }; 489 };
475 Notification.init(); 490 Notification.init();
OLDNEW
« no previous file with comments | « no previous file | test/notification.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld