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

Unified Diff: lib/api.js

Issue 29366747: Issue 4657 - Add Acceptable Ads API (Closed)
Patch Set: Created Dec. 2, 2016, 4:27 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
Index: lib/api.js
diff --git a/lib/api.js b/lib/api.js
index ca656b898f6680637d15e84a030a5c8b02986738..bee771687b068b1320505030816bcaa904ddb382 100644
--- a/lib/api.js
+++ b/lib/api.js
@@ -28,6 +28,13 @@ var API = (function()
var checkForUpdates = require("updater").checkForUpdates;
var Notification = require("notification").Notification;
+ // returns first element of the array that satifies predicate.
sergei 2016/12/02 16:36:06 Should I move it into utils.js or extend Array.pro
sergei 2016/12/02 16:38:02 I meant extend in compat.js. The link is https://
Eric 2016/12/05 14:40:58 At the point of use, it would be better to use the
sergei 2017/03/17 15:55:25 Done.
+ var find = function (array, pred) {
+ for (var i = 0; i < array.length; ++i)
+ if (pred(array[i]))
+ return array[i];
+ };
+
return {
getFilterFromText: function(text)
{
@@ -137,6 +144,36 @@ var API = (function()
return result;
},
+ isAASubscription: function(subscription)
+ {
+ return subscription.url == Prefs.subscriptions_exceptionsurl;
+ },
+
+ setAASubscriptionEnabled: function (enabled)
Eric 2016/12/05 14:40:58 Nit: extra space after 'function'
sergei 2017/03/17 15:55:25 Done.
+ {
+ var aaSubscription = find(FilterStorage.subscriptions, API.isAASubscription);
Eric 2016/12/05 14:40:58 See comment on line 173
+ if (!enabled)
+ {
+ if (aaSubscription && !aaSubscription.disabled)
+ aaSubscription.disabled = true;
+ return;
+ }
+ if (!aaSubscription) {
+ aaSubscription = Subscription.fromURL(Prefs.subscriptions_exceptionsurl);
+ FilterStorage.addSubscription(aaSubscription);
+ }
+ if (aaSubscription.disabled)
+ aaSubscription.disabled = false;
+ if (!aaSubscription.lastDownload)
+ Synchronizer.execute(aaSubscription);
+ },
+
+ isAASubscriptionEnabled: function()
+ {
+ var aaSubscription = find(FilterStorage.subscriptions, API.isAASubscription);
Eric 2016/12/05 14:40:58 Also see comment on line 154. With the above line
sergei 2017/03/17 15:55:25 I would like to avoid augmenting of FilterStorage
+ return aaSubscription && !aaSubscription.disabled;
+ },
+
showNextNotification: function(url)
{
Notification.showNext(url);
@@ -181,7 +218,7 @@ var API = (function()
getHostFromUrl: function(url)
{
- return extractHostFromURL(url);
+ return extractHostFromURL(url);
},
compareVersions: function(v1, v2)

Powered by Google App Engine
This is Rietveld