Index: lib/notification.js |
diff --git a/lib/notification.js b/lib/notification.js |
index 311e4e881389424155f1a61a3c351a3f69cfaf88..594863110bb9cd20cdad56672a0b72baf624d263 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,28 @@ 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.blocked_total >= v, |
+ blockedTotalMax: v => Prefs.blocked_total <= v, |
+ locales: v => v.includes(Utils.appLocale) |
+ }; |
+ |
let notificationToShow = null; |
for (let notification of notifications) |
{ |
@@ -289,19 +300,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 || |