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

Delta Between Two Patch Sets: lib/filterStorage.js

Issue 29934588: Issue 7094 - Encapsulate management of subscription filters (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Simplify patch Created Nov. 17, 2018, 9:25 p.m.
Right Patch Set: Remove hasFilter and related code Created Nov. 18, 2018, 10:21 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
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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 filterNotifier.emit("subscription.removed", subscription); 190 filterNotifier.emit("subscription.removed", subscription);
191 } 191 }
192 192
193 /** 193 /**
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.<Filter>} filters The new list of filters. 196 * @param {Array.<Filter>} filters The new list of filters.
197 */ 197 */
198 updateSubscriptionFilters(subscription, filters) 198 updateSubscriptionFilters(subscription, filters)
199 { 199 {
200 disconnectSubscriptionFilters(subscription);
201
202 let oldFilters = [...subscription.filters()]; 200 let oldFilters = [...subscription.filters()];
201 disconnectSubscriptionFilters(subscription, oldFilters);
203 subscription.clearFilters(); 202 subscription.clearFilters();
203
204 for (let filter of filters) 204 for (let filter of filters)
205 subscription.addFilter(filter); 205 subscription.addFilter(filter);
206 206
207 connectSubscriptionFilters(subscription, filters); 207 connectSubscriptionFilters(subscription, filters);
Manish Jethani 2018/11/17 21:41:09 The reason we're passing the filters array to the
208
208 filterNotifier.emit("subscription.updated", subscription, oldFilters); 209 filterNotifier.emit("subscription.updated", subscription, oldFilters);
209 } 210 }
210 211
211 /** 212 /**
212 * Adds a user-defined filter to the storage. 213 * Adds a user-defined filter to the storage.
213 * @param {Filter} filter 214 * @param {Filter} filter
214 * @param {?SpecialSubscription} [subscription] The subscription that the 215 * @param {?SpecialSubscription} [subscription] The subscription that the
215 * filter should be added to. 216 * filter should be added to.
216 * @param {number} [position] The position within the subscription at which 217 * @param {number} [position] The position within the subscription at which
217 * the filter should be added. If not specified, the filter is added at the 218 * the filter should be added. If not specified, the filter is added at the
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 * @param {Filter} filter 253 * @param {Filter} filter
253 * @param {?SpecialSubscription} [subscription] The subscription that the 254 * @param {?SpecialSubscription} [subscription] The subscription that the
254 * filter should be removed from. If not specified, the filter will be 255 * filter should be removed from. If not specified, the filter will be
255 * removed from all subscriptions. 256 * removed from all subscriptions.
256 * @param {number} [position] The position within the subscription at which 257 * @param {number} [position] The position within the subscription at which
257 * the filter should be removed. If not specified, all instances of the 258 * the filter should be removed. If not specified, all instances of the
258 * filter will be removed. 259 * filter will be removed.
259 */ 260 */
260 removeFilter(filter, subscription, position) 261 removeFilter(filter, subscription, position)
261 { 262 {
262 let subscriptions = ( 263 let subscriptions = (
Manish Jethani 2018/11/17 21:41:09 Note: Both removeFilter() and moveFilter() can pro
263 subscription ? [subscription] : filter.subscriptions() 264 subscription ? [subscription] : filter.subscriptions()
264 ); 265 );
265 for (let currentSubscription of subscriptions) 266 for (let currentSubscription of subscriptions)
266 { 267 {
267 if (currentSubscription instanceof SpecialSubscription) 268 if (currentSubscription instanceof SpecialSubscription)
268 { 269 {
269 let positions = []; 270 let positions = [];
270 if (typeof position == "undefined") 271 if (typeof position == "undefined")
271 { 272 {
272 let index = -1; 273 let index = -1;
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 * subscription is disconnected from its own filters. 676 * subscription is disconnected from its own filters.
676 */ 677 */
677 function disconnectSubscriptionFilters(subscription, filters) 678 function disconnectSubscriptionFilters(subscription, filters)
678 { 679 {
679 if (!filterStorage.knownSubscriptions.has(subscription.url)) 680 if (!filterStorage.knownSubscriptions.has(subscription.url))
680 return; 681 return;
681 682
682 for (let filter of filters || subscription.filters()) 683 for (let filter of filters || subscription.filters())
683 filter.removeSubscription(subscription); 684 filter.removeSubscription(subscription);
684 } 685 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld