| Index: lib/notification.js |
| =================================================================== |
| --- a/lib/notification.js |
| +++ b/lib/notification.js |
| @@ -62,12 +62,25 @@ |
| return translations[defaultLocale]; |
| } |
| +function initNotificationMatcher(notification) |
| +{ |
| + if ("_matcher" in notification || !(notification.urlFilters instanceof Array)) |
| + return; |
| + |
| + let matcher = new Matcher(); |
| + for (let urlFilter of notification.urlFilters) |
| + matcher.add(Filter.fromText(urlFilter)); |
| + matcher.toJSON = () => {}; |
|
sergei
2018/01/03 11:12:22
This is not exactly how it's said in the issue "No
Thomas Greiner
2018/01/11 18:18:19
Fortunately, we can now use `Symbol` instead so th
kzar
2018/01/12 12:27:17
Acknowledged.
|
| + notification._matcher = matcher; |
| +} |
| + |
| /** |
| * The object providing actual downloading functionality. |
| * @type Downloader |
| */ |
| let downloader = null; |
| let localData = []; |
| +let remoteData = []; |
|
sergei
2018/01/03 11:12:22
Could you please add a comment that localData and
Thomas Greiner
2018/01/11 18:18:19
Yep, will do.
|
| /** |
| * Regularly fetches notifications and decides which to show. |
| @@ -80,6 +93,14 @@ |
| */ |
| init: function() |
| { |
| + let notificationdata = Prefs.notificationdata.data; |
| + if (notificationdata) |
| + { |
| + for (let notification of notificationdata.notifications) |
| + initNotificationMatcher(notification); |
| + remoteData = notificationdata.notifications; |
| + } |
| + |
| downloader = new Downloader(this._getDownloadables.bind(this), INITIAL_DELAY, CHECK_INTERVAL); |
| onShutdown.add(function() |
| { |
| @@ -131,7 +152,9 @@ |
| notification.type = notification.severity; |
| delete notification.severity; |
| } |
| + initNotificationMatcher(notification); |
| } |
| + remoteData = data.notifications; |
|
sergei
2018/01/03 11:12:22
It's a bit theoretical but IMO it can be a technic
kzar
2018/01/04 17:04:09
Yea, I don't think these changes are necessary now
Thomas Greiner
2018/01/11 18:18:19
Good point. I don't remember why I made this chang
|
| Prefs.notificationdata.data = data; |
|
sergei
2018/01/03 11:12:22
Despite it's not directly a part of this issue, sh
kzar
2018/01/04 17:04:09
Hmm, I'm not too familiar with this code but I thi
Thomas Greiner
2018/01/11 18:18:19
By overriding existing notifications we can contro
|
| } |
| catch (e) |
| @@ -170,10 +193,6 @@ |
| (maxVersionKey in target && Services.vc.compare(version, target[maxVersionKey]) > 0)); |
| } |
| - let remoteData = []; |
| - if (typeof Prefs.notificationdata.data == "object" && Prefs.notificationdata.data.notifications instanceof Array) |
| - remoteData = Prefs.notificationdata.data.notifications; |
| - |
| if (!(Prefs.notificationdata.shown instanceof Array)) |
| { |
| Prefs.notificationdata.shown = []; |
| @@ -192,14 +211,11 @@ |
| && Prefs.notificationdata.shown.indexOf(notification.id) !== -1) |
|
kzar
2018/01/04 17:04:09
We can use .includes(notification.id) these days (
|
| continue; |
| - if (typeof url === "string" || notification.urlFilters instanceof Array) |
|
kzar
2018/01/04 17:04:09
IMO this code should instead be replaced with a ca
Thomas Greiner
2018/01/11 18:18:19
I agree that splitting that off into its own funct
kzar
2018/01/12 12:27:17
Acknowledged.
|
| + if (typeof url === "string" || "_matcher" in notification) |
| { |
| - if (typeof url === "string" && notification.urlFilters instanceof Array) |
| + if (typeof url === "string" && "_matcher" in notification) |
| { |
| - let matcher = new Matcher(); |
| - for (let urlFilter of notification.urlFilters) |
| - matcher.add(Filter.fromText(urlFilter)); |
| - if (!matcher.matchesAny(url, "DOCUMENT", url)) |
| + if (!notification._matcher.matchesAny(url, "DOCUMENT", url)) |
| continue; |
| } |
| else |
| @@ -278,7 +294,10 @@ |
| addNotification: function(notification) |
| { |
| if (localData.indexOf(notification) == -1) |
| + { |
| + initNotificationMatcher(notification); |
| localData.push(notification); |
| + } |
| }, |
| /** |