mirror of https://github.com/zulip/zulip.git
scheduled_messages: Move UI to new scheduled_messages_ui module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
c7927569bc
commit
ac38aaad21
|
@ -167,6 +167,7 @@ EXEMPT_FILES = make_set(
|
|||
"web/src/scheduled_messages.js",
|
||||
"web/src/scheduled_messages_overlay_ui.js",
|
||||
"web/src/scheduled_messages_popover.js",
|
||||
"web/src/scheduled_messages_ui.js",
|
||||
"web/src/scroll_bar.ts",
|
||||
"web/src/scroll_util.ts",
|
||||
"web/src/search.js",
|
||||
|
|
|
@ -1,16 +1,5 @@
|
|||
import $ from "jquery";
|
||||
|
||||
import render_compose_banner from "../templates/compose_banner/compose_banner.hbs";
|
||||
|
||||
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_ui from "./compose_ui";
|
||||
import {$t} from "./i18n";
|
||||
import * as narrow from "./narrow";
|
||||
import * as people from "./people";
|
||||
import * as sub_store from "./sub_store";
|
||||
import * as timerender from "./timerender";
|
||||
|
||||
export const MINIMUM_SCHEDULED_MESSAGE_DELAY_SECONDS = 5 * 60;
|
||||
|
@ -59,12 +48,6 @@ export function is_send_later_timestamp_missing_or_expired(
|
|||
return false;
|
||||
}
|
||||
|
||||
function hide_scheduled_message_success_compose_banner(scheduled_message_id) {
|
||||
$(
|
||||
`.message_scheduled_success_compose_banner[data-scheduled-message-id=${scheduled_message_id}]`,
|
||||
).hide();
|
||||
}
|
||||
|
||||
export function add_scheduled_messages(scheduled_messages) {
|
||||
for (const scheduled_message of scheduled_messages) {
|
||||
scheduled_messages_data[scheduled_message.scheduled_message_id] = scheduled_message;
|
||||
|
@ -74,7 +57,6 @@ export function add_scheduled_messages(scheduled_messages) {
|
|||
export function remove_scheduled_message(scheduled_message_id) {
|
||||
if (scheduled_messages_data[scheduled_message_id] !== undefined) {
|
||||
delete scheduled_messages_data[scheduled_message_id];
|
||||
hide_scheduled_message_success_compose_banner(scheduled_message_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -86,80 +68,6 @@ export function update_scheduled_message(scheduled_message) {
|
|||
scheduled_messages_data[scheduled_message.scheduled_message_id] = scheduled_message;
|
||||
}
|
||||
|
||||
function narrow_via_edit_scheduled_message(compose_args) {
|
||||
if (compose_args.type === "stream") {
|
||||
narrow.activate(
|
||||
[
|
||||
{operator: "stream", operand: compose_args.stream},
|
||||
{operator: "topic", operand: compose_args.topic},
|
||||
],
|
||||
{trigger: "edit scheduled message"},
|
||||
);
|
||||
} else {
|
||||
narrow.activate([{operator: "dm", operand: compose_args.private_message_recipient}], {
|
||||
trigger: "edit scheduled message",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export function open_scheduled_message_in_compose(scheduled_msg, should_narrow_to_recipient) {
|
||||
let compose_args;
|
||||
if (scheduled_msg.type === "stream") {
|
||||
compose_args = {
|
||||
type: "stream",
|
||||
stream: sub_store.maybe_get_stream_name(scheduled_msg.to),
|
||||
topic: scheduled_msg.topic,
|
||||
content: scheduled_msg.content,
|
||||
};
|
||||
} else {
|
||||
const recipient_emails = [];
|
||||
if (scheduled_msg.to) {
|
||||
for (const recipient_id of scheduled_msg.to) {
|
||||
recipient_emails.push(people.get_by_user_id(recipient_id).email);
|
||||
}
|
||||
}
|
||||
compose_args = {
|
||||
type: scheduled_msg.type,
|
||||
private_message_recipient: recipient_emails.join(","),
|
||||
content: scheduled_msg.content,
|
||||
};
|
||||
}
|
||||
|
||||
if (should_narrow_to_recipient) {
|
||||
narrow_via_edit_scheduled_message(compose_args);
|
||||
}
|
||||
|
||||
compose.clear_compose_box();
|
||||
compose_banner.clear_message_sent_banners(false);
|
||||
compose_actions.start(compose_args.type, compose_args);
|
||||
compose_ui.autosize_textarea($("#compose-textarea"));
|
||||
set_selected_schedule_timestamp(scheduled_msg.scheduled_delivery_timestamp);
|
||||
}
|
||||
|
||||
function show_message_unscheduled_banner(scheduled_delivery_timestamp) {
|
||||
const deliver_at = timerender.get_full_datetime(
|
||||
new Date(scheduled_delivery_timestamp * 1000),
|
||||
"time",
|
||||
);
|
||||
const unscheduled_banner = render_compose_banner({
|
||||
banner_type: compose_banner.WARNING,
|
||||
banner_text: $t({
|
||||
defaultMessage: "This message is no longer scheduled to be sent.",
|
||||
}),
|
||||
button_text: $t({defaultMessage: "Schedule for {deliver_at}"}, {deliver_at}),
|
||||
classname: compose_banner.CLASSNAMES.unscheduled_message,
|
||||
});
|
||||
compose_banner.append_compose_banner_to_banner_list(unscheduled_banner, $("#compose_banners"));
|
||||
}
|
||||
|
||||
export function edit_scheduled_message(scheduled_message_id, should_narrow_to_recipient = true) {
|
||||
const scheduled_msg = scheduled_messages_data[scheduled_message_id];
|
||||
delete_scheduled_message(scheduled_message_id, () => {
|
||||
open_scheduled_message_in_compose(scheduled_msg, should_narrow_to_recipient);
|
||||
show_message_unscheduled_banner(scheduled_msg.scheduled_delivery_timestamp);
|
||||
});
|
||||
}
|
||||
|
||||
export function delete_scheduled_message(scheduled_msg_id, success = () => {}) {
|
||||
channel.del({
|
||||
url: "/json/scheduled_messages/" + scheduled_msg_id,
|
||||
|
@ -303,17 +211,4 @@ export function reset_selected_schedule_timestamp() {
|
|||
|
||||
export function initialize(scheduled_messages_params) {
|
||||
add_scheduled_messages(scheduled_messages_params.scheduled_messages);
|
||||
|
||||
$("body").on("click", ".undo_scheduled_message", (e) => {
|
||||
const scheduled_message_id = Number.parseInt(
|
||||
$(e.target)
|
||||
.parents(".message_scheduled_success_compose_banner")
|
||||
.attr("data-scheduled-message-id"),
|
||||
10,
|
||||
);
|
||||
const should_narrow_to_recipient = false;
|
||||
edit_scheduled_message(scheduled_message_id, should_narrow_to_recipient);
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import * as messages_overlay_ui from "./messages_overlay_ui";
|
|||
import * as overlays from "./overlays";
|
||||
import * as people from "./people";
|
||||
import * as scheduled_messages from "./scheduled_messages";
|
||||
import * as scheduled_messages_ui from "./scheduled_messages_ui";
|
||||
import * as stream_color from "./stream_color";
|
||||
import * as stream_data from "./stream_data";
|
||||
import * as sub_store from "./sub_store";
|
||||
|
@ -27,7 +28,7 @@ export const keyboard_handling_context = {
|
|||
messages_overlay_ui.get_focused_element_id(this),
|
||||
10,
|
||||
);
|
||||
scheduled_messages.edit_scheduled_message(focused_element_id);
|
||||
scheduled_messages_ui.edit_scheduled_message(focused_element_id);
|
||||
overlays.close_overlay("scheduled");
|
||||
},
|
||||
on_delete() {
|
||||
|
@ -132,7 +133,7 @@ export function initialize() {
|
|||
.closest(".scheduled-message-row")
|
||||
.attr("data-scheduled-message-id");
|
||||
scheduled_msg_id = Number.parseInt(scheduled_msg_id, 10);
|
||||
scheduled_messages.edit_scheduled_message(scheduled_msg_id);
|
||||
scheduled_messages_ui.edit_scheduled_message(scheduled_msg_id);
|
||||
overlays.close_overlay("scheduled");
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
|
|
|
@ -0,0 +1,109 @@
|
|||
import $ from "jquery";
|
||||
|
||||
import render_compose_banner from "../templates/compose_banner/compose_banner.hbs";
|
||||
|
||||
import * as compose from "./compose";
|
||||
import * as compose_actions from "./compose_actions";
|
||||
import * as compose_banner from "./compose_banner";
|
||||
import * as compose_ui from "./compose_ui";
|
||||
import {$t} from "./i18n";
|
||||
import * as narrow from "./narrow";
|
||||
import * as people from "./people";
|
||||
import * as scheduled_messages from "./scheduled_messages";
|
||||
import * as sub_store from "./sub_store";
|
||||
import * as timerender from "./timerender";
|
||||
|
||||
export function hide_scheduled_message_success_compose_banner(scheduled_message_id) {
|
||||
$(
|
||||
`.message_scheduled_success_compose_banner[data-scheduled-message-id=${scheduled_message_id}]`,
|
||||
).hide();
|
||||
}
|
||||
|
||||
function narrow_via_edit_scheduled_message(compose_args) {
|
||||
if (compose_args.type === "stream") {
|
||||
narrow.activate(
|
||||
[
|
||||
{operator: "stream", operand: compose_args.stream},
|
||||
{operator: "topic", operand: compose_args.topic},
|
||||
],
|
||||
{trigger: "edit scheduled message"},
|
||||
);
|
||||
} else {
|
||||
narrow.activate([{operator: "dm", operand: compose_args.private_message_recipient}], {
|
||||
trigger: "edit scheduled message",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export function open_scheduled_message_in_compose(scheduled_msg, should_narrow_to_recipient) {
|
||||
let compose_args;
|
||||
if (scheduled_msg.type === "stream") {
|
||||
compose_args = {
|
||||
type: "stream",
|
||||
stream: sub_store.maybe_get_stream_name(scheduled_msg.to),
|
||||
topic: scheduled_msg.topic,
|
||||
content: scheduled_msg.content,
|
||||
};
|
||||
} else {
|
||||
const recipient_emails = [];
|
||||
if (scheduled_msg.to) {
|
||||
for (const recipient_id of scheduled_msg.to) {
|
||||
recipient_emails.push(people.get_by_user_id(recipient_id).email);
|
||||
}
|
||||
}
|
||||
compose_args = {
|
||||
type: scheduled_msg.type,
|
||||
private_message_recipient: recipient_emails.join(","),
|
||||
content: scheduled_msg.content,
|
||||
};
|
||||
}
|
||||
|
||||
if (should_narrow_to_recipient) {
|
||||
narrow_via_edit_scheduled_message(compose_args);
|
||||
}
|
||||
|
||||
compose.clear_compose_box();
|
||||
compose_banner.clear_message_sent_banners(false);
|
||||
compose_actions.start(compose_args.type, compose_args);
|
||||
compose_ui.autosize_textarea($("#compose-textarea"));
|
||||
scheduled_messages.set_selected_schedule_timestamp(scheduled_msg.scheduled_delivery_timestamp);
|
||||
}
|
||||
|
||||
function show_message_unscheduled_banner(scheduled_delivery_timestamp) {
|
||||
const deliver_at = timerender.get_full_datetime(
|
||||
new Date(scheduled_delivery_timestamp * 1000),
|
||||
"time",
|
||||
);
|
||||
const unscheduled_banner = render_compose_banner({
|
||||
banner_type: compose_banner.WARNING,
|
||||
banner_text: $t({
|
||||
defaultMessage: "This message is no longer scheduled to be sent.",
|
||||
}),
|
||||
button_text: $t({defaultMessage: "Schedule for {deliver_at}"}, {deliver_at}),
|
||||
classname: compose_banner.CLASSNAMES.unscheduled_message,
|
||||
});
|
||||
compose_banner.append_compose_banner_to_banner_list(unscheduled_banner, $("#compose_banners"));
|
||||
}
|
||||
|
||||
export function edit_scheduled_message(scheduled_message_id, should_narrow_to_recipient = true) {
|
||||
const scheduled_msg = scheduled_messages.scheduled_messages_data[scheduled_message_id];
|
||||
scheduled_messages.delete_scheduled_message(scheduled_message_id, () => {
|
||||
open_scheduled_message_in_compose(scheduled_msg, should_narrow_to_recipient);
|
||||
show_message_unscheduled_banner(scheduled_msg.scheduled_delivery_timestamp);
|
||||
});
|
||||
}
|
||||
|
||||
export function initialize() {
|
||||
$("body").on("click", ".undo_scheduled_message", (e) => {
|
||||
const scheduled_message_id = Number.parseInt(
|
||||
$(e.target)
|
||||
.parents(".message_scheduled_success_compose_banner")
|
||||
.attr("data-scheduled-message-id"),
|
||||
10,
|
||||
);
|
||||
const should_narrow_to_recipient = false;
|
||||
edit_scheduled_message(scheduled_message_id, should_narrow_to_recipient);
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
});
|
||||
}
|
|
@ -41,6 +41,7 @@ import {realm_user_settings_defaults} from "./realm_user_settings_defaults";
|
|||
import * as reload from "./reload";
|
||||
import * as scheduled_messages from "./scheduled_messages";
|
||||
import * as scheduled_messages_overlay_ui from "./scheduled_messages_overlay_ui";
|
||||
import * as scheduled_messages_ui from "./scheduled_messages_ui";
|
||||
import * as scroll_bar from "./scroll_bar";
|
||||
import * as settings_account from "./settings_account";
|
||||
import * as settings_bots from "./settings_bots";
|
||||
|
@ -496,6 +497,9 @@ export function dispatch_normal_event(event) {
|
|||
}
|
||||
case "remove": {
|
||||
scheduled_messages.remove_scheduled_message(event.scheduled_message_id);
|
||||
scheduled_messages_ui.hide_scheduled_message_success_compose_banner(
|
||||
event.scheduled_message_id,
|
||||
);
|
||||
scheduled_messages_overlay_ui.remove_scheduled_message_id(
|
||||
event.scheduled_message_id,
|
||||
);
|
||||
|
|
|
@ -87,6 +87,7 @@ import * as resize from "./resize";
|
|||
import * as scheduled_messages from "./scheduled_messages";
|
||||
import * as scheduled_messages_overlay_ui from "./scheduled_messages_overlay_ui";
|
||||
import * as scheduled_messages_popover from "./scheduled_messages_popover";
|
||||
import * as scheduled_messages_ui from "./scheduled_messages_ui";
|
||||
import * as scroll_bar from "./scroll_bar";
|
||||
import * as scroll_util from "./scroll_util";
|
||||
import * as search from "./search";
|
||||
|
@ -530,6 +531,7 @@ export function initialize_everything() {
|
|||
message_list_tooltips.initialize();
|
||||
// This populates data for scheduled messages.
|
||||
scheduled_messages.initialize(scheduled_messages_params);
|
||||
scheduled_messages_ui.initialize();
|
||||
popover_menus.initialize();
|
||||
compose_popovers.initialize();
|
||||
left_sidebar_navigation_area_popovers.initialize();
|
||||
|
|
Loading…
Reference in New Issue