Index: lib/filterStorage.js |
=================================================================== |
--- a/lib/filterStorage.js |
+++ b/lib/filterStorage.js |
@@ -123,16 +123,43 @@ |
* @type {number} |
*/ |
get subscriptionCount() |
{ |
return this.knownSubscriptions.size; |
} |
/** |
+ * Yields subscriptions in the storage to which the given filter belongs. |
+ * @param {Filter} filter |
+ * @yields {Subscription} |
+ */ |
+ *subscriptionsForFilter(filter) |
+ { |
+ if (!filter.subscriptionsAdded) |
+ addSubscriptionsToFilter(filter); |
+ |
+ yield* filter.subscriptions(); |
+ } |
+ |
+ /** |
+ * Returns the number of subscriptions in the storage to which the given |
+ * filter belongs. |
+ * @param {Filter} filter |
+ * @return {number} |
+ */ |
+ getSubscriptionCountForFilter(filter) |
+ { |
+ if (!filter.subscriptionsAdded) |
+ addSubscriptionsToFilter(filter); |
+ |
+ return filter.subscriptionCount; |
+ } |
+ |
+ /** |
* Finds the filter group that a filter should be added to by default. Will |
* return <code>null</code> if this group doesn't exist yet. |
* @param {Filter} filter |
* @returns {?SpecialSubscription} |
*/ |
getGroupForFilter(filter) |
{ |
let generalSubscription = null; |
@@ -646,16 +673,32 @@ |
* Reads the user's filters from disk, manages them in memory, and writes them |
* back to disk. |
*/ |
let filterStorage = new FilterStorage(); |
exports.filterStorage = filterStorage; |
/** |
+ * Adds to a filter any subscriptions in the storage to which the filter |
+ * belongs. |
+ * @param {Filter} filter |
+ */ |
+function addSubscriptionsToFilter(filter) |
+{ |
+ for (let subscription of filterStorage.subscriptions()) |
+ { |
+ if (subscription.hasFilter(filter)) |
+ filter.addSubscription(subscription); |
+ } |
+ |
+ filter.subscriptionsAdded = true; |
+} |
+ |
+/** |
* 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 |
* subscription should be connected. If this is not given, the subscription |
* is connected to its own filters. |
*/ |
function connectSubscriptionFilters(subscription, filters) |