Allow filters to be en-/disabled per subscription
Background
In eyeo/adblockplus/abpui/adblockplusui#681 it got pointed out that it's not obvious that changing the state of a filter in a special subscription (i.e. custom filter) also affects its state in a downloadable subscription such as EasyList. Therefore one option to avoid this from happening would be to store the filter state per subscription so that, for example, disabling a filter in one subscription doesn't change that the filter remains enabled in another subscription.
There could still be situations though where a filter's state needs to be modified even before it's being added to a subscription so we may need to retain the filter's global state in addition to its per-subscription state. However, it's unclear at this point whether this is indeed necessary and it's expected to increase the complexity of this change by quite a bit which may render it infeasible.
Suggested change (if global state is not necessary)
- Only allow modifications to the filter state in conjunction with a subscription it's in.
- Consider a filter to be enabled when it's enabled in at least one subscription.
Testing Notes
This change enables the UI team to enable / disable filters per subscription, but does not force them to make the change immediately.
For now, a crucial test is that enabling / disabling filters still works with no change to UI. This will still retain the non-obvious behaviour described in eyeo/adblockplus/abpui/adblockplusui#681 where disabling a custom filter will disable that filter globally, even if the filter also appears in subscriptions.
Integration Notes
This change introduces a way to enable and disable filters per subscription.
- When setting or checking disabled status using
ActiveFilter
, usefilter.isDisabledForSubscription(subscriptionUrl)
andfilter.setDisabledForSubscription(subscriptionUrl)
instead offilter.disabled
. - When setting or checking disabled status using
filterState
directly, use the new functionsfilterState.isDisabledForSubscription(filterText, subscriptionUrl)
andfilterState.setDisabledForSubscription(filterText, subscriptionUrl, disabled)
- To inspect which subscriptions a filter is disabled for, see
filter.disabledSubscriptions
orfilterState.disabledSubscriptions(filterText)
These changes are backwards compatible, so filter.disabled
and filterState.isEnabled
will continue to work as before, however these functions are now deprecated in favour of the new subscription-specific alternatives. Note that setting filter.disabled
will overwrite any previously set disabled subscriptions, and disabling a filter for a specific subscription will override any previous filter.disabled
state.
There is a new event, filterState.disabledSubscriptions
, that will by triggered when the filter.disabledSubscriptions
Set changes.
The event filterState.disabled
has been removed. This event was only being triggered in the edge case of resetting all the state of the filter. The correct event to subscribe to for filters being enabled or disabled is filterState.disabledSubscriptions
for the new subscription-specific enabled / disabled state, or filterState.enabled
for the old global enabled / disabled state.