mirror of https://github.com/zulip/zulip.git
compose: Use the new endpoint to create scheduled messages.
This commit is contained in:
parent
d60d6e9115
commit
5baa0dc313
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -82,6 +82,13 @@ export function is_time_selected_for_schedule() {
|
|||
}
|
||||
|
||||
export function get_selected_send_later_time() {
|
||||
if (!selected_send_later_time) {
|
||||
return undefined;
|
||||
}
|
||||
return selected_send_later_time;
|
||||
}
|
||||
|
||||
export function get_formatted_selected_send_later_time() {
|
||||
if (!selected_send_later_time) {
|
||||
return undefined;
|
||||
}
|
||||
|
@ -863,7 +870,7 @@ export function initialize() {
|
|||
possible_send_later_today = false;
|
||||
}
|
||||
|
||||
const formatted_send_later_time = get_selected_send_later_time();
|
||||
const formatted_send_later_time = get_formatted_selected_send_later_time();
|
||||
|
||||
instance.setContent(
|
||||
parse_html(
|
||||
|
|
|
@ -3,9 +3,12 @@ import $ from "jquery";
|
|||
import * as channel from "./channel";
|
||||
import * as compose from "./compose";
|
||||
import * as compose_actions from "./compose_actions";
|
||||
import * as compose_banner from "./compose_banner";
|
||||
import * as compose_fade from "./compose_fade";
|
||||
import * as compose_ui from "./compose_ui";
|
||||
import {$t} from "./i18n";
|
||||
import * as narrow from "./narrow";
|
||||
import * as notifications from "./notifications";
|
||||
import * as overlays from "./overlays";
|
||||
import * as people from "./people";
|
||||
import * as popover_menus from "./popover_menus";
|
||||
|
@ -68,6 +71,36 @@ export function edit_scheduled_message(scheduled_msg_id) {
|
|||
popover_menus.show_schedule_confirm_button(scheduled_msg.formatted_send_at_time, true);
|
||||
}
|
||||
|
||||
export function send_request_to_schedule_message(scheduled_message_data, deliver_at) {
|
||||
const success = function () {
|
||||
compose.clear_compose_box();
|
||||
notifications.notify_above_composebox(
|
||||
$t({defaultMessage: `Your message has been scheduled for {deliver_at}.`}, {deliver_at}),
|
||||
"scheduled_message_banner",
|
||||
"/#scheduled",
|
||||
"",
|
||||
$t({defaultMessage: "View scheduled messages"}),
|
||||
);
|
||||
};
|
||||
|
||||
const error = function (xhr) {
|
||||
const response = channel.xhr_error_message("Error sending message", xhr);
|
||||
compose_ui.hide_compose_spinner();
|
||||
compose_banner.show_error_message(
|
||||
response,
|
||||
compose_banner.CLASSNAMES.generic_compose_error,
|
||||
$("#compose-textarea"),
|
||||
);
|
||||
};
|
||||
|
||||
channel.post({
|
||||
url: "/json/scheduled_messages",
|
||||
data: scheduled_message_data,
|
||||
success,
|
||||
error,
|
||||
});
|
||||
}
|
||||
|
||||
export function delete_scheduled_message(scheduled_msg_id) {
|
||||
channel.del({
|
||||
url: "/json/scheduled_messages/" + scheduled_msg_id,
|
||||
|
|
|
@ -38,7 +38,7 @@ function format(scheduled_messages) {
|
|||
msg_render_context.is_stream = false;
|
||||
msg_render_context.recipients = people.get_recipients(msg.to.join(","));
|
||||
}
|
||||
const time = new Date(msg.deliver_at);
|
||||
const time = new Date(msg.scheduled_delivery_timestamp * 1000);
|
||||
msg_render_context.full_date_time = timerender.get_full_datetime(time);
|
||||
msg_render_context.formatted_send_at_time = date_fns.format(time, "MMM d yyyy h:mm a");
|
||||
formatted_msgs.push(msg_render_context);
|
||||
|
|
|
@ -654,7 +654,7 @@ export function initialize() {
|
|||
return false;
|
||||
}
|
||||
|
||||
const send_at_time = popover_menus.get_selected_send_later_time();
|
||||
const send_at_time = popover_menus.get_formatted_selected_send_later_time();
|
||||
instance.setContent(
|
||||
parse_html(
|
||||
$t(
|
||||
|
|
Loading…
Reference in New Issue