From a717c7df18006f2f969350b32110fd6b61da01ac Mon Sep 17 00:00:00 2001 From: Vishnu Ks Date: Fri, 10 Jun 2016 23:45:08 +0530 Subject: [PATCH] Seperate extract PM recipients as function. --- static/js/compose.js | 2 +- static/js/composebox_typeahead.js | 9 ++------- static/js/util.js | 4 ++++ 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/static/js/compose.js b/static/js/compose.js index 80839c85f7..b48506b1d7 100644 --- a/static/js/compose.js +++ b/static/js/compose.js @@ -330,7 +330,7 @@ function create_message_object() { if (message.type === "private") { // TODO: this should be collapsed with the code in composebox_typeahead.js - message.to = compose.recipient().split(/\s*[,;]\s*/); + message.to = util.extract_pm_recipients(compose.recipient()); message.reply_to = compose.recipient(); } else { message.to = compose.stream_name(); diff --git a/static/js/composebox_typeahead.js b/static/js/composebox_typeahead.js index 144204ae49..7c34f3d03d 100644 --- a/static/js/composebox_typeahead.js +++ b/static/js/composebox_typeahead.js @@ -13,15 +13,10 @@ var composebox_typeahead = (function () { var exports = {}; -function get_pm_recipients(query_string) { - // Assumes email addresses don't have commas or semicolons in them - return query_string.split(/\s*[,;]\s*/); -} - // Returns an array of private message recipients, removing empty elements. // For example, "a,,b, " => ["a", "b"] exports.get_cleaned_pm_recipients = function (query_string) { - var recipients = get_pm_recipients(query_string); + var recipients = util.extract_pm_recipients(query_string); recipients = _.filter(recipients, function (elem) { return elem.match(/\S/); }); @@ -55,7 +50,7 @@ exports.topics_seen_for = function (stream) { }; function get_last_recipient_in_pm(query_string) { - var recipients = get_pm_recipients(query_string); + var recipients = util.extract_pm_recipients(query_string); return recipients[recipients.length-1]; } diff --git a/static/js/util.js b/static/js/util.js index 0b7d59c1dd..0815e9ee61 100644 --- a/static/js/util.js +++ b/static/js/util.js @@ -69,6 +69,10 @@ exports.is_pm_recipient = function (email, message) { return recipients.indexOf(email.toLowerCase()) !== -1; }; +exports.extract_pm_recipients = function (recipients) { + return recipients.split(/\s*[,;]\s*/); +}; + exports.same_major_recipient = function (a, b) { // Same behavior as same_recipient, except that it returns true for messages // on different topics but the same stream.