2021-04-15 02:59:34 +02:00
|
|
|
import $ from "jquery";
|
|
|
|
|
2021-05-05 05:51:55 +02:00
|
|
|
import * as compose_actions from "./compose_actions";
|
2021-05-10 14:01:27 +02:00
|
|
|
import {$t} from "./i18n";
|
2021-04-15 02:59:34 +02:00
|
|
|
import * as message_lists from "./message_lists";
|
2021-05-10 17:21:20 +02:00
|
|
|
import * as message_store from "./message_store";
|
|
|
|
import * as narrow_state from "./narrow_state";
|
|
|
|
import * as people from "./people";
|
2023-07-26 22:07:21 +02:00
|
|
|
import * as stream_data from "./stream_data";
|
2021-04-15 02:59:34 +02:00
|
|
|
|
2024-04-11 19:44:26 +02:00
|
|
|
function format_stream_recipient_label(stream_id: number, topic: string): string {
|
2024-05-09 07:22:45 +02:00
|
|
|
const stream = stream_data.get_sub_by_id(stream_id);
|
|
|
|
if (stream) {
|
|
|
|
return "#" + stream.name + " > " + topic;
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2024-04-11 19:44:26 +02:00
|
|
|
type ComposeClosedMessage = {
|
2024-05-16 05:05:29 +02:00
|
|
|
stream_id?: number | undefined;
|
2024-04-11 19:44:26 +02:00
|
|
|
topic?: string;
|
2024-05-16 05:05:29 +02:00
|
|
|
display_reply_to?: string | undefined;
|
2024-04-11 19:44:26 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
export function get_recipient_label(message?: ComposeClosedMessage): string {
|
2022-04-24 06:13:19 +02:00
|
|
|
// TODO: This code path is bit of a type-checking disaster; we mix
|
|
|
|
// actual message objects with fake objects containing just a
|
|
|
|
// couple fields, both those constructed here and potentially
|
|
|
|
// passed in.
|
2024-02-05 19:03:29 +01:00
|
|
|
if (message_lists.current === undefined) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2021-07-30 19:58:32 +02:00
|
|
|
if (message === undefined) {
|
2023-05-02 04:04:46 +02:00
|
|
|
if (message_lists.current.visibly_empty()) {
|
2021-07-30 19:58:32 +02:00
|
|
|
// For empty narrows where there's a clear reply target,
|
2023-06-16 13:23:39 +02:00
|
|
|
// i.e. stream+topic or a single direct message conversation,
|
|
|
|
// we label the button as replying to the thread.
|
2024-05-23 23:45:54 +02:00
|
|
|
const stream_id = narrow_state.stream_sub()?.stream_id;
|
|
|
|
const topic = narrow_state.topic();
|
|
|
|
if (stream_id !== undefined && topic !== undefined) {
|
2024-05-09 07:22:45 +02:00
|
|
|
return format_stream_recipient_label(stream_id, topic);
|
2022-05-26 04:20:07 +02:00
|
|
|
} else if (narrow_state.pm_ids_string()) {
|
2024-04-11 19:44:26 +02:00
|
|
|
const user_ids = people.user_ids_string_to_ids_array(narrow_state.pm_ids_string()!);
|
2024-05-09 07:50:33 +02:00
|
|
|
return message_store.get_pm_full_names(user_ids);
|
2021-07-30 19:58:32 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
message = message_lists.current.selected_message();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (message) {
|
2023-07-26 22:07:21 +02:00
|
|
|
if (message.stream_id && message.topic) {
|
2024-05-09 07:22:45 +02:00
|
|
|
return format_stream_recipient_label(message.stream_id, message.topic);
|
2021-07-30 19:58:32 +02:00
|
|
|
} else if (message.display_reply_to) {
|
|
|
|
return message.display_reply_to;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2024-04-11 19:44:26 +02:00
|
|
|
function update_reply_button_state(disable = false): void {
|
|
|
|
$(".compose_reply_button").attr("disabled", disable ? "disabled" : null);
|
compose_box: Convert dynamic closed compose box tooltips to tippyjs.
This commit converts the dynamic closed_compose_box
tooltip to template-based tippy.js tooltips. The functions in
the compose_closed_ui.js file are refactored to dynamically change
the 'data-tooltip-template-id' attribute according to the situation.
The title parameter is removed from the functions in
compose_closed_ui.js so that we can change the tooltip within the
caller functions themselves, according to the situation. Since there
is no way to match the title in existing functions with different
languages to change the tooltip attribute dynamically, it is better
to change the tooltip attribute within the caller function according
to the situation, rather than passing the title as a parameter.
In the case of the reply button, we disable it when direct messages
are not allowed. However, tippy.js tooltips do not appear in the
case of disabled elements, so we have to use the container element
around it to show the tooltip. This approach is used in the case of
the reply button, where the span element wraps the button.
We used to have two titles for the reply button: one is the usual
'Reply to selected message', and the other is for the disabled state.
However, in the case of recent conversations, it makes more sense
to have a new tooltip title: 'Reply to selected conversation'.
To ensure that the tooltip content changes dynamically, it is
required to destroy the tooltip instance and then reinitialize it
every time.
Fixes: #25096
2023-04-13 16:22:02 +02:00
|
|
|
if (disable) {
|
2023-12-20 04:08:58 +01:00
|
|
|
$("#compose_buttons .compose-reply-button-wrapper").attr(
|
2024-04-09 07:56:36 +02:00
|
|
|
"data-reply-button-type",
|
|
|
|
"direct_disabled",
|
compose_box: Convert dynamic closed compose box tooltips to tippyjs.
This commit converts the dynamic closed_compose_box
tooltip to template-based tippy.js tooltips. The functions in
the compose_closed_ui.js file are refactored to dynamically change
the 'data-tooltip-template-id' attribute according to the situation.
The title parameter is removed from the functions in
compose_closed_ui.js so that we can change the tooltip within the
caller functions themselves, according to the situation. Since there
is no way to match the title in existing functions with different
languages to change the tooltip attribute dynamically, it is better
to change the tooltip attribute within the caller function according
to the situation, rather than passing the title as a parameter.
In the case of the reply button, we disable it when direct messages
are not allowed. However, tippy.js tooltips do not appear in the
case of disabled elements, so we have to use the container element
around it to show the tooltip. This approach is used in the case of
the reply button, where the span element wraps the button.
We used to have two titles for the reply button: one is the usual
'Reply to selected message', and the other is for the disabled state.
However, in the case of recent conversations, it makes more sense
to have a new tooltip title: 'Reply to selected conversation'.
To ensure that the tooltip content changes dynamically, it is
required to destroy the tooltip instance and then reinitialize it
every time.
Fixes: #25096
2023-04-13 16:22:02 +02:00
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (narrow_state.is_message_feed_visible()) {
|
2023-12-20 04:08:58 +01:00
|
|
|
$("#compose_buttons .compose-reply-button-wrapper").attr(
|
2024-04-09 07:56:36 +02:00
|
|
|
"data-reply-button-type",
|
|
|
|
"selected_message",
|
compose_box: Convert dynamic closed compose box tooltips to tippyjs.
This commit converts the dynamic closed_compose_box
tooltip to template-based tippy.js tooltips. The functions in
the compose_closed_ui.js file are refactored to dynamically change
the 'data-tooltip-template-id' attribute according to the situation.
The title parameter is removed from the functions in
compose_closed_ui.js so that we can change the tooltip within the
caller functions themselves, according to the situation. Since there
is no way to match the title in existing functions with different
languages to change the tooltip attribute dynamically, it is better
to change the tooltip attribute within the caller function according
to the situation, rather than passing the title as a parameter.
In the case of the reply button, we disable it when direct messages
are not allowed. However, tippy.js tooltips do not appear in the
case of disabled elements, so we have to use the container element
around it to show the tooltip. This approach is used in the case of
the reply button, where the span element wraps the button.
We used to have two titles for the reply button: one is the usual
'Reply to selected message', and the other is for the disabled state.
However, in the case of recent conversations, it makes more sense
to have a new tooltip title: 'Reply to selected conversation'.
To ensure that the tooltip content changes dynamically, it is
required to destroy the tooltip instance and then reinitialize it
every time.
Fixes: #25096
2023-04-13 16:22:02 +02:00
|
|
|
);
|
|
|
|
} else {
|
2023-12-20 04:08:58 +01:00
|
|
|
$("#compose_buttons .compose-reply-button-wrapper").attr(
|
2024-04-09 07:56:36 +02:00
|
|
|
"data-reply-button-type",
|
|
|
|
"selected_conversation",
|
compose_box: Convert dynamic closed compose box tooltips to tippyjs.
This commit converts the dynamic closed_compose_box
tooltip to template-based tippy.js tooltips. The functions in
the compose_closed_ui.js file are refactored to dynamically change
the 'data-tooltip-template-id' attribute according to the situation.
The title parameter is removed from the functions in
compose_closed_ui.js so that we can change the tooltip within the
caller functions themselves, according to the situation. Since there
is no way to match the title in existing functions with different
languages to change the tooltip attribute dynamically, it is better
to change the tooltip attribute within the caller function according
to the situation, rather than passing the title as a parameter.
In the case of the reply button, we disable it when direct messages
are not allowed. However, tippy.js tooltips do not appear in the
case of disabled elements, so we have to use the container element
around it to show the tooltip. This approach is used in the case of
the reply button, where the span element wraps the button.
We used to have two titles for the reply button: one is the usual
'Reply to selected message', and the other is for the disabled state.
However, in the case of recent conversations, it makes more sense
to have a new tooltip title: 'Reply to selected conversation'.
To ensure that the tooltip content changes dynamically, it is
required to destroy the tooltip instance and then reinitialize it
every time.
Fixes: #25096
2023-04-13 16:22:02 +02:00
|
|
|
);
|
2023-01-03 08:29:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-11 19:44:26 +02:00
|
|
|
function update_new_conversation_button(
|
|
|
|
btn_text: string,
|
|
|
|
is_direct_message_narrow?: boolean,
|
|
|
|
): void {
|
2023-10-04 21:39:33 +02:00
|
|
|
const $new_conversation_button = $("#new_conversation_button");
|
|
|
|
$new_conversation_button.text(btn_text);
|
|
|
|
// In a direct-message narrow, the new conversation button should act
|
|
|
|
// like a new direct message button
|
|
|
|
if (is_direct_message_narrow) {
|
|
|
|
$new_conversation_button.addClass("compose_new_direct_message_button");
|
|
|
|
$new_conversation_button.removeClass("compose_new_conversation_button");
|
|
|
|
} else {
|
|
|
|
// Restore the usual new conversation button class, if it was
|
|
|
|
// changed after a previous direct-message narrow visit
|
|
|
|
$new_conversation_button.addClass("compose_new_conversation_button");
|
|
|
|
$new_conversation_button.removeClass("compose_new_direct_message_button");
|
|
|
|
}
|
2021-05-11 22:04:35 +02:00
|
|
|
}
|
|
|
|
|
2024-04-11 19:44:26 +02:00
|
|
|
function update_new_direct_message_button(btn_text: string): void {
|
2023-10-04 21:06:27 +02:00
|
|
|
$("#new_direct_message_button").text(btn_text);
|
2021-05-11 22:04:35 +02:00
|
|
|
}
|
|
|
|
|
2024-04-11 19:44:26 +02:00
|
|
|
function toggle_direct_message_button_visibility(is_direct_message_narrow?: boolean): void {
|
2023-10-04 21:44:46 +02:00
|
|
|
const $new_direct_message_button_container = $(".new_direct_message_button_container");
|
|
|
|
if (is_direct_message_narrow) {
|
|
|
|
$new_direct_message_button_container.hide();
|
|
|
|
} else {
|
|
|
|
$new_direct_message_button_container.show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-11 19:44:26 +02:00
|
|
|
function update_buttons(
|
|
|
|
text_stream: string,
|
|
|
|
is_direct_message_narrow?: boolean,
|
|
|
|
disable_reply?: boolean,
|
|
|
|
): void {
|
2023-01-24 19:49:56 +01:00
|
|
|
const text_conversation = $t({defaultMessage: "New direct message"});
|
2023-10-04 21:39:33 +02:00
|
|
|
update_new_conversation_button(text_stream, is_direct_message_narrow);
|
2023-10-04 21:06:27 +02:00
|
|
|
update_new_direct_message_button(text_conversation);
|
compose_box: Convert dynamic closed compose box tooltips to tippyjs.
This commit converts the dynamic closed_compose_box
tooltip to template-based tippy.js tooltips. The functions in
the compose_closed_ui.js file are refactored to dynamically change
the 'data-tooltip-template-id' attribute according to the situation.
The title parameter is removed from the functions in
compose_closed_ui.js so that we can change the tooltip within the
caller functions themselves, according to the situation. Since there
is no way to match the title in existing functions with different
languages to change the tooltip attribute dynamically, it is better
to change the tooltip attribute within the caller function according
to the situation, rather than passing the title as a parameter.
In the case of the reply button, we disable it when direct messages
are not allowed. However, tippy.js tooltips do not appear in the
case of disabled elements, so we have to use the container element
around it to show the tooltip. This approach is used in the case of
the reply button, where the span element wraps the button.
We used to have two titles for the reply button: one is the usual
'Reply to selected message', and the other is for the disabled state.
However, in the case of recent conversations, it makes more sense
to have a new tooltip title: 'Reply to selected conversation'.
To ensure that the tooltip content changes dynamically, it is
required to destroy the tooltip instance and then reinitialize it
every time.
Fixes: #25096
2023-04-13 16:22:02 +02:00
|
|
|
update_reply_button_state(disable_reply);
|
2023-10-04 21:44:46 +02:00
|
|
|
toggle_direct_message_button_visibility(is_direct_message_narrow);
|
2021-05-11 22:04:35 +02:00
|
|
|
}
|
|
|
|
|
2024-04-11 19:44:26 +02:00
|
|
|
export function update_buttons_for_private(): void {
|
2023-10-04 16:11:48 +02:00
|
|
|
const text_stream = $t({defaultMessage: "Start new conversation"});
|
2023-10-04 21:39:33 +02:00
|
|
|
const is_direct_message_narrow = true;
|
2024-04-11 19:44:26 +02:00
|
|
|
const pm_ids_string = narrow_state.pm_ids_string();
|
|
|
|
if (!pm_ids_string || people.user_can_direct_message(pm_ids_string)) {
|
2023-12-16 03:32:31 +01:00
|
|
|
$("#new_conversation_button").attr("data-conversation-type", "direct");
|
2023-10-04 21:39:33 +02:00
|
|
|
update_buttons(text_stream, is_direct_message_narrow);
|
2023-01-03 08:29:15 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// disable the [Message X] button when in a private narrow
|
|
|
|
// if the user cannot dm the current recipient
|
|
|
|
const disable_reply = true;
|
2023-10-04 21:39:33 +02:00
|
|
|
update_buttons(text_stream, is_direct_message_narrow, disable_reply);
|
2021-05-11 22:04:35 +02:00
|
|
|
}
|
|
|
|
|
2024-04-11 19:44:26 +02:00
|
|
|
export function update_buttons_for_stream_views(): void {
|
2023-10-04 16:11:48 +02:00
|
|
|
const text_stream = $t({defaultMessage: "Start new conversation"});
|
2023-12-16 03:32:31 +01:00
|
|
|
$("#new_conversation_button").attr("data-conversation-type", "stream");
|
2021-05-11 22:04:35 +02:00
|
|
|
update_buttons(text_stream);
|
|
|
|
}
|
|
|
|
|
2024-04-11 19:44:26 +02:00
|
|
|
export function update_buttons_for_non_specific_views(): void {
|
2023-10-04 16:11:48 +02:00
|
|
|
const text_stream = $t({defaultMessage: "Start new conversation"});
|
2024-02-25 21:54:42 +01:00
|
|
|
$("#new_conversation_button").attr("data-conversation-type", "non-specific");
|
2021-05-11 22:04:35 +02:00
|
|
|
update_buttons(text_stream);
|
|
|
|
}
|
|
|
|
|
2024-04-11 19:44:26 +02:00
|
|
|
function set_reply_button_label(label: string): void {
|
2023-06-20 15:08:26 +02:00
|
|
|
$("#left_bar_compose_reply_button_big").text(label);
|
2021-05-10 14:01:27 +02:00
|
|
|
}
|
|
|
|
|
2024-04-11 19:44:26 +02:00
|
|
|
export function set_standard_text_for_reply_button(): void {
|
2021-05-10 14:05:30 +02:00
|
|
|
set_reply_button_label($t({defaultMessage: "Compose message"}));
|
2021-05-07 18:38:01 +02:00
|
|
|
}
|
|
|
|
|
2024-04-11 19:44:26 +02:00
|
|
|
export function update_reply_recipient_label(message?: ComposeClosedMessage): void {
|
2021-07-30 19:58:32 +02:00
|
|
|
const recipient_label = get_recipient_label(message);
|
|
|
|
if (recipient_label) {
|
2021-05-10 17:21:20 +02:00
|
|
|
set_reply_button_label(
|
|
|
|
$t({defaultMessage: "Message {recipient_label}"}, {recipient_label}),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
set_standard_text_for_reply_button();
|
2021-04-15 02:59:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-11 19:44:26 +02:00
|
|
|
export function initialize(): void {
|
2021-04-15 02:59:34 +02:00
|
|
|
// When the message selection changes, change the label on the Reply button.
|
|
|
|
$(document).on("message_selected.zulip", () => {
|
2023-02-14 06:42:58 +01:00
|
|
|
if (narrow_state.is_message_feed_visible()) {
|
2023-09-06 23:04:07 +02:00
|
|
|
// message_selected events can occur with Recent Conversations
|
2024-04-02 13:10:48 +02:00
|
|
|
// open due to the combined feed view loading in the background,
|
2023-02-14 06:42:58 +01:00
|
|
|
// so we only update if message feed is visible.
|
|
|
|
update_reply_recipient_label();
|
2021-05-10 17:21:20 +02:00
|
|
|
}
|
2021-04-15 02:59:34 +02:00
|
|
|
});
|
2021-05-05 05:51:55 +02:00
|
|
|
|
2022-02-08 00:13:33 +01:00
|
|
|
// Click handlers for buttons in the compose box.
|
2023-10-04 16:11:48 +02:00
|
|
|
$("body").on("click", ".compose_new_conversation_button", () => {
|
2024-04-04 02:38:16 +02:00
|
|
|
compose_actions.start({
|
|
|
|
message_type: "stream",
|
|
|
|
trigger: "clear topic button",
|
2024-03-01 20:30:53 +01:00
|
|
|
keep_composebox_empty: true,
|
2024-04-04 02:38:16 +02:00
|
|
|
});
|
2021-05-05 05:51:55 +02:00
|
|
|
});
|
|
|
|
|
2023-10-04 21:06:27 +02:00
|
|
|
$("body").on("click", ".compose_new_direct_message_button", () => {
|
2024-04-04 02:38:16 +02:00
|
|
|
compose_actions.start({
|
|
|
|
message_type: "private",
|
|
|
|
trigger: "new direct message",
|
2024-03-01 20:30:53 +01:00
|
|
|
keep_composebox_empty: true,
|
2024-04-04 02:38:16 +02:00
|
|
|
});
|
2021-05-05 05:51:55 +02:00
|
|
|
});
|
2021-04-15 02:59:34 +02:00
|
|
|
}
|