compose: Use the new endpoint to create scheduled messages.

This commit is contained in:
Aman Agrawal
2023-04-20 02:34:08 +00:00
committed by Tim Abbott
parent d60d6e9115
commit 5baa0dc313
5 changed files with 73 additions and 12 deletions

View File

@@ -804,14 +804,35 @@ export function reset_compose_scheduling_state(reset_edit_state = true) {
}
function schedule_message_to_custom_date() {
const request = create_message_object();
const selected_send_later_time = popover_menus.get_selected_send_later_time();
request.content = `/schedule ${selected_send_later_time}\n` + request.content;
// If this is an edit request `scheduled_message_id` will be defined.
let scheduled_message_id;
if ($("#compose-textarea").attr("data-scheduled-message-id")) {
scheduled_message_id = $("#compose-textarea").attr("data-scheduled-message-id");
$("#compose-textarea").removeAttr("data-scheduled-message-id");
const compose_message_object = create_message_object();
const deliver_at = popover_menus.get_formatted_selected_send_later_time();
const send_later_time = popover_menus.get_selected_send_later_time();
const scheduled_delivery_timestamp = Math.floor(Date.parse(send_later_time) / 1000);
const message_type = compose_message_object.type;
let req_type;
if (message_type === "private") {
req_type = "direct";
} else {
req_type = message_type;
}
reminder.schedule_message(request, clear_compose_box, scheduled_message_id);
const scheduled_message_data = {
type: req_type,
to: JSON.stringify(compose_message_object.to),
topic: compose_message_object.topic,
content: compose_message_object.content,
scheduled_delivery_timestamp,
};
// If this is an edit request `scheduled_message_id` will be defined.
if ($("#compose-textarea").attr("data-scheduled-message-id")) {
scheduled_message_data.scheduled_message_id = $("#compose-textarea").attr(
"data-scheduled-message-id",
);
}
scheduled_messages.send_request_to_schedule_message(scheduled_message_data, deliver_at);
}