From 639ec9380a864e602410038c765ab74d3d946ad5 Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Fri, 25 Jan 2013 16:04:17 -0500 Subject: [PATCH] Handle case where @-replies are not at beginning of msg (imported from commit 2ed80845f49f48de71a5ea1db382dc4d9369f393) --- zephyr/static/js/composebox_typeahead.js | 4 ++-- zephyr/static/js/typeahead_helper.js | 23 +++++++++++++++++------ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/zephyr/static/js/composebox_typeahead.js b/zephyr/static/js/composebox_typeahead.js index ff2d30bedf..b805a86d6b 100644 --- a/zephyr/static/js/composebox_typeahead.js +++ b/zephyr/static/js/composebox_typeahead.js @@ -169,7 +169,7 @@ exports.initialize = function () { // Case-insensitive. return (item.toLowerCase().indexOf(current_recipient.toLowerCase()) !== -1); }, - sorter: typeahead_helper.sort_recipients, + sorter: typeahead_helper.sort_recipientbox_typeahead, updater: function (item) { var previous_recipients = exports.get_cleaned_pm_recipients(this.query); previous_recipients.pop(); @@ -200,7 +200,7 @@ exports.initialize = function () { // Case-insensitive. return (item.toLowerCase().indexOf(current_recipient.toLowerCase()) !== -1); }, - sorter: typeahead_helper.sort_recipients, + sorter: typeahead_helper.sort_textbox_typeahead, updater: function (item) { return this.query.replace(/@\S+$/, "") + "@" + typeahead_helper.private_message_mapped[item].email.split("@")[0]; }, diff --git a/zephyr/static/js/typeahead_helper.js b/zephyr/static/js/typeahead_helper.js index a90ea70881..c1a427ce2d 100644 --- a/zephyr/static/js/typeahead_helper.js +++ b/zephyr/static/js/typeahead_helper.js @@ -140,18 +140,29 @@ exports.sort_subjects = function (items) { return exports.sorter(this.query, items, identity); }; -exports.sort_recipients = function (matches) { - var cleaned = composebox_typeahead.get_cleaned_pm_recipients(this.query); - var query = cleaned[cleaned.length - 1]; - if (query[0] === '@') - query = query.substring(1); - +exports.sort_recipients = function (matches, query) { var name_results = prefix_sort(query, matches, identity); var email_results = prefix_sort(query, name_results.rest, email_from_identity); var sorted_by_pms = exports.sort_by_pms(email_results.rest); return name_results.matches.concat(email_results.matches.concat(sorted_by_pms)); }; +exports.sort_textbox_typeahead = function(matches) { + // input may be free text ending in @ for autocomplete + var query = this.query; + if (query.indexOf('@') > -1) { + var parts = this.query.split('@'); + query = parts[parts.length - 1]; + } + return exports.sort_recipients(matches, query); +}; + +exports.sort_recipientbox_typeahead = function(matches) { + // input_text may be one or more pm recipients + var cleaned = composebox_typeahead.get_cleaned_pm_recipients(this.query); + var query = cleaned[cleaned.length - 1]; + return exports.sort_recipients(matches, query);}; + return exports; }());