From 0a22094e24c059649d95353c67263e2c8e7bcc31 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Tue, 20 Aug 2013 09:56:27 -0400 Subject: [PATCH] Change operator canonicalizations. Streams are converted to their "official" names now. Topics are not canonicalized at all. All other operands continue to be lowercased. Since we don't lowercase stream/topic at the parsing stage, we have to modify the predicate function to do the lowercasing of stream/topic to enable case-insensitive comparisons. This is slightly more expensive. The server-side predicate functions are already case-insensitive. (imported from commit 286f118c6c3ff9d23b37c7f958cab4c0eacd5feb) --- static/js/filter.js | 13 ++++++++++++- zerver/tests/frontend/node/filter.js | 2 +- zerver/tests/frontend/node/narrow.js | 10 +++++----- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/static/js/filter.js b/static/js/filter.js index 73982646b9..cbdeeac2b0 100644 --- a/static/js/filter.js +++ b/static/js/filter.js @@ -32,7 +32,16 @@ Filter.canonicalize_tuple = function (tuple) { var operand = tuple[1]; operator = Filter.canonicalize_operator(operator); - operand = stream_data.canonicalized_name(operand); + + switch (operator) { + case 'stream': + operand = stream_data.get_name(operand); + break; + case 'topic': + break; + default: + operand = operand.toString().toLowerCase(); + } // We may want to consider allowing mixed-case operators at some point return [operator, operand]; @@ -147,6 +156,7 @@ Filter.prototype = { return false; } + operand = operand.toLowerCase(); if (page_params.domain === "mit.edu") { // MIT users expect narrowing to "social" to also show messages to /^(un)*social(.d)*$/ // (unsocial, ununsocial, social.d, etc) @@ -170,6 +180,7 @@ Filter.prototype = { return false; } + operand = operand.toLowerCase(); if (page_params.domain === "mit.edu") { // MIT users expect narrowing to topic "foo" to also show messages to /^foo(.d)*$/ // (foo, foo.d, foo.d.d, etc) diff --git a/zerver/tests/frontend/node/filter.js b/zerver/tests/frontend/node/filter.js index d4b9aeee83..31c4f1a802 100644 --- a/zerver/tests/frontend/node/filter.js +++ b/zerver/tests/frontend/node/filter.js @@ -42,7 +42,7 @@ var Filter = global.Filter; assert.equal(Filter.canonicalize_operator('Stream'), 'stream'); assert.equal(Filter.canonicalize_operator('Subject'), 'topic'); - assert.deepEqual(Filter.canonicalize_tuple(['Stream', 'Denmark']), ['stream', 'denmark']); + assert.deepEqual(Filter.canonicalize_tuple(['Stream', 'Denmark']), ['stream', 'Denmark']); }()); (function test_predicates() { diff --git a/zerver/tests/frontend/node/narrow.js b/zerver/tests/frontend/node/narrow.js index e4c58fee17..0f543010bb 100644 --- a/zerver/tests/frontend/node/narrow.js +++ b/zerver/tests/frontend/node/narrow.js @@ -27,12 +27,12 @@ var stream_data = global.stream_data; var operators = [['stream', 'Foo'], ['topic', 'Bar'], ['search', 'yo']]; narrow._set_current_filter(new Filter(operators)); - assert.equal(narrow.stream(), 'foo'); + assert.equal(narrow.stream(), 'Foo'); }()); (function test_operators() { - var operators = [['stream', 'Foo'], ['topic', 'Bar'], ['search', 'yo']]; - var canonical_operators = [['stream', 'foo'], ['topic', 'bar'], ['search', 'yo']]; + var operators = [['stream', 'Foo'], ['topic', 'Bar'], ['search', 'Yo']]; + var canonical_operators = [['stream', 'Foo'], ['topic', 'Bar'], ['search', 'yo']]; narrow._set_current_filter(new Filter(operators)); assert.deepEqual(narrow.operators(), canonical_operators); @@ -44,8 +44,8 @@ var stream_data = global.stream_data; var opts = {}; narrow.set_compose_defaults(opts); - assert.equal(opts.stream, 'foo'); - assert.equal(opts.subject, 'bar'); + assert.equal(opts.stream, 'Foo'); + assert.equal(opts.subject, 'Bar'); stream_data.add_sub('ROME', {name: 'ROME'}); operators = [['stream', 'rome']];