From 70b0e73a24d6e129b6f4c177013131c33cbde9f0 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Thu, 5 Dec 2013 11:35:42 -0500 Subject: [PATCH] Support sender:me and pm-with:me search syntax. We convert sender:me to sender:steve@zulip.com at parsing time, so users will see the canonicalization in the search bar. Likewise for pm-with. (imported from commit aa9951f13d4633cfef85f03e5486d607fdef414f) --- static/js/filter.js | 7 +++++++ zerver/tests/frontend/node/filter.js | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/static/js/filter.js b/static/js/filter.js index a7613c618e..b8d7eb8030 100644 --- a/static/js/filter.js +++ b/static/js/filter.js @@ -74,6 +74,13 @@ Filter.canonicalize_tuple = function (tuple) { break; case 'topic': break; + case 'sender': + case 'pm-with': + operand = operand.toString().toLowerCase(); + if (operand === 'me') { + operand = page_params.email; + } + break; default: operand = operand.toString().toLowerCase(); } diff --git a/zerver/tests/frontend/node/filter.js b/zerver/tests/frontend/node/filter.js index e363a0b40d..19dd69ace7 100644 --- a/zerver/tests/frontend/node/filter.js +++ b/zerver/tests/frontend/node/filter.js @@ -8,6 +8,7 @@ add_dependencies({ }); set_global('page_params', { + email: 'hamlet@zulip.com', domain: 'zulip.com' }); @@ -52,6 +53,9 @@ var Filter = require('js/filter.js'); assert.equal(Filter.canonicalize_operator('Subject'), 'topic'); assert.deepEqual(Filter.canonicalize_tuple(['Stream', 'Denmark']), ['stream', 'Denmark']); + + assert.deepEqual(Filter.canonicalize_tuple(['sender', 'me']), ['sender', 'hamlet@zulip.com']); + assert.deepEqual(Filter.canonicalize_tuple(['pm-with', 'me']), ['pm-with', 'hamlet@zulip.com']); }()); function get_predicate(operators) {