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

Delta Between Two Patch Sets: lib/filterStorage.js

Issue 29946572: Issue 7094 - Keep subscription filters by text only (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Fix bug Created Nov. 19, 2018, 2:28 a.m.
Right Patch Set: Rebase Created Feb. 16, 2019, 3:10 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « lib/filterListener.js ('k') | lib/iniParser.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 * Replaces the list of filters in a subscription with a new list. 194 * Replaces the list of filters in a subscription with a new list.
195 * @param {Subscription} subscription The subscription to be updated. 195 * @param {Subscription} subscription The subscription to be updated.
196 * @param {Array.<string>} filterText The new filter text. 196 * @param {Array.<string>} filterText The new filter text.
197 */ 197 */
198 updateSubscriptionFilters(subscription, filterText) 198 updateSubscriptionFilters(subscription, filterText)
199 { 199 {
200 let oldFilterText = [...subscription.filterText()]; 200 let oldFilterText = [...subscription.filterText()];
201 disconnectSubscriptionFilters(subscription, oldFilterText); 201 disconnectSubscriptionFilters(subscription, oldFilterText);
202 subscription.clearFilters(); 202 subscription.clearFilters();
203 203
204 for (let filter of filterText) 204 for (let text of filterText)
205 subscription.addFilterText(filter); 205 subscription.addFilterText(text);
206 206
207 connectSubscriptionFilters(subscription, filterText); 207 connectSubscriptionFilters(subscription, filterText);
208 208
209 filterNotifier.emit("subscription.updated", subscription, oldFilterText); 209 filterNotifier.emit("subscription.updated", subscription, oldFilterText);
210 } 210 }
211 211
212 /** 212 /**
213 * Adds a user-defined filter to the storage. 213 * Adds a user-defined filter to the storage.
214 * @param {Filter} filter 214 * @param {Filter} filter
215 * @param {?SpecialSubscription} [subscription] The subscription that the 215 * @param {?SpecialSubscription} [subscription] The subscription that the
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 * back to disk. 648 * back to disk.
649 */ 649 */
650 let filterStorage = new FilterStorage(); 650 let filterStorage = new FilterStorage();
651 651
652 exports.filterStorage = filterStorage; 652 exports.filterStorage = filterStorage;
653 653
654 /** 654 /**
655 * Connects a subscription to its filters without any notifications. 655 * Connects a subscription to its filters without any notifications.
656 * @param {Subscription} subscription The subscription that should be 656 * @param {Subscription} subscription The subscription that should be
657 * connected to its filters. 657 * connected to its filters.
658 * @param {?Array.<string>} [filters] A list of filters to which the 658 * @param {?Array.<string>} [filterText] A list of filters (in text form) to
659 * subscription should be connected. If this is not given, the subscription 659 * which the subscription should be connected. If this is not given, the
660 * is connected to its own filters. 660 * subscription is connected to its own filters.
661 */ 661 */
662 function connectSubscriptionFilters(subscription, filters) 662 function connectSubscriptionFilters(subscription, filterText)
663 { 663 {
664 if (!filterStorage.knownSubscriptions.has(subscription.url)) 664 if (!filterStorage.knownSubscriptions.has(subscription.url))
665 return; 665 return;
666 666
667 for (let text of filters || subscription.filterText()) 667 for (let text of filterText || subscription.filterText())
668 { 668 Filter.fromText(text).addSubscription(subscription);
669 let filter = Filter.fromText(text);
670 filter.addSubscription(subscription);
671 }
672 } 669 }
673 670
674 /** 671 /**
675 * Disconnects a subscription from its filters without any notifications. 672 * Disconnects a subscription from its filters without any notifications.
676 * @param {Subscription} subscription The subscription that should be 673 * @param {Subscription} subscription The subscription that should be
677 * disconnected from its filters. 674 * disconnected from its filters.
678 * @param {?Array.<string>} [filters] A list of filters from which the 675 * @param {?Array.<string>} [filterText] A list of filters (in text form) from
679 * subscription should be disconnected. If this is not given, the 676 * which the subscription should be disconnected. If this is not given, the
680 * subscription is disconnected from its own filters. 677 * subscription is disconnected from its own filters.
681 */ 678 */
682 function disconnectSubscriptionFilters(subscription, filters) 679 function disconnectSubscriptionFilters(subscription, filterText)
683 { 680 {
684 if (!filterStorage.knownSubscriptions.has(subscription.url)) 681 if (!filterStorage.knownSubscriptions.has(subscription.url))
685 return; 682 return;
686 683
687 for (let text of filters || subscription.filterText()) 684 for (let text of filterText || subscription.filterText())
688 { 685 Filter.fromText(text).removeSubscription(subscription);
689 let filter = Filter.fromText(text);
690 filter.removeSubscription(subscription);
691 }
692 } 686 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld