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

Unified Diff: messageResponder.js

Issue 29321198: Issue 2376 - Implement custom filters in new options page (Closed)
Patch Set: Addressed comments, moved error message to background page for consistency Created July 9, 2015, 4:25 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « locale/en-US/options.json ('k') | options.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: messageResponder.js
===================================================================
--- a/messageResponder.js
+++ b/messageResponder.js
@@ -28,8 +28,11 @@
var filterClasses = require("filterClasses");
var Filter = filterClasses.Filter;
+ var WhitelistFilter = filterClasses.WhitelistFilter
var BlockingFilter = filterClasses.BlockingFilter;
var Synchronizer = require("synchronizer").Synchronizer;
+ var parseFilters = require("filterValidation").parseFilters;
+ var parseFilter = require("filterValidation").parseFilter;
var subscriptionClasses = require("subscriptionClasses");
var Subscription = subscriptionClasses.Subscription;
@@ -195,12 +198,59 @@
callback(subscription.filters.map(convertFilter));
break;
+ case "filters.importRaw":
+ var result = parseFilters(message.text);
+ var errors = result.errors.filter(function(error)
+ {
+ return error.type != "unexpected-filter-list-header";
+ });
+
+ if (errors.length > 0)
+ {
+ alert(errors.join("\n"));
+ return;
+ }
+
+ var seenFilter = Object.create(null);
+ for (var i = 0; i < result.filters.length; i++)
+ {
+ var filter = result.filters[i];
+ FilterStorage.addFilter(filter);
+ seenFilter[filter.text] = null;
+ }
+
+ for (var i = 0; i < FilterStorage.subscriptions.length; i++)
+ {
+ var subscription = FilterStorage.subscriptions[i];
+ if (!(subscription instanceof SpecialSubscription))
+ continue;
+
+ var filters = subscription.filters.slice();
+ for (var j = 0; j < filters.length; j++)
+ {
+ var filter = filters[j];
+ if (filter instanceof WhitelistFilter &&
+ /^@@\|\|([^\/:]+)\^\$document$/.test(filter.text))
+ continue;
+
+ if (!(filter.text in seenFilter))
+ FilterStorage.removeFilter(filter);
+ }
+ }
+ break;
case "filters.listen":
if (message.filter)
listenerFilters.filter = message.filter;
else
delete listenerFilters.filter;
break;
+ case "filters.parse":
+ var result = parseFilter(message.text);
+ if (result.error)
+ alert(result.error);
Sebastian Noack 2015/07/10 07:31:01 Please no alert() or similar calls in the backgrou
Thomas Greiner 2015/07/10 12:38:53 Unfortunately, this didn't make it into the initia
+ else
+ FilterStorage.addFilter(result.filter);
+ break;
case "filters.remove":
var filter = Filter.fromText(message.text);
var subscription = null;
« no previous file with comments | « locale/en-US/options.json ('k') | options.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld