Clean up the send_message processing of the message recipient.

(imported from commit 1e6d7783901743650cfb759b3136ae1de0f2989e)
This commit is contained in:
Tim Abbott
2013-04-17 13:34:20 -04:00
parent de5038f4d7
commit bc60be9ad5
2 changed files with 26 additions and 20 deletions

View File

@@ -227,6 +227,23 @@ exports.cancel = function () {
$(document).trigger($.Event('compose_canceled.zephyr')); $(document).trigger($.Event('compose_canceled.zephyr'));
}; };
function create_message_object() {
var message = {client: 'website',
type: compose.composing(),
subject: compose.subject(),
stream: compose.stream_name(),
private_message_recipient: compose.recipient(),
content: compose.message_content()};
if (message.type === "private") {
// TODO: this should be collapsed with the code in composebox_typeahead.js
message.to = compose.recipient().split(/\s*[,;]\s*/);
} else {
message.to = compose.stream_name();
}
return message;
}
function compose_error(error_text, bad_input) { function compose_error(error_text, bad_input) {
$('#send-status').removeClass(status_classes) $('#send-status').removeClass(status_classes)
.addClass('alert-error') .addClass('alert-error')
@@ -242,27 +259,16 @@ var send_options;
function send_message() { function send_message() {
var send_status = $('#send-status'); var send_status = $('#send-status');
// TODO: this should be collapsed with the code in composebox_typeahead.js var request = create_message_object();
var recipients = compose.recipient().split(/\s*[,;]\s*/);
var request = {client: 'website',
type: compose.composing(),
subject: compose.subject(),
content: compose.message_content()};
if (request.type === "private") {
request.to = JSON.stringify(recipients);
} else {
request.to = JSON.stringify([compose.stream_name()]);
}
if (tutorial.is_running()) { if (tutorial.is_running()) {
// We make a new copy of the request object for the tutorial so that we tutorial.message_was_sent(request);
// don't mess up the request we're actually sending to the server
var tutorial_copy_of_message = $.extend({}, request, {to: compose.stream_name()});
if (request.type === "private") {
$.extend(tutorial_copy_of_message, {to: recipients});
} }
tutorial.message_was_sent(tutorial_copy_of_message);
if (request.type === "private") {
request.to = JSON.stringify(request.to);
} else {
request.to = JSON.stringify([request.to]);
} }
$.ajax({ $.ajax({

View File

@@ -53,7 +53,7 @@ function stream_to_me(message) {
} }
function pm_to_me(message) { function pm_to_me(message) {
return message.type === 'private' && message.to[0] === 'humbug+tutorial@humbughq.com'; return message.type === 'private' && message.to === 'humbug+tutorial@humbughq.com';
} }
function any_message_to_me(message) { function any_message_to_me(message) {