mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 06:23:38 +00:00
compose_actions: Include message type in opts for start.
This commit is contained in:
@@ -703,11 +703,17 @@ export function initialize() {
|
||||
// COMPOSE
|
||||
|
||||
$("body").on("click", ".empty_feed_compose_stream", (e) => {
|
||||
compose_actions.start("stream", {trigger: "empty feed message"});
|
||||
compose_actions.start({
|
||||
message_type: "stream",
|
||||
trigger: "empty feed message",
|
||||
});
|
||||
e.preventDefault();
|
||||
});
|
||||
$("body").on("click", ".empty_feed_compose_private", (e) => {
|
||||
compose_actions.start("private", {trigger: "empty feed message"});
|
||||
compose_actions.start({
|
||||
message_type: "private",
|
||||
trigger: "empty feed message",
|
||||
});
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
|
||||
@@ -183,18 +183,18 @@ function same_recipient_as_before(opts) {
|
||||
);
|
||||
}
|
||||
|
||||
export function start(msg_type, opts) {
|
||||
export function start(opts) {
|
||||
if (page_params.is_spectator) {
|
||||
spectators.login_to_access();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!msg_type) {
|
||||
if (!opts.message_type) {
|
||||
// We prefer callers to be explicit about the message type, but
|
||||
// we if we don't know, we open a stream compose box by default,
|
||||
// which opens stream selection dropdown.
|
||||
// Also, msg_type is used to check if compose box is open in compose_state.composing().
|
||||
msg_type = "stream";
|
||||
// Also, message_type is used to check if compose box is open in compose_state.composing().
|
||||
opts.message_type = "stream";
|
||||
blueslip.warn("Empty message type in compose.start");
|
||||
}
|
||||
|
||||
@@ -207,7 +207,7 @@ export function start(msg_type, opts) {
|
||||
compose_banner.clear_message_sent_banners();
|
||||
expand_compose_box();
|
||||
|
||||
opts = fill_in_opts_from_current_narrowed_view(msg_type, opts);
|
||||
opts = fill_in_opts_from_current_narrowed_view(opts.message_type, opts);
|
||||
const is_clear_topic_button_triggered = opts.trigger === "clear topic button";
|
||||
|
||||
// If we are invoked by a compose hotkey (c or x) or new topic
|
||||
@@ -226,7 +226,7 @@ export function start(msg_type, opts) {
|
||||
if (
|
||||
subbed_streams.length === 1 &&
|
||||
(is_clear_topic_button_triggered ||
|
||||
(opts.trigger === "compose_hotkey" && msg_type === "stream"))
|
||||
(opts.trigger === "compose_hotkey" && opts.message_type === "stream"))
|
||||
) {
|
||||
opts.stream_id = subbed_streams[0].stream_id;
|
||||
}
|
||||
@@ -235,13 +235,13 @@ export function start(msg_type, opts) {
|
||||
// with (like from a draft), save any existing content as a draft, and clear the compose box.
|
||||
if (
|
||||
compose_state.composing() &&
|
||||
(!same_recipient_as_before({...opts, message_type: msg_type}) || opts.content !== undefined)
|
||||
(!same_recipient_as_before(opts) || opts.content !== undefined)
|
||||
) {
|
||||
drafts.update_draft();
|
||||
clear_box();
|
||||
}
|
||||
|
||||
if (msg_type === "private") {
|
||||
if (opts.message_type === "private") {
|
||||
compose_state.set_compose_recipient_id(compose_state.DIRECT_MESSAGE_ID);
|
||||
compose_recipient.on_compose_select_recipient_update();
|
||||
} else if (opts.stream_id) {
|
||||
@@ -266,13 +266,10 @@ export function start(msg_type, opts) {
|
||||
$(".compose_control_button_container:has(.add-poll)").addClass("disabled-on-hover");
|
||||
}
|
||||
|
||||
compose_state.set_message_type(msg_type);
|
||||
compose_state.set_message_type(opts.message_type);
|
||||
|
||||
// Show either stream/topic fields or "You and" field.
|
||||
show_compose_box({
|
||||
...opts,
|
||||
message_type: msg_type,
|
||||
});
|
||||
show_compose_box(opts);
|
||||
|
||||
if (opts.draft_id) {
|
||||
$("textarea#compose-textarea").data("draft-id", opts.draft_id);
|
||||
@@ -307,7 +304,7 @@ export function start(msg_type, opts) {
|
||||
// while writing a long message.
|
||||
resize.reset_compose_message_max_height();
|
||||
|
||||
complete_starting_tasks(msg_type, opts);
|
||||
complete_starting_tasks(opts.message_type, opts);
|
||||
}
|
||||
|
||||
export function cancel() {
|
||||
@@ -466,7 +463,10 @@ export function on_narrow(opts) {
|
||||
// the view's scroll position. recenter_view is responsible
|
||||
// for taking the open compose box into account when placing
|
||||
// the selecting message.
|
||||
start("private", {skip_scrolling_selected_message: true});
|
||||
start({
|
||||
message_type: "private",
|
||||
skip_scrolling_selected_message: true,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -183,10 +183,16 @@ export function initialize() {
|
||||
|
||||
// Click handlers for buttons in the compose box.
|
||||
$("body").on("click", ".compose_new_conversation_button", () => {
|
||||
compose_actions.start("stream", {trigger: "clear topic button"});
|
||||
compose_actions.start({
|
||||
message_type: "stream",
|
||||
trigger: "clear topic button",
|
||||
});
|
||||
});
|
||||
|
||||
$("body").on("click", ".compose_new_direct_message_button", () => {
|
||||
compose_actions.start("private", {trigger: "new direct message"});
|
||||
compose_actions.start({
|
||||
message_type: "private",
|
||||
trigger: "new direct message",
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -39,12 +39,17 @@ export function initialize() {
|
||||
onMount(instance) {
|
||||
const $popper = $(instance.popper);
|
||||
$popper.one("click", ".compose_mobile_stream_button", (e) => {
|
||||
compose_actions.start("stream", {trigger: "clear topic button"});
|
||||
compose_actions.start({
|
||||
mesage_type: "stream",
|
||||
trigger: "clear topic button",
|
||||
});
|
||||
e.stopPropagation();
|
||||
popover_menus.hide_current_popover_if_visible(instance);
|
||||
});
|
||||
$popper.one("click", ".compose_mobile_direct_message_button", (e) => {
|
||||
compose_actions.start("private");
|
||||
compose_actions.start({
|
||||
message_type: "private",
|
||||
});
|
||||
e.stopPropagation();
|
||||
popover_menus.hide_current_popover_if_visible(instance);
|
||||
});
|
||||
|
||||
@@ -28,7 +28,10 @@ export function respond_to_message(opts) {
|
||||
if (message === undefined) {
|
||||
// Open empty compose with nothing pre-filled since
|
||||
// user is not focused on any table row.
|
||||
compose_actions.start("stream", {trigger: "recent_view_nofocus"});
|
||||
compose_actions.start({
|
||||
message_type: "stream",
|
||||
trigger: "recent_view_nofocus",
|
||||
});
|
||||
return;
|
||||
}
|
||||
} else if (inbox_util.is_visible()) {
|
||||
@@ -36,7 +39,8 @@ export function respond_to_message(opts) {
|
||||
if (message_opts.message === undefined) {
|
||||
// If the user is not focused on inbox header, msg_type
|
||||
// is not defined, so we open empty compose with nothing prefilled.
|
||||
compose_actions.start(message_opts.msg_type ?? "stream", {
|
||||
compose_actions.start({
|
||||
message_type: message_opts.msg_type ?? "stream",
|
||||
trigger: "inbox_nofocus",
|
||||
...message_opts,
|
||||
});
|
||||
@@ -56,7 +60,10 @@ export function respond_to_message(opts) {
|
||||
!narrow_state.narrowed_by_stream_reply() &&
|
||||
!narrow_state.narrowed_by_topic_reply()
|
||||
) {
|
||||
compose_actions.start("stream", {trigger: "empty_narrow_compose"});
|
||||
compose_actions.start({
|
||||
message_type: "stream",
|
||||
trigger: "empty_narrow_compose",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const current_filter = narrow_state.filter();
|
||||
@@ -65,7 +72,10 @@ export function respond_to_message(opts) {
|
||||
const first_operand = first_term.operand;
|
||||
|
||||
if (first_operator === "stream" && !stream_data.is_subscribed_by_name(first_operand)) {
|
||||
compose_actions.start("stream", {trigger: "empty_narrow_compose"});
|
||||
compose_actions.start({
|
||||
message_type: "stream",
|
||||
trigger: "empty_narrow_compose",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -80,7 +90,7 @@ export function respond_to_message(opts) {
|
||||
msg_type,
|
||||
opts,
|
||||
);
|
||||
compose_actions.start(new_opts.message_type, new_opts);
|
||||
compose_actions.start(new_opts);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -113,7 +123,8 @@ export function respond_to_message(opts) {
|
||||
pm_recipient = people.pm_reply_to(message);
|
||||
}
|
||||
|
||||
compose_actions.start(msg_type, {
|
||||
compose_actions.start({
|
||||
message_type: msg_type,
|
||||
stream_id,
|
||||
topic,
|
||||
private_message_recipient: pm_recipient,
|
||||
|
||||
@@ -478,9 +478,12 @@ export function initialize() {
|
||||
|
||||
if (page_params.narrow !== undefined) {
|
||||
if (page_params.narrow_topic !== undefined) {
|
||||
compose_actions.start("stream", {topic: page_params.narrow_topic});
|
||||
compose_actions.start({
|
||||
message_type: "stream",
|
||||
topic: page_params.narrow_topic,
|
||||
});
|
||||
} else {
|
||||
compose_actions.start("stream", {});
|
||||
compose_actions.start({message_type: "stream"});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,10 @@ function restore_draft(draft_id) {
|
||||
}
|
||||
|
||||
overlays.close_overlay("drafts");
|
||||
compose_actions.start(compose_args.type, compose_args);
|
||||
compose_actions.start({
|
||||
...compose_args,
|
||||
message_type: compose_args.type,
|
||||
});
|
||||
}
|
||||
|
||||
function remove_draft($draft_row) {
|
||||
|
||||
@@ -998,12 +998,18 @@ export function process_hotkey(e, hotkey) {
|
||||
return true;
|
||||
case "compose": // 'c': compose
|
||||
if (!compose_state.composing()) {
|
||||
compose_actions.start("stream", {trigger: "compose_hotkey"});
|
||||
compose_actions.start({
|
||||
message_type: "stream",
|
||||
trigger: "compose_hotkey",
|
||||
});
|
||||
}
|
||||
return true;
|
||||
case "compose_private_message":
|
||||
if (!compose_state.composing()) {
|
||||
compose_actions.start("private", {trigger: "compose_hotkey"});
|
||||
compose_actions.start({
|
||||
message_type: "private",
|
||||
trigger: "compose_hotkey",
|
||||
});
|
||||
}
|
||||
return true;
|
||||
case "open_drafts":
|
||||
|
||||
@@ -50,7 +50,8 @@ export function initialize() {
|
||||
const send_now = Number.parseInt(vars.send_after_reload, 10);
|
||||
|
||||
try {
|
||||
compose_actions.start(vars.msg_type, {
|
||||
compose_actions.start({
|
||||
message_type: vars.msg_type,
|
||||
stream_id: Number.parseInt(vars.stream_id, 10) || undefined,
|
||||
topic: vars.topic || "",
|
||||
private_message_recipient: vars.recipient || "",
|
||||
|
||||
@@ -18,7 +18,7 @@ export function hide_scheduled_message_success_compose_banner(scheduled_message_
|
||||
}
|
||||
|
||||
function narrow_via_edit_scheduled_message(compose_args) {
|
||||
if (compose_args.type === "stream") {
|
||||
if (compose_args.message_type === "stream") {
|
||||
narrow.activate(
|
||||
[
|
||||
{
|
||||
@@ -40,7 +40,7 @@ export function open_scheduled_message_in_compose(scheduled_msg, should_narrow_t
|
||||
let compose_args;
|
||||
if (scheduled_msg.type === "stream") {
|
||||
compose_args = {
|
||||
type: "stream",
|
||||
message_type: "stream",
|
||||
stream_id: scheduled_msg.to,
|
||||
topic: scheduled_msg.topic,
|
||||
content: scheduled_msg.content,
|
||||
@@ -56,7 +56,7 @@ export function open_scheduled_message_in_compose(scheduled_msg, should_narrow_t
|
||||
}
|
||||
}
|
||||
compose_args = {
|
||||
type: scheduled_msg.type,
|
||||
message_type: scheduled_msg.type,
|
||||
private_message_recipient: recipient_emails.join(","),
|
||||
content: scheduled_msg.content,
|
||||
};
|
||||
@@ -66,7 +66,7 @@ export function open_scheduled_message_in_compose(scheduled_msg, should_narrow_t
|
||||
narrow_via_edit_scheduled_message(compose_args);
|
||||
}
|
||||
|
||||
compose_actions.start(compose_args.type, compose_args);
|
||||
compose_actions.start(compose_args);
|
||||
scheduled_messages.set_selected_schedule_timestamp(scheduled_msg.scheduled_delivery_timestamp);
|
||||
}
|
||||
|
||||
|
||||
@@ -156,7 +156,8 @@ function build_stream_popover(opts) {
|
||||
const sub = stream_popover_sub(e);
|
||||
hide_stream_popover();
|
||||
|
||||
compose_actions.start("stream", {
|
||||
compose_actions.start({
|
||||
message_type: "stream",
|
||||
trigger: "popover new topic button",
|
||||
stream_id: sub.stream_id,
|
||||
topic: "",
|
||||
|
||||
@@ -540,7 +540,10 @@ export function initialize() {
|
||||
upload_files(compose_upload_object, {mode: "compose"}, files);
|
||||
} else {
|
||||
// Start a new message in other views.
|
||||
compose_actions.start("stream", {trigger: "drag_drop_file"});
|
||||
compose_actions.start({
|
||||
message_type: "stream",
|
||||
trigger: "drag_drop_file",
|
||||
});
|
||||
upload_files(compose_upload_object, {mode: "compose"}, files);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -752,7 +752,10 @@ function register_click_handlers() {
|
||||
});
|
||||
$("body").on("click", ".user-card-popover-root .mention_user", (e) => {
|
||||
if (!compose_state.composing()) {
|
||||
compose_actions.start("stream", {trigger: "sidebar user actions"});
|
||||
compose_actions.start({
|
||||
message_type: "stream",
|
||||
trigger: "sidebar user actions",
|
||||
});
|
||||
}
|
||||
const user_id = elem_to_user_id($(e.target).parents("ul"));
|
||||
const name = people.get_by_user_id(user_id).full_name;
|
||||
@@ -848,7 +851,8 @@ function register_click_handlers() {
|
||||
$("body").on("click", ".respond_personal_button, .compose_private_message", (e) => {
|
||||
const user_id = elem_to_user_id($(e.target).parents("ul"));
|
||||
const email = people.get_by_user_id(user_id).email;
|
||||
compose_actions.start("private", {
|
||||
compose_actions.start({
|
||||
message_type: "private",
|
||||
trigger: "popover send private",
|
||||
private_message_recipient: email,
|
||||
});
|
||||
|
||||
@@ -485,8 +485,7 @@ test_ui("initialize", ({override}) => {
|
||||
let compose_actions_expected_opts;
|
||||
let compose_actions_start_checked;
|
||||
|
||||
override(compose_actions, "start", (msg_type, opts) => {
|
||||
assert.equal(msg_type, "stream");
|
||||
override(compose_actions, "start", (opts) => {
|
||||
assert.deepEqual(opts, compose_actions_expected_opts);
|
||||
compose_actions_start_checked = true;
|
||||
});
|
||||
@@ -518,7 +517,10 @@ test_ui("initialize", ({override}) => {
|
||||
|
||||
function set_up_compose_start_mock(expected_opts) {
|
||||
compose_actions_start_checked = false;
|
||||
compose_actions_expected_opts = expected_opts;
|
||||
compose_actions_expected_opts = {
|
||||
...expected_opts,
|
||||
message_type: "stream",
|
||||
};
|
||||
}
|
||||
|
||||
(function test_page_params_narrow_path() {
|
||||
|
||||
@@ -131,8 +131,10 @@ test("start", ({override, override_rewire, mock_template}) => {
|
||||
topic: "topic1",
|
||||
};
|
||||
|
||||
let opts = {};
|
||||
start("stream", opts);
|
||||
let opts = {
|
||||
message_type: "stream",
|
||||
};
|
||||
start(opts);
|
||||
|
||||
assert_visible("#compose_recipient_box");
|
||||
assert_hidden("#compose-direct-recipient");
|
||||
@@ -155,8 +157,10 @@ test("start", ({override, override_rewire, mock_template}) => {
|
||||
trigger: "clear topic button",
|
||||
};
|
||||
|
||||
opts = {};
|
||||
start("stream", opts);
|
||||
opts = {
|
||||
message_type: "stream",
|
||||
};
|
||||
start(opts);
|
||||
assert.equal(compose_state.stream_name(), "Denmark");
|
||||
assert.equal(compose_state.topic(), "");
|
||||
|
||||
@@ -164,8 +168,10 @@ test("start", ({override, override_rewire, mock_template}) => {
|
||||
trigger: "compose_hotkey",
|
||||
};
|
||||
|
||||
opts = {};
|
||||
start("stream", opts);
|
||||
opts = {
|
||||
message_type: "stream",
|
||||
};
|
||||
start(opts);
|
||||
assert.equal(compose_state.stream_name(), "Denmark");
|
||||
assert.equal(compose_state.topic(), "");
|
||||
|
||||
@@ -179,8 +185,10 @@ test("start", ({override, override_rewire, mock_template}) => {
|
||||
|
||||
compose_state.set_stream_id("");
|
||||
// More than 1 subscription, do not autofill
|
||||
opts = {};
|
||||
start("stream", opts);
|
||||
opts = {
|
||||
message_type: "stream",
|
||||
};
|
||||
start(opts);
|
||||
assert.equal(compose_state.stream_name(), "");
|
||||
assert.equal(compose_state.topic(), "");
|
||||
stream_data.clear_subscriptions();
|
||||
@@ -191,10 +199,11 @@ test("start", ({override, override_rewire, mock_template}) => {
|
||||
};
|
||||
|
||||
opts = {
|
||||
message_type: "private",
|
||||
content: "hello",
|
||||
};
|
||||
|
||||
start("private", opts);
|
||||
start(opts);
|
||||
|
||||
assert_hidden("input#stream_message_recipient_topic");
|
||||
assert_visible("#compose-direct-recipient");
|
||||
@@ -206,10 +215,11 @@ test("start", ({override, override_rewire, mock_template}) => {
|
||||
|
||||
// Triggered by new direct message
|
||||
opts = {
|
||||
message_type: "private",
|
||||
trigger: "new direct message",
|
||||
};
|
||||
|
||||
start("private", opts);
|
||||
start(opts);
|
||||
|
||||
assert.equal(compose_state.private_message_recipient(), "");
|
||||
assert.equal(compose_state.get_message_type(), "private");
|
||||
|
||||
Reference in New Issue
Block a user