Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
compose: Create new message object all at once.
Evy Kassirer39aa0eea4c79
diff --git a/web/src/compose.js b/web/src/compose.jsindex e87ee89ad20..6bcacebbd9a 100644--- a/web/src/compose.js+++ b/web/src/compose.js@@ -132,50 +132,12 @@ export function send_message_success(request, data) {export let send_message = () => {// Changes here must also be kept in sync with echo.try_deliver_locally- const request = {- type: compose_state.get_message_type(),- content: compose_state.message_content(),- sender_id: current_user.user_id,- queue_id: server_events_state.queue_id,- stream_id: undefined,- };- request.topic = "";-- if (request.type === "private") {- // TODO: this should be collapsed with the code in composebox_typeahead.ts- const recipient = compose_state.private_message_recipient_emails();- const emails = util.extract_pm_recipients(recipient);- request.to = emails;- request.reply_to = recipient;- request.private_message_recipient = recipient;- request.to_user_ids = people.email_list_to_user_ids_string(emails);-- // Note: The `undefined` case is for situations like- // the is_zephyr_mirror_realm case where users may- // be automatically created when you try to send a- // direct message to their email address.- if (request.to_user_ids !== undefined) {- request.to = people.user_ids_string_to_ids_array(request.to_user_ids);- }- } else {- const topic = compose_state.topic();- request.topic = util.is_topic_name_considered_empty(topic) ? "" : topic;- const stream_id = compose_state.stream_id();- request.stream_id = stream_id;- request.to = stream_id;- }-compose_state.set_recipient_edited_manually(false);compose_state.set_is_content_unedited_restored_draft(false);- if (request.type === "private") {- request.to = JSON.stringify(request.to);- } else {- request.to = JSON.stringify([request.to]);- }// Silently save / update a draft to ensure the message is not lost in case send fails.// We delete the draft on successful send.- request.draft_id = drafts.update_draft({+ const draft_id = drafts.update_draft({no_notify: true,update_count: false,is_sending_saving: true,@@ -184,11 +146,52 @@ export let send_message = () => {// message can just disappear into the void.force_save: true,});+ const message_type = compose_state.get_message_type();++ let message_data;+ if (message_type === "private") {+ // TODO: this should be collapsed with the code in composebox_typeahead.ts+ const recipient = compose_state.private_message_recipient_emails();+ const emails = util.extract_pm_recipients(recipient);+ const to_user_ids = people.email_list_to_user_ids_string(emails);+ // Note: The `undefined` case is for situations like+ // the is_zephyr_mirror_realm case where users may+ // be automatically created when you try to send a+ // direct message to their email address.+ const request_to =+ to_user_ids !== undefined ? people.user_ids_string_to_ids_array(to_user_ids) : emails;+ message_data = {+ type: message_type,+ content: compose_state.message_content(),+ sender_id: current_user.user_id,+ queue_id: server_events_state.queue_id,+ topic: "",+ to: JSON.stringify(request_to),+ reply_to: recipient,+ private_message_recipient: recipient,+ to_user_ids: people.email_list_to_user_ids_string(emails),+ draft_id,+ stream_id: undefined,+ };+ } else {+ const stream_id = compose_state.stream_id();+ const topic = compose_state.topic();+ message_data = {+ type: message_type,+ content: compose_state.message_content(),+ sender_id: current_user.user_id,+ queue_id: server_events_state.queue_id,+ topic: util.is_topic_name_considered_empty(topic) ? "" : topic,+ stream_id,+ to: JSON.stringify([stream_id]),+ draft_id,+ };+ }let local_id;let locally_echoed;- const message = echo.try_deliver_locally(request, message_events.insert_new_messages);+ const message = echo.try_deliver_locally(message_data, message_events.insert_new_messages);if (message) {// We are rendering this message locally with an id// like 92l99.01 that corresponds to a reasonable@@ -204,9 +207,12 @@ export let send_message = () => {local_id = sent_messages.get_new_local_id();}- request.local_id = local_id;- request.locally_echoed = locally_echoed;- request.resend = false;+ const request = {+ ...message_data,+ local_id,+ locally_echoed,+ resend: false,+ };function success(data) {send_message_success(request, data);@@ -251,9 +257,9 @@ export let send_message = () => {// message would send. Ensure that the displayed count is correct.drafts.sync_count();- const draft = drafts.draft_model.getDraft(request.draft_id);+ const draft = drafts.draft_model.getDraft(message_data.draft_id);draft.is_sending_saving = false;- drafts.draft_model.editDraft(request.draft_id, draft);+ drafts.draft_model.editDraft(message_data.draft_id, draft);}transmit.send_message(request, success, error);