mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 22:43:42 +00:00
compose_ui: Add message_type to ComposeTriggeredOptions.
This commit is contained in:
@@ -22,14 +22,20 @@ import * as stream_data from "./stream_data";
|
||||
import * as user_status from "./user_status";
|
||||
import * as util from "./util";
|
||||
|
||||
// TODO: Refactor to push this into a field of ComposeTriggeredOptions.
|
||||
type MessageType = "stream" | "private";
|
||||
type ComposeTriggeredOptions = {
|
||||
trigger: string;
|
||||
private_message_recipient: string;
|
||||
topic: string;
|
||||
stream_id: number;
|
||||
};
|
||||
} & (
|
||||
| {
|
||||
message_type: "stream";
|
||||
topic: string;
|
||||
stream_id: number;
|
||||
}
|
||||
| {
|
||||
message_type: "private";
|
||||
private_message_recipient: string;
|
||||
}
|
||||
);
|
||||
type ComposePlaceholderOptions = {
|
||||
direct_message_user_ids: number[];
|
||||
message_type: MessageType;
|
||||
@@ -87,14 +93,14 @@ export function insert_and_scroll_into_view(
|
||||
autosize_textarea($textarea);
|
||||
}
|
||||
|
||||
function get_focus_area(msg_type: MessageType, opts: ComposeTriggeredOptions): string {
|
||||
function get_focus_area(opts: ComposeTriggeredOptions): string {
|
||||
// Set focus to "Topic" when narrowed to a stream+topic
|
||||
// and "Start new conversation" button clicked.
|
||||
if (msg_type === "stream" && opts.stream_id && !opts.topic) {
|
||||
if (opts.message_type === "stream" && opts.stream_id && !opts.topic) {
|
||||
return "input#stream_message_recipient_topic";
|
||||
} else if (
|
||||
(msg_type === "stream" && opts.stream_id) ||
|
||||
(msg_type === "private" && opts.private_message_recipient)
|
||||
(opts.message_type === "stream" && opts.stream_id) ||
|
||||
(opts.message_type === "private" && opts.private_message_recipient)
|
||||
) {
|
||||
if (opts.trigger === "clear topic button") {
|
||||
return "input#stream_message_recipient_topic";
|
||||
@@ -102,7 +108,7 @@ function get_focus_area(msg_type: MessageType, opts: ComposeTriggeredOptions): s
|
||||
return "textarea#compose-textarea";
|
||||
}
|
||||
|
||||
if (msg_type === "stream") {
|
||||
if (opts.message_type === "stream") {
|
||||
return "#compose_select_recipient_widget_wrapper";
|
||||
}
|
||||
return "#private_message_recipient";
|
||||
@@ -111,12 +117,12 @@ function get_focus_area(msg_type: MessageType, opts: ComposeTriggeredOptions): s
|
||||
// Export for testing
|
||||
export const _get_focus_area = get_focus_area;
|
||||
|
||||
export function set_focus(msg_type: MessageType, opts: ComposeTriggeredOptions): void {
|
||||
export function set_focus(opts: ComposeTriggeredOptions): void {
|
||||
// Called mainly when opening the compose box or switching the
|
||||
// message type to set the focus in the first empty input in the
|
||||
// compose box.
|
||||
if (window.getSelection()!.toString() === "" || opts.trigger !== "message click") {
|
||||
const focus_area = get_focus_area(msg_type, opts);
|
||||
const focus_area = get_focus_area(opts);
|
||||
$(focus_area).trigger("focus");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user