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: Made blockedTotal and locales part of targets Created Aug. 21, 2017, 3:10 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 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 { 206 {
207 remoteData = Prefs.notificationdata.data.notifications; 207 remoteData = Prefs.notificationdata.data.notifications;
208 } 208 }
209 209
210 let notifications = localData.concat(remoteData); 210 let notifications = localData.concat(remoteData);
211 if (notifications.length === 0) 211 if (notifications.length === 0)
212 return null; 212 return null;
213 213
214 const {addonName, addonVersion, application, 214 const {addonName, addonVersion, application,
215 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
216 let notificationToShow = null; 240 let notificationToShow = null;
217 for (let notification of notifications) 241 for (let notification of notifications)
218 { 242 {
219 if (typeof notification.type === "undefined" || 243 if (typeof notification.type === "undefined" ||
220 notification.type !== "critical") 244 notification.type !== "critical")
221 { 245 {
222 let shown; 246 let shown;
223 if (typeof Prefs.notificationdata.shown == "object") 247 if (typeof Prefs.notificationdata.shown == "object")
224 shown = Prefs.notificationdata.shown[notification.id]; 248 shown = Prefs.notificationdata.shown[notification.id];
225 249
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 { 294 {
271 continue; 295 continue;
272 } 296 }
273 } 297 }
274 else 298 else
275 continue; 299 continue;
276 } 300 }
277 301
278 if (notification.targets instanceof Array) 302 if (notification.targets instanceof Array)
279 { 303 {
280 let checks = new Map([ 304 let match = false;
Wladimir Palant 2017/08/22 07:54:58 This shouldn't be set inside the loop, we'll get n
wspee 2017/08/23 10:12:20 Acknowledged.
281 ["extension", v => v == addonName], 305
282 ["extensionMinVersion",
283 v => Services.vc.compare(addonVersion, v) >= 0],
284 ["extensionMaxVersion",
285 v => Services.vc.compare(addonVersion, v) <= 0],
286 ["application", v => v == application],
287 ["applicationMinVersion",
288 v => Services.vc.compare(applicationVersion, v) >= 0],
289 ["applicationMaxVersion",
290 v => Services.vc.compare(applicationVersion, v) <= 0],
291 ["platform", v => v == platform],
292 ["platformMinVersion",
293 v => Services.vc.compare(platformVersion, v) >= 0],
294 ["platformMaxVersion",
295 v => Services.vc.compare(platformVersion, v) <= 0],
296 ["blockedTotalMax", v => Prefs.blocked_total <= parseInt(v, 10)],
297 ["blockedTotalMin", v => Prefs.blocked_total >= parseInt(v, 10)],
Wladimir Palant 2017/08/22 07:54:58 Why parseInt() here? I'd say that the backend is s
wspee 2017/08/23 10:12:19 Acknowledged. Thanks for pointing that out, the b
298 ["locales", v => v.indexOf(Utils.appLocale) != -1]
299 ]);
300
301 let match = true;
Wladimir Palant 2017/08/22 07:54:58 I'd say that this should be initialized with false
wspee 2017/08/23 10:12:20 Acknowledged.
302 for (let target of notification.targets) 306 for (let target of notification.targets)
303 { 307 {
304 match = true; 308 if (Object.keys(target).every(key =>
305 for (let key of Object.keys(target)) 309 targetChecks.hasOwnProperty(key) &&
Wladimir Palant 2017/08/22 07:54:58 How about making this more compact and closer to t
wspee 2017/08/23 10:12:20 Acknowledged.
310 targetChecks[key](target[key])))
306 { 311 {
307 let value = target[key]; 312 match = true;
308 let check = checks.get(key);
309
310 if (!check || !check(value))
wspee 2017/08/21 15:18:21 This implementation no longer ignores unknown targ
Wladimir Palant 2017/08/22 07:54:58 Agreed.
wspee 2017/08/23 10:12:20 See https://issues.adblockplus.org/ticket/5558#tic
311 {
312 match = false;
313 }
314 }
315 if (match)
316 {
317 break; 313 break;
318 } 314 }
319 } 315 }
320 if (!match) 316 if (!match)
321 { 317 {
322 continue; 318 continue;
323 } 319 }
324 } 320 }
325 321
326 if (!notificationToShow || 322 if (!notificationToShow ||
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 else if (index != -1 && forceValue !== true) 481 else if (index != -1 && forceValue !== true)
486 categories.splice(index, 1); 482 categories.splice(index, 1);
487 483
488 // HACK: JSON values aren't saved unless they are assigned a 484 // HACK: JSON values aren't saved unless they are assigned a
489 // different object. 485 // different object.
490 Prefs.notifications_ignoredcategories = 486 Prefs.notifications_ignoredcategories =
491 JSON.parse(JSON.stringify(categories)); 487 JSON.parse(JSON.stringify(categories));
492 } 488 }
493 }; 489 };
494 Notification.init(); 490 Notification.init();
LEFTRIGHT

Powered by Google App Engine
This is Rietveld