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 initial comments Created July 8, 2015, 6:13 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') | options.html » ('J')
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;
@@ -46,6 +49,7 @@
var convertSubscription = convertObject.bind(null, ["disabled",
"downloadStatus", "homepage", "lastSuccess", "title", "url"]);
+ var convertFilterParsingError = convertObject.bind(null, ["type"]);
var convertFilter = convertObject.bind(null, ["text"]);
var changeListeners = null;
@@ -195,12 +199,61 @@
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"));
Thomas Greiner 2015/07/09 11:07:55 This won't work because this code is running in th
Sebastian Noack 2015/07/10 07:31:00 What could go wrong when adding filters? Currently
Thomas Greiner 2015/07/10 12:38:52 We're talking about the same issue: the placement
saroyanm 2015/07/13 14:05:34 Done.
+ 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;
+ }
+
+ var remove = [];
+ for (var i = 0; i < FilterStorage.subscriptions.length; i++)
+ {
+ var subscription = FilterStorage.subscriptions[i];
+ if (!(subscription instanceof SpecialSubscription))
+ continue;
+
+ for (var j = 0; j < subscription.filters.length; j++)
+ {
+ var filter = subscription.filters[j];
+ if (filter instanceof WhitelistFilter &&
Sebastian Noack 2015/07/09 12:12:14 Nit: Isn't |filter instanceof WhilelistFilter| red
saroyanm 2015/07/09 16:31:41 Yes this redundant, but it's the way it was implem
Sebastian Noack 2015/07/10 07:31:00 Just because the previous code is doing something,
saroyanm 2015/07/13 14:05:34 Done.
+ /^@@\|\|([^\/:]+)\^\$document$/.test(filter.text))
+ continue;
+
+ if (!(filter.text in seenFilter))
+ remove.push(filter);
+ }
+ }
+ for (var i = 0; i < remove.length; i++)
+ FilterStorage.removeFilter(remove[i]);
Sebastian Noack 2015/07/09 12:12:14 Any reason to collect the filters to be removed in
saroyanm 2015/07/09 16:31:40 In that case we will have object relation issue, b
Sebastian Noack 2015/07/10 07:31:00 What one would usually do in this case, is simply
Thomas Greiner 2015/07/10 12:38:53 However, it's just as confusing as the current met
Sebastian Noack 2015/07/14 11:57:24 If you keep the performance aspect aside, I suppos
Thomas Greiner 2015/07/14 12:47:16 Remembering what you said that some people copy en
saroyanm 2015/07/14 13:15:46 Agree as well, done.
+ break;
case "filters.listen":
if (message.filter)
listenerFilters.filter = message.filter;
else
delete listenerFilters.filter;
break;
+ case "filter.parse":
Thomas Greiner 2015/07/09 11:07:55 Plural for consistency: "filters.parse"
saroyanm 2015/07/09 16:31:40 Done.
+ var result = parseFilter(message.text);
+ if (result.filter)
Sebastian Noack 2015/07/09 12:12:14 Note that if the normalized filter text is empty r
saroyanm 2015/07/09 16:31:40 We changed the implementation here, we will need t
Sebastian Noack 2015/07/10 07:31:00 This sounds rather complicated and backwards to me
Thomas Greiner 2015/07/10 12:38:53 It would be more inline with how we return filters
Sebastian Noack 2015/07/14 11:57:24 Yes, we need to listen for subscription download e
saroyanm 2015/07/14 13:15:46 Currently we have implemented global error reporti
+ callback({filter: convertFilter(result.filter)});
+ else
+ callback({error: convertFilterParsingError(result.error)});
+ 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') | options.html » ('J')

Powered by Google App Engine
This is Rietveld