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

Unified 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.
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 | « no previous file | test/notification.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/notification.js
diff --git a/lib/notification.js b/lib/notification.js
index 311e4e881389424155f1a61a3c351a3f69cfaf88..c499b30da0eecba90b62b0b6c8738dcf4c56264e 100644
--- a/lib/notification.js
+++ b/lib/notification.js
@@ -200,17 +200,6 @@ let Notification = exports.Notification =
*/
_getNextToShow(url)
{
- function checkTarget(target, parameter, name, version)
- {
- let minVersionKey = parameter + "MinVersion";
- let maxVersionKey = parameter + "MaxVersion";
- return !((parameter in target && target[parameter] != name) ||
- (minVersionKey in target &&
- Services.vc.compare(version, target[minVersionKey]) < 0) ||
- (maxVersionKey in target &&
- Services.vc.compare(version, target[maxVersionKey]) > 0));
- }
-
let remoteData = [];
if (typeof Prefs.notificationdata.data == "object" &&
Prefs.notificationdata.data.notifications instanceof Array)
@@ -224,6 +213,30 @@ let Notification = exports.Notification =
const {addonName, addonVersion, application,
applicationVersion, platform, platformVersion} = require("info");
+
+ let targetChecks = {
+ extension: v => v == addonName,
+ extensionMinVersion:
+ v => Services.vc.compare(addonVersion, v) >= 0,
+ extensionMaxVersion:
+ v => Services.vc.compare(addonVersion, v) <= 0,
+ application: v => v == application,
+ applicationMinVersion:
+ v => Services.vc.compare(applicationVersion, v) >= 0,
+ applicationMaxVersion:
+ v => Services.vc.compare(applicationVersion, v) <= 0,
+ platform: v => v == platform,
+ platformMinVersion:
+ v => Services.vc.compare(platformVersion, v) >= 0,
+ platformMaxVersion:
+ v => Services.vc.compare(platformVersion, v) <= 0,
+ blockedTotalMin: v => Prefs.show_statsinpopup &&
+ Prefs.blocked_total >= v,
+ blockedTotalMax: v => Prefs.show_statsinpopup &&
+ Prefs.blocked_total <= v,
+ locales: v => v.includes(Utils.appLocale)
+ };
+
let notificationToShow = null;
for (let notification of notifications)
{
@@ -289,19 +302,21 @@ let Notification = exports.Notification =
if (notification.targets instanceof Array)
{
let match = false;
+
for (let target of notification.targets)
{
- if (checkTarget(target, "extension", addonName, addonVersion) &&
- checkTarget(target, "application", application,
- applicationVersion) &&
- checkTarget(target, "platform", platform, platformVersion))
+ if (Object.keys(target).every(key =>
+ targetChecks.hasOwnProperty(key) &&
+ targetChecks[key](target[key])))
{
match = true;
break;
}
}
if (!match)
+ {
continue;
+ }
}
if (!notificationToShow ||
« 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