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
|
|
|
|
2021-07-30 19:58:32 +02:00
|
|
|
export function get_recipient_label(message) {
|
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.
|
2021-07-30 19:58:32 +02:00
|
|
|
if (narrow_state.narrowed_to_topic()) {
|
2023-07-26 22:07:21 +02:00
|
|
|
const stream = narrow_state.stream_sub();
|
|
|
|
const stream_id = stream?.stream_id;
|
2021-07-30 19:58:32 +02:00
|
|
|
message = {
|
2023-07-26 22:07:21 +02:00
|
|
|
stream_id,
|
2021-07-30 19:58:32 +02:00
|
|
|
topic: narrow_state.topic(),
|
|
|
|
};
|
2022-05-26 04:20:07 +02:00
|
|
|
} else if (narrow_state.pm_ids_string()) {
|
2021-07-30 19:58:32 +02:00
|
|
|
// TODO: This is a total hack. Ideally, we'd rework
|
|
|
|
// this to not duplicate the actual compose_actions.js
|
|
|
|
// logic for what happens when you click the button,
|
|
|
|
// and not call into random modules with hacky fake
|
|
|
|
// "message" objects.
|
2022-05-26 04:20:07 +02:00
|
|
|
const user_ids = people.user_ids_string_to_ids_array(narrow_state.pm_ids_string());
|
2021-07-30 19:58:32 +02:00
|
|
|
const user_ids_dicts = user_ids.map((user_id) => ({id: user_id}));
|
|
|
|
message = {
|
|
|
|
display_reply_to: message_store.get_pm_full_names({
|
|
|
|
type: "private",
|
|
|
|
display_recipient: user_ids_dicts,
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
message = message_lists.current.selected_message();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (message) {
|
2023-07-26 22:07:21 +02:00
|
|
|
if (message.stream_id && message.topic) {
|
|
|
|
const stream = stream_data.get_sub_by_id(message.stream_id);
|
|
|
|
if (stream) {
|
|
|
|
return "#" + stream.name + " > " + message.topic;
|
|
|
|
}
|
2021-07-30 19:58:32 +02:00
|
|
|
} else if (message.display_reply_to) {
|
|
|
|
return message.display_reply_to;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
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
|
|
|
function update_reply_button_state(disable = false) {
|
2023-01-03 08:29:15 +01:00
|
|
|
$(".compose_reply_button").attr("disabled", disable);
|
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(
|
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
|
|
|
"data-tooltip-template-id",
|
|
|
|
"compose_reply_button_disabled_tooltip_template",
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (narrow_state.is_message_feed_visible()) {
|
2023-12-20 04:08:58 +01:00
|
|
|
$("#compose_buttons .compose-reply-button-wrapper").attr(
|
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
|
|
|
"data-tooltip-template-id",
|
|
|
|
"compose_reply_message_button_tooltip_template",
|
|
|
|
);
|
|
|
|
} else {
|
2023-12-20 04:08:58 +01:00
|
|
|
$("#compose_buttons .compose-reply-button-wrapper").attr(
|
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
|
|
|
"data-tooltip-template-id",
|
|
|
|
"compose_reply_selected_topic_button_tooltip_template",
|
|
|
|
);
|
2023-01-03 08:29:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-04 21:39:33 +02:00
|
|
|
function update_new_conversation_button(btn_text, is_direct_message_narrow) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-10-04 21:06:27 +02:00
|
|
|
function update_new_direct_message_button(btn_text) {
|
|
|
|
$("#new_direct_message_button").text(btn_text);
|
2021-05-11 22:04:35 +02:00
|
|
|
}
|
|
|
|
|
2023-10-04 21:44:46 +02:00
|
|
|
function toggle_direct_message_button_visibility(is_direct_message_narrow) {
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-04 21:39:33 +02:00
|
|
|
function update_buttons(text_stream, is_direct_message_narrow, disable_reply) {
|
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
|
|
|
}
|
|
|
|
|
|
|
|
export function update_buttons_for_private() {
|
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;
|
2023-01-03 08:29:15 +01:00
|
|
|
if (
|
|
|
|
!narrow_state.pm_ids_string() ||
|
|
|
|
people.user_can_direct_message(narrow_state.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
|
|
|
}
|
|
|
|
|
2023-10-04 18:36:15 +02:00
|
|
|
export function update_buttons_for_stream_views() {
|
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-02-25 21:54:42 +01:00
|
|
|
export function update_buttons_for_non_specific_views() {
|
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);
|
|
|
|
}
|
|
|
|
|
2021-05-10 14:01:27 +02:00
|
|
|
function set_reply_button_label(label) {
|
2023-06-20 15:08:26 +02:00
|
|
|
$("#left_bar_compose_reply_button_big").text(label);
|
2021-05-10 14:01:27 +02:00
|
|
|
}
|
|
|
|
|
2021-05-10 14:05:30 +02:00
|
|
|
export function set_standard_text_for_reply_button() {
|
|
|
|
set_reply_button_label($t({defaultMessage: "Compose message"}));
|
2021-05-07 18:38:01 +02:00
|
|
|
}
|
|
|
|
|
2021-03-18 13:57:28 +01:00
|
|
|
export function update_reply_recipient_label(message) {
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function initialize() {
|
|
|
|
// 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
|
2021-05-10 17:21:20 +02:00
|
|
|
// open due to "All messages" 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", () => {
|
2023-10-03 21:43:55 +02:00
|
|
|
compose_actions.start("stream", {trigger: "clear topic button"});
|
2021-05-05 05:51:55 +02:00
|
|
|
});
|
|
|
|
|
2023-10-04 21:06:27 +02:00
|
|
|
$("body").on("click", ".compose_new_direct_message_button", () => {
|
2023-06-16 11:56:47 +02:00
|
|
|
compose_actions.start("private", {trigger: "new direct message"});
|
2021-05-05 05:51:55 +02:00
|
|
|
});
|
2021-04-15 02:59:34 +02:00
|
|
|
}
|