Index: messageResponder.js |
=================================================================== |
--- a/messageResponder.js |
+++ b/messageResponder.js |
@@ -212,6 +212,51 @@ |
else |
FilterStorage.removeFilter(filter, subscription, message.index); |
break; |
+ case "filters.importRaw": |
Thomas Greiner
2015/06/30 09:23:27
It's easier to search for the right method if the
saroyanm
2015/07/08 18:25:39
Done.
|
+ var parseFilters = require("filterValidation").parseFilters; |
+ var result = parseFilters(message.text); |
+ |
+ var errors = result.errors.filter(function(e) |
Thomas Greiner
2015/06/30 09:23:27
Please rename this variable from "e" to "error". G
saroyanm
2015/07/08 18:25:39
Done, Agree
|
+ { |
+ return e.type != "unexpected-filter-list-header"; |
Thomas Greiner
2015/06/30 09:23:26
I'm aware that you didn't write this but what's th
saroyanm
2015/07/08 18:25:40
It's being fired when the the filter starts with "
Thomas Greiner
2015/07/09 11:07:54
Asked Sebastian about this and the line of reasoni
|
+ }); |
+ |
+ 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; |
+ } |
+ |
+ 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 && /^@@\|\|([^\/:]+)\^\$document$/.test(filter.text)) |
Thomas Greiner
2015/06/30 09:23:27
Beware of the 80 characters limit
saroyanm
2015/07/08 18:25:39
Done.
|
+ continue; |
+ |
+ if (!(filter.text in seenFilter)) |
+ FilterStorage.removeFilter(filter); |
+ } |
+ } |
+ break; |
+ case "parse.filter": |
Thomas Greiner
2015/06/30 09:23:27
This name is inconsistent with the other ones whic
saroyanm
2015/07/08 18:25:40
Done.
|
+ var parseFilter = require("filterValidation").parseFilter; |
Thomas Greiner
2015/06/30 09:23:26
No need to require it each time it's called so ple
saroyanm
2015/07/08 18:25:40
Agree, was stupid.
|
+ callback(parseFilter(message.text)); |
Thomas Greiner
2015/06/30 09:23:26
"parseFilter" returns an instance of `Filter` (e.g
saroyanm
2015/07/08 18:25:39
Good point, done.
|
+ break; |
case "prefs.get": |
callback(Prefs[message.key]); |
break; |