2023-10-03 19:21:19 +02:00
|
|
|
import ClipboardJS from "clipboard";
|
|
|
|
import $ from "jquery";
|
|
|
|
|
|
|
|
import render_delete_topic_modal from "../templates/confirm_dialog/confirm_delete_topic.hbs";
|
2024-05-18 23:19:32 +02:00
|
|
|
import render_left_sidebar_topic_actions_popover from "../templates/popovers/left_sidebar/left_sidebar_topic_actions_popover.hbs";
|
2023-10-03 19:21:19 +02:00
|
|
|
|
|
|
|
import * as confirm_dialog from "./confirm_dialog";
|
|
|
|
import {$t_html} from "./i18n";
|
|
|
|
import * as message_edit from "./message_edit";
|
|
|
|
import * as popover_menus from "./popover_menus";
|
|
|
|
import * as popover_menus_data from "./popover_menus_data";
|
|
|
|
import * as starred_messages_ui from "./starred_messages_ui";
|
2024-02-13 02:08:24 +01:00
|
|
|
import {realm} from "./state_data";
|
2023-10-03 19:21:19 +02:00
|
|
|
import * as stream_popover from "./stream_popover";
|
2023-11-06 14:08:46 +01:00
|
|
|
import * as ui_util from "./ui_util";
|
2023-10-03 19:21:19 +02:00
|
|
|
import * as unread_ops from "./unread_ops";
|
|
|
|
import * as user_topics from "./user_topics";
|
2024-05-02 22:58:14 +02:00
|
|
|
import * as util from "./util";
|
2023-10-03 19:21:19 +02:00
|
|
|
|
|
|
|
export function initialize() {
|
|
|
|
popover_menus.register_popover_menu(
|
|
|
|
"#stream_filters .topic-sidebar-menu-icon, .inbox-row .inbox-topic-menu",
|
|
|
|
{
|
|
|
|
...popover_menus.left_sidebar_tippy_options,
|
|
|
|
onShow(instance) {
|
|
|
|
popover_menus.popover_instances.topics_menu = instance;
|
2023-11-06 14:57:46 +01:00
|
|
|
ui_util.show_left_sidebar_menu_icon(instance.reference);
|
2023-10-03 19:21:19 +02:00
|
|
|
popover_menus.on_show_prep(instance);
|
|
|
|
let stream_id;
|
|
|
|
let topic_name;
|
|
|
|
let url;
|
|
|
|
|
|
|
|
if (instance.reference.classList.contains("inbox-topic-menu")) {
|
|
|
|
const $elt = $(instance.reference);
|
|
|
|
stream_id = Number.parseInt($elt.attr("data-stream-id"), 10);
|
|
|
|
topic_name = $elt.attr("data-topic-name");
|
2024-06-03 10:49:57 +02:00
|
|
|
url = new URL($elt.attr("data-topic-url"), realm.realm_url);
|
2023-10-03 19:21:19 +02:00
|
|
|
} else {
|
|
|
|
const $elt = $(instance.reference)
|
|
|
|
.closest(".topic-sidebar-menu-icon")
|
|
|
|
.expectOne();
|
|
|
|
const $stream_li = $elt.closest(".narrow-filter").expectOne();
|
|
|
|
topic_name = $elt.closest("li").expectOne().attr("data-topic-name");
|
2024-05-17 22:06:52 +02:00
|
|
|
url = $elt.closest("li").find(".sidebar-topic-name").expectOne().prop("href");
|
2023-10-03 19:21:19 +02:00
|
|
|
stream_id = stream_popover.elem_to_stream_id($stream_li);
|
|
|
|
}
|
|
|
|
|
|
|
|
instance.context = popover_menus_data.get_topic_popover_content_context({
|
|
|
|
stream_id,
|
|
|
|
topic_name,
|
|
|
|
url,
|
|
|
|
});
|
2023-11-06 14:08:46 +01:00
|
|
|
instance.setContent(
|
2024-05-18 23:04:21 +02:00
|
|
|
ui_util.parse_html(render_left_sidebar_topic_actions_popover(instance.context)),
|
2023-11-06 14:08:46 +01:00
|
|
|
);
|
2023-10-03 19:21:19 +02:00
|
|
|
},
|
|
|
|
onMount(instance) {
|
|
|
|
const $popper = $(instance.popper);
|
|
|
|
const {stream_id, topic_name} = instance.context;
|
|
|
|
|
|
|
|
if (!stream_id) {
|
2024-04-02 09:29:56 +02:00
|
|
|
popover_menus.hide_current_popover_if_visible(instance);
|
2023-10-03 19:21:19 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-05-02 22:58:14 +02:00
|
|
|
$popper.on("change", "input[name='sidebar-topic-visibility-select']", (e) => {
|
|
|
|
const start_time = Date.now();
|
|
|
|
const visibility_policy = Number.parseInt(
|
|
|
|
$(e.currentTarget).attr("data-visibility-policy"),
|
|
|
|
10,
|
|
|
|
);
|
|
|
|
|
|
|
|
const success_cb = () => {
|
|
|
|
setTimeout(
|
|
|
|
() => {
|
|
|
|
popover_menus.hide_current_popover_if_visible(instance);
|
|
|
|
},
|
|
|
|
util.get_remaining_time(start_time, 500),
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const error_cb = () => {
|
|
|
|
const prev_visibility_policy = user_topics.get_topic_visibility_policy(
|
|
|
|
stream_id,
|
|
|
|
topic_name,
|
|
|
|
);
|
|
|
|
const $prev_visibility_policy_input = $(e.currentTarget)
|
|
|
|
.parent()
|
|
|
|
.find(`input[data-visibility-policy="${prev_visibility_policy}"]`);
|
|
|
|
setTimeout(
|
|
|
|
() => {
|
|
|
|
$prev_visibility_policy_input.prop("checked", true);
|
|
|
|
},
|
|
|
|
util.get_remaining_time(start_time, 500),
|
|
|
|
);
|
|
|
|
};
|
2023-10-03 19:21:19 +02:00
|
|
|
|
|
|
|
user_topics.set_user_topic_visibility_policy(
|
|
|
|
stream_id,
|
|
|
|
topic_name,
|
|
|
|
visibility_policy,
|
2024-05-02 22:58:14 +02:00
|
|
|
false,
|
|
|
|
false,
|
|
|
|
undefined,
|
|
|
|
success_cb,
|
|
|
|
error_cb,
|
2023-10-03 19:21:19 +02:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
$popper.one("click", ".sidebar-popover-unstar-all-in-topic", () => {
|
|
|
|
starred_messages_ui.confirm_unstar_all_messages_in_topic(
|
|
|
|
Number.parseInt(stream_id, 10),
|
|
|
|
topic_name,
|
|
|
|
);
|
2024-04-02 09:29:56 +02:00
|
|
|
popover_menus.hide_current_popover_if_visible(instance);
|
2023-10-03 19:21:19 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
$popper.one("click", ".sidebar-popover-mark-topic-read", () => {
|
|
|
|
unread_ops.mark_topic_as_read(stream_id, topic_name);
|
2024-04-02 09:29:56 +02:00
|
|
|
popover_menus.hide_current_popover_if_visible(instance);
|
2023-10-03 19:21:19 +02:00
|
|
|
});
|
|
|
|
|
2024-01-24 19:03:43 +01:00
|
|
|
$popper.one("click", ".sidebar-popover-mark-topic-unread", () => {
|
|
|
|
unread_ops.mark_topic_as_unread(stream_id, topic_name);
|
2024-04-02 09:29:56 +02:00
|
|
|
popover_menus.hide_current_popover_if_visible(instance);
|
2024-01-24 19:03:43 +01:00
|
|
|
});
|
|
|
|
|
2023-10-03 19:21:19 +02:00
|
|
|
$popper.one("click", ".sidebar-popover-delete-topic-messages", () => {
|
|
|
|
const html_body = render_delete_topic_modal({topic_name});
|
|
|
|
|
|
|
|
confirm_dialog.launch({
|
|
|
|
html_heading: $t_html({defaultMessage: "Delete topic"}),
|
|
|
|
help_link: "/help/delete-a-topic",
|
|
|
|
html_body,
|
|
|
|
on_click() {
|
|
|
|
message_edit.delete_topic(stream_id, topic_name);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2024-04-02 09:29:56 +02:00
|
|
|
popover_menus.hide_current_popover_if_visible(instance);
|
2023-10-03 19:21:19 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
$popper.one("click", ".sidebar-popover-toggle-resolved", () => {
|
|
|
|
message_edit.with_first_message_id(stream_id, topic_name, (message_id) => {
|
|
|
|
message_edit.toggle_resolve_topic(message_id, topic_name, true);
|
|
|
|
});
|
|
|
|
|
2024-04-02 09:29:56 +02:00
|
|
|
popover_menus.hide_current_popover_if_visible(instance);
|
2023-10-03 19:21:19 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
$popper.one("click", ".sidebar-popover-move-topic-messages", () => {
|
|
|
|
stream_popover.build_move_topic_to_stream_popover(stream_id, topic_name, false);
|
2024-04-02 09:29:56 +02:00
|
|
|
popover_menus.hide_current_popover_if_visible(instance);
|
2023-10-03 19:21:19 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
$popper.one("click", ".sidebar-popover-rename-topic-messages", () => {
|
|
|
|
stream_popover.build_move_topic_to_stream_popover(stream_id, topic_name, true);
|
2024-04-02 09:29:56 +02:00
|
|
|
popover_menus.hide_current_popover_if_visible(instance);
|
2023-10-03 19:21:19 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
new ClipboardJS($popper.find(".sidebar-popover-copy-link-to-topic")[0]).on(
|
|
|
|
"success",
|
|
|
|
() => {
|
2024-04-02 09:29:56 +02:00
|
|
|
popover_menus.hide_current_popover_if_visible(instance);
|
2023-10-03 19:21:19 +02:00
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
onHidden(instance) {
|
|
|
|
instance.destroy();
|
|
|
|
popover_menus.popover_instances.topics_menu = undefined;
|
2023-11-06 14:57:46 +01:00
|
|
|
ui_util.hide_left_sidebar_menu_icon();
|
2023-10-03 19:21:19 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|