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

Unified Diff: lib/notification.js

Issue 11163031: Notifications: implemented better target checks (Closed)
Patch Set: Created July 19, 2013, 2:42 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 | « .hgsubstate ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/notification.js
===================================================================
--- a/lib/notification.js
+++ b/lib/notification.js
@@ -128,45 +128,60 @@ let Notification = exports.Notification
/**
* Determines which notification is to be shown next.
* @param {Array of Object} notifications active notifications
* @return {Object} notification to be shown, or null if there is none
*/
getNextToShow: function()
{
+ 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));
+
+ }
+
if (typeof Prefs.notificationdata.data != "object" || !(Prefs.notificationdata.data.notifications instanceof Array))
return null;
if (!(Prefs.notificationdata.shown instanceof Array))
{
Prefs.notificationdata.shown = [];
saveNotificationData();
}
- let {application, addonVersion} = require("info");
+ let {addonName, addonVersion, application, applicationVersion, platform, platformVersion} = require("info");
let notifications = Prefs.notificationdata.data.notifications;
let notificationToShow = null;
for each (let notification in notifications)
{
if ((typeof notification.severity == "undefined" || notification.severity === "information")
&& Prefs.notificationdata.shown.indexOf(notification.id) !== -1)
continue;
- if (notification.platforms instanceof Array
- && notification.platforms.indexOf(application) === -1)
- continue;
-
- if ("minVersion" in notification
- && Services.vc.compare(addonVersion, notification.minVersion) < 0)
- continue;
-
- if ("maxVersion" in notification
- && Services.vc.compare(addonVersion, notification.maxVersion) > 0)
- continue;
+ if (notification.targets instanceof Array)
+ {
+ let match = false;
+ for each (let target in notification.targets)
+ {
+ if (checkTarget(target, "extension", addonName, addonVersion) &&
+ checkTarget(target, "application", application, applicationVersion) &&
+ checkTarget(target, "platform", platform, platformVersion))
+ {
+ match = true;
+ break;
+ }
+ }
+ if (!match)
+ continue;
+ }
if (!notificationToShow
|| getNumericalSeverity(notification) > getNumericalSeverity(notificationToShow))
notificationToShow = notification;
}
if (notificationToShow && "id" in notificationToShow)
{
« no previous file with comments | « .hgsubstate ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld