Index: lib/filterStorage.js |
=================================================================== |
--- a/lib/filterStorage.js |
+++ b/lib/filterStorage.js |
@@ -188,30 +188,30 @@ |
Subscription.knownSubscriptions.delete(subscription.url); |
filterNotifier.emit("subscription.removed", subscription); |
} |
/** |
* Replaces the list of filters in a subscription with a new list. |
* @param {Subscription} subscription The subscription to be updated. |
- * @param {Array.<Filter>} filters The new list of filters. |
+ * @param {Array.<string>} filterText The new filter text. |
*/ |
- updateSubscriptionFilters(subscription, filters) |
+ updateSubscriptionFilters(subscription, filterText) |
{ |
- let oldFilters = [...subscription.filters()]; |
- disconnectSubscriptionFilters(subscription, oldFilters); |
+ let oldFilterText = [...subscription.filterText()]; |
+ disconnectSubscriptionFilters(subscription, oldFilterText); |
subscription.clearFilters(); |
- for (let filter of filters) |
- subscription.addFilter(filter); |
+ for (let filter of filterText) |
+ subscription.addFilterText(filter); |
- connectSubscriptionFilters(subscription, filters); |
+ connectSubscriptionFilters(subscription, filterText); |
- filterNotifier.emit("subscription.updated", subscription, oldFilters); |
+ filterNotifier.emit("subscription.updated", subscription, oldFilterText); |
} |
/** |
* Adds a user-defined filter to the storage. |
* @param {Filter} filter |
* @param {?SpecialSubscription} [subscription] The subscription that the |
* filter should be added to. |
* @param {number} [position] The position within the subscription at which |
@@ -279,18 +279,19 @@ |
} while (index >= 0); |
} |
else |
positions.push(position); |
for (let j = positions.length - 1; j >= 0; j--) |
{ |
let currentPosition = positions[j]; |
- let currentFilter = currentSubscription.filterAt(currentPosition); |
- if (currentFilter && currentFilter.text == filter.text) |
+ let currentFilterText = |
+ currentSubscription.filterTextAt(currentPosition); |
+ if (currentFilterText && currentFilterText == filter.text) |
{ |
currentSubscription.deleteFilterAt(currentPosition); |
if (currentSubscription.searchFilter(filter) < 0) |
filter.removeSubscription(currentSubscription); |
filterNotifier.emit("filter.removed", filter, currentSubscription, |
currentPosition); |
} |
} |
@@ -306,18 +307,18 @@ |
* @param {number} oldPosition The current position of the filter. |
* @param {number} newPosition The new position of the filter. |
*/ |
moveFilter(filter, subscription, oldPosition, newPosition) |
{ |
if (!(subscription instanceof SpecialSubscription)) |
return; |
- let currentFilter = subscription.filterAt(oldPosition); |
- if (!currentFilter || currentFilter.text != filter.text) |
+ let currentFilterText = subscription.filterTextAt(oldPosition); |
+ if (!currentFilterText || currentFilterText != filter.text) |
return; |
newPosition = Math.min(Math.max(newPosition, 0), |
subscription.filterCount - 1); |
if (oldPosition == newPosition) |
return; |
subscription.deleteFilterAt(oldPosition); |
@@ -499,22 +500,22 @@ |
{ |
yield* subscription.serialize(); |
yield* subscription.serializeFilters(); |
} |
// Save filter data |
for (let subscription of subscriptions) |
{ |
- for (let filter of subscription.filters()) |
+ for (let text of subscription.filterText()) |
{ |
- if (!saved.has(filter.text)) |
+ if (!saved.has(text)) |
{ |
- yield* filter.serialize(); |
- saved.add(filter.text); |
+ yield* Filter.fromText(text).serialize(); |
+ saved.add(text); |
} |
} |
} |
} |
/** |
* Saves all subscriptions back to disk. |
* @returns {Promise} A promise resolved or rejected when saving is complete. |
@@ -649,37 +650,43 @@ |
let filterStorage = new FilterStorage(); |
exports.filterStorage = filterStorage; |
/** |
* Connects a subscription to its filters without any notifications. |
* @param {Subscription} subscription The subscription that should be |
* connected to its filters. |
- * @param {?Array.<Filter>} [filters] A list of filters to which the |
+ * @param {?Array.<string>} [filters] A list of filters to which the |
* subscription should be connected. If this is not given, the subscription |
* is connected to its own filters. |
*/ |
function connectSubscriptionFilters(subscription, filters) |
{ |
if (!filterStorage.knownSubscriptions.has(subscription.url)) |
return; |
- for (let filter of filters || subscription.filters()) |
+ for (let text of filters || subscription.filterText()) |
+ { |
+ let filter = Filter.fromText(text); |
filter.addSubscription(subscription); |
+ } |
} |
/** |
* Disconnects a subscription from its filters without any notifications. |
* @param {Subscription} subscription The subscription that should be |
* disconnected from its filters. |
- * @param {?Array.<Filter>} [filters] A list of filters from which the |
+ * @param {?Array.<string>} [filters] A list of filters from which the |
* subscription should be disconnected. If this is not given, the |
* subscription is disconnected from its own filters. |
*/ |
function disconnectSubscriptionFilters(subscription, filters) |
{ |
if (!filterStorage.knownSubscriptions.has(subscription.url)) |
return; |
- for (let filter of filters || subscription.filters()) |
+ for (let text of filters || subscription.filterText()) |
+ { |
+ let filter = Filter.fromText(text); |
filter.removeSubscription(subscription); |
+ } |
} |