From 487861554fce3991bd1405a31226da8c335116ed Mon Sep 17 00:00:00 2001 From: Mohit Gupta Date: Thu, 27 Jun 2019 22:46:55 +0530 Subject: [PATCH] search: Fix searching and search suggestion in Group PM. Fix the .get_suggestions and .get_suggestions_legacy to correctly handle search terms in group PM and treat it as search term by not concatenating it at end of pm-with email list operand. --- frontend_tests/node_tests/search_suggestion.js | 7 +++++++ frontend_tests/node_tests/search_suggestion_legacy.js | 9 +++++++++ static/js/search_suggestion.js | 4 ++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/frontend_tests/node_tests/search_suggestion.js b/frontend_tests/node_tests/search_suggestion.js index cc63d780da..aa40fadac2 100644 --- a/frontend_tests/node_tests/search_suggestion.js +++ b/frontend_tests/node_tests/search_suggestion.js @@ -422,6 +422,13 @@ run_test('group_suggestions', () => { "pm-with:jeff@zulip.com,ted@zulip.com", ]; assert.deepEqual(suggestions.strings, expected); + + query = "pm-with:jeff@zulip.com,ted@zulip.com hi"; + suggestions = search.get_suggestions("", query); + expected = [ + "pm-with:jeff@zulip.com,ted@zulip.com hi", + ]; + assert.deepEqual(suggestions.strings, expected); }); init(); diff --git a/frontend_tests/node_tests/search_suggestion_legacy.js b/frontend_tests/node_tests/search_suggestion_legacy.js index 9c98066855..b40f85930e 100644 --- a/frontend_tests/node_tests/search_suggestion_legacy.js +++ b/frontend_tests/node_tests/search_suggestion_legacy.js @@ -426,6 +426,15 @@ run_test('group_suggestions', () => { "pm-with:jeff@zulip.com,ted@zulip.com", ]; assert.deepEqual(suggestions.strings, expected); + + query = "pm-with:jeff@zulip.com,ted@zulip.com hi"; + suggestions = search.get_suggestions_legacy(query); + expected = [ + "pm-with:jeff@zulip.com,ted@zulip.com hi", + "pm-with:jeff@zulip.com,ted@zulip.com", + ]; + assert.deepEqual(suggestions.strings, expected); + }); init(); diff --git a/static/js/search_suggestion.js b/static/js/search_suggestion.js index bbc4cd8159..09d9feb631 100644 --- a/static/js/search_suggestion.js +++ b/static/js/search_suggestion.js @@ -588,7 +588,7 @@ exports.get_suggestions = function (base_query, query) { last.operator === 'search' && person_suggestion_ops.indexOf(query_operators[query_operators_len - 2].operator) !== -1) { var person_op = query_operators[query_operators_len - 2]; - if (!people.get_by_email(person_op.operand)) { + if (!people.reply_to_to_user_ids_string(person_op.operand)) { last = { operator: person_op.operator, operand: person_op.operand + ' ' + last.operand, @@ -713,7 +713,7 @@ exports.get_suggestions_legacy = function (query) { last.operator === 'search' && person_suggestion_ops.indexOf(operators[operators_len - 2].operator) !== -1) { var person_op = operators[operators_len - 2]; - if (!people.get_by_email(person_op.operand)) { + if (!people.reply_to_to_user_ids_string(person_op.operand)) { last = { operator: person_op.operator, operand: person_op.operand + ' ' + last.operand,