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

Delta Between Two Patch Sets: lib/notification.js

Issue 29501607: Issue 5459 - Add support to show a notification based on the number of ads blocked (Closed)
Left Patch Set: Update commit message Created July 31, 2017, 3:19 p.m.
Right 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | test/notification.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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
307 if (typeof notification.blocked_total_min == 'number' &&
308 (typeof Prefs.blocked_total != 'number' ||
309 notification.blocked_total_min > Prefs.blocked_total))
310 continue
Wladimir Palant 2017/08/15 10:31:21 Nit: please run ESLint. There should be a semicolo
wspee 2017/08/21 15:18:21 Of course, sorry forgot to use ESLint.
311
312 if (typeof notification.blocked_total_max == 'number' &&
313 (typeof Prefs.blocked_total != 'number' ||
314 notification.blocked_total_max < Prefs.blocked_total))
315 continue
Wladimir Palant 2017/08/15 10:31:21 We should use camelCase for consistency. Also, we
wspee 2017/08/21 15:18:21 I implemented the syntax from the issue (#5457), t
316 321
317 if (!notificationToShow || 322 if (!notificationToShow ||
318 getNumericalSeverity(notification) > 323 getNumericalSeverity(notification) >
319 getNumericalSeverity(notificationToShow)) 324 getNumericalSeverity(notificationToShow))
320 notificationToShow = notification; 325 notificationToShow = notification;
321 } 326 }
322 327
323 return notificationToShow; 328 return notificationToShow;
324 }, 329 },
325 330
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 else if (index != -1 && forceValue !== true) 481 else if (index != -1 && forceValue !== true)
477 categories.splice(index, 1); 482 categories.splice(index, 1);
478 483
479 // HACK: JSON values aren't saved unless they are assigned a 484 // HACK: JSON values aren't saved unless they are assigned a
480 // different object. 485 // different object.
481 Prefs.notifications_ignoredcategories = 486 Prefs.notifications_ignoredcategories =
482 JSON.parse(JSON.stringify(categories)); 487 JSON.parse(JSON.stringify(categories));
483 } 488 }
484 }; 489 };
485 Notification.init(); 490 Notification.init();
LEFTRIGHT

Powered by Google App Engine
This is Rietveld