2021-06-24 09:26:39 +02:00
|
|
|
import ClipboardJS from "clipboard";
|
2021-03-11 05:43:45 +01:00
|
|
|
import $ from "jquery";
|
|
|
|
|
2022-03-07 22:25:54 +01:00
|
|
|
import * as resolved_topic from "../shared/js/resolved_topic";
|
2021-02-28 01:02:37 +01:00
|
|
|
import render_all_messages_sidebar_actions from "../templates/all_messages_sidebar_actions.hbs";
|
2021-06-21 09:53:50 +02:00
|
|
|
import render_delete_topic_modal from "../templates/confirm_dialog/confirm_delete_topic.hbs";
|
2021-11-12 11:09:12 +01:00
|
|
|
import render_drafts_sidebar_actions from "../templates/drafts_sidebar_action.hbs";
|
2021-02-28 01:02:37 +01:00
|
|
|
import render_move_topic_to_stream from "../templates/move_topic_to_stream.hbs";
|
|
|
|
import render_starred_messages_sidebar_actions from "../templates/starred_messages_sidebar_actions.hbs";
|
|
|
|
import render_stream_sidebar_actions from "../templates/stream_sidebar_actions.hbs";
|
|
|
|
import render_topic_sidebar_actions from "../templates/topic_sidebar_actions.hbs";
|
|
|
|
|
2021-03-16 23:38:59 +01:00
|
|
|
import * as blueslip from "./blueslip";
|
2021-03-22 16:09:12 +01:00
|
|
|
import * as browser_history from "./browser_history";
|
2021-02-28 01:02:37 +01:00
|
|
|
import * as channel from "./channel";
|
2021-01-19 15:27:49 +01:00
|
|
|
import * as compose_actions from "./compose_actions";
|
2022-02-26 12:28:09 +01:00
|
|
|
import * as composebox_typeahead from "./composebox_typeahead";
|
2021-05-07 18:41:12 +02:00
|
|
|
import * as confirm_dialog from "./confirm_dialog";
|
2021-07-18 11:18:03 +02:00
|
|
|
import * as dialog_widget from "./dialog_widget";
|
2021-11-12 11:09:12 +01:00
|
|
|
import * as drafts from "./drafts";
|
2021-07-27 14:05:22 +02:00
|
|
|
import {DropdownListWidget} from "./dropdown_list_widget";
|
2021-02-28 01:07:13 +01:00
|
|
|
import * as hash_util from "./hash_util";
|
2021-05-07 18:41:12 +02:00
|
|
|
import {$t, $t_html} from "./i18n";
|
2022-09-28 08:27:24 +02:00
|
|
|
import * as keydown_util from "./keydown_util";
|
2021-02-28 01:02:37 +01:00
|
|
|
import * as message_edit from "./message_edit";
|
2021-07-08 20:36:52 +02:00
|
|
|
import * as muted_topics_ui from "./muted_topics_ui";
|
2021-03-25 22:35:45 +01:00
|
|
|
import {page_params} from "./page_params";
|
2021-02-28 01:03:09 +01:00
|
|
|
import * as popovers from "./popovers";
|
2021-05-13 18:17:57 +02:00
|
|
|
import * as settings_data from "./settings_data";
|
2021-03-05 09:48:15 +01:00
|
|
|
import * as starred_messages from "./starred_messages";
|
2021-03-25 09:45:39 +01:00
|
|
|
import * as starred_messages_ui from "./starred_messages_ui";
|
2021-03-22 18:29:15 +01:00
|
|
|
import * as stream_bar from "./stream_bar";
|
2021-02-28 01:02:37 +01:00
|
|
|
import * as stream_color from "./stream_color";
|
|
|
|
import * as stream_data from "./stream_data";
|
2021-07-09 15:51:31 +02:00
|
|
|
import * as stream_settings_ui from "./stream_settings_ui";
|
2021-04-15 17:02:54 +02:00
|
|
|
import * as sub_store from "./sub_store";
|
2021-11-24 16:03:21 +01:00
|
|
|
import * as ui_report from "./ui_report";
|
2021-02-28 21:30:08 +01:00
|
|
|
import * as unread_ops from "./unread_ops";
|
2021-07-28 16:00:58 +02:00
|
|
|
import {user_settings} from "./user_settings";
|
2022-08-14 15:33:13 +02:00
|
|
|
import * as user_topics from "./user_topics";
|
2021-02-28 00:39:51 +01:00
|
|
|
|
2017-03-05 17:28:40 +01:00
|
|
|
// We handle stream popovers and topic popovers in this
|
|
|
|
// module. Both are popped up from the left sidebar.
|
2019-11-02 00:06:25 +01:00
|
|
|
let current_stream_sidebar_elem;
|
|
|
|
let current_topic_sidebar_elem;
|
|
|
|
let all_messages_sidebar_elem;
|
|
|
|
let starred_messages_sidebar_elem;
|
2021-11-12 11:09:12 +01:00
|
|
|
let drafts_sidebar_elem;
|
2021-03-28 19:28:30 +02:00
|
|
|
let stream_widget;
|
2022-01-25 11:36:19 +01:00
|
|
|
let $stream_header_colorblock;
|
2017-03-05 17:28:40 +01:00
|
|
|
|
2022-10-21 14:23:22 +02:00
|
|
|
// Keep the menu icon over which the popover is based off visible.
|
|
|
|
function show_left_sidebar_menu_icon(element) {
|
|
|
|
$(element).closest("[class*='-sidebar-menu-icon']").addClass("left_sidebar_menu_icon_visible");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove the class from element when popover is closed
|
|
|
|
function hide_left_sidebar_menu_icon() {
|
|
|
|
$(".left_sidebar_menu_icon_visible").removeClass("left_sidebar_menu_icon_visible");
|
|
|
|
}
|
|
|
|
|
2020-07-08 22:17:16 +02:00
|
|
|
function get_popover_menu_items(sidebar_elem) {
|
|
|
|
if (!sidebar_elem) {
|
|
|
|
blueslip.error("Trying to get menu items when action popover is closed.");
|
2020-09-24 07:50:36 +02:00
|
|
|
return undefined;
|
2020-07-08 22:17:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const popover_data = $(sidebar_elem).data("popover");
|
|
|
|
if (!popover_data) {
|
|
|
|
blueslip.error("Cannot find popover data for stream sidebar menu.");
|
2020-09-24 07:50:36 +02:00
|
|
|
return undefined;
|
2020-07-08 22:17:16 +02:00
|
|
|
}
|
|
|
|
return $("li:not(.divider):visible > a", popover_data.$tip);
|
|
|
|
}
|
|
|
|
|
2021-02-28 01:02:37 +01:00
|
|
|
export function stream_sidebar_menu_handle_keyboard(key) {
|
2020-07-08 22:17:16 +02:00
|
|
|
const items = get_popover_menu_items(current_stream_sidebar_elem);
|
|
|
|
popovers.popover_items_handle_keyboard(key, items);
|
2021-02-28 01:02:37 +01:00
|
|
|
}
|
2020-07-08 22:17:16 +02:00
|
|
|
|
2021-02-28 01:02:37 +01:00
|
|
|
export function topic_sidebar_menu_handle_keyboard(key) {
|
2020-07-09 03:18:27 +02:00
|
|
|
const items = get_popover_menu_items(current_topic_sidebar_elem);
|
|
|
|
popovers.popover_items_handle_keyboard(key, items);
|
2021-02-28 01:02:37 +01:00
|
|
|
}
|
2020-07-09 03:18:27 +02:00
|
|
|
|
2021-02-28 01:02:37 +01:00
|
|
|
export function all_messages_sidebar_menu_handle_keyboard(key) {
|
2020-07-10 19:39:26 +02:00
|
|
|
const items = get_popover_menu_items(all_messages_sidebar_elem);
|
|
|
|
popovers.popover_items_handle_keyboard(key, items);
|
2021-02-28 01:02:37 +01:00
|
|
|
}
|
2020-07-10 19:39:26 +02:00
|
|
|
|
2021-02-28 01:02:37 +01:00
|
|
|
export function starred_messages_sidebar_menu_handle_keyboard(key) {
|
2020-07-10 20:25:24 +02:00
|
|
|
const items = get_popover_menu_items(starred_messages_sidebar_elem);
|
|
|
|
popovers.popover_items_handle_keyboard(key, items);
|
2021-02-28 01:02:37 +01:00
|
|
|
}
|
2020-07-10 20:25:24 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
function elem_to_stream_id($elem) {
|
|
|
|
const stream_id = Number.parseInt($elem.attr("data-stream-id"), 10);
|
2020-01-12 13:39:37 +01:00
|
|
|
|
|
|
|
if (stream_id === undefined) {
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.error("could not find stream id");
|
2020-01-12 13:39:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return stream_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
function topic_popover_stream_id(e) {
|
|
|
|
return elem_to_stream_id($(e.currentTarget));
|
|
|
|
}
|
|
|
|
|
2021-02-28 01:02:37 +01:00
|
|
|
export function stream_popped() {
|
2017-03-05 17:28:40 +01:00
|
|
|
return current_stream_sidebar_elem !== undefined;
|
2021-02-28 01:02:37 +01:00
|
|
|
}
|
2017-03-05 17:28:40 +01:00
|
|
|
|
2021-02-28 01:02:37 +01:00
|
|
|
export function topic_popped() {
|
2017-03-05 17:28:40 +01:00
|
|
|
return current_topic_sidebar_elem !== undefined;
|
2021-02-28 01:02:37 +01:00
|
|
|
}
|
2017-03-05 17:28:40 +01:00
|
|
|
|
2021-02-28 01:02:37 +01:00
|
|
|
export function all_messages_popped() {
|
2018-02-15 20:38:06 +01:00
|
|
|
return all_messages_sidebar_elem !== undefined;
|
2021-02-28 01:02:37 +01:00
|
|
|
}
|
2018-02-15 20:38:06 +01:00
|
|
|
|
2021-02-28 01:02:37 +01:00
|
|
|
export function starred_messages_popped() {
|
2019-02-22 12:28:29 +01:00
|
|
|
return starred_messages_sidebar_elem !== undefined;
|
2021-02-28 01:02:37 +01:00
|
|
|
}
|
2019-02-22 12:28:29 +01:00
|
|
|
|
2021-11-12 11:09:12 +01:00
|
|
|
export function drafts_popped() {
|
|
|
|
return drafts_sidebar_elem !== undefined;
|
|
|
|
}
|
|
|
|
|
2021-02-28 01:02:37 +01:00
|
|
|
export function hide_stream_popover() {
|
|
|
|
if (stream_popped()) {
|
2017-03-05 17:28:40 +01:00
|
|
|
$(current_stream_sidebar_elem).popover("destroy");
|
2022-10-21 14:23:22 +02:00
|
|
|
hide_left_sidebar_menu_icon();
|
2017-03-05 17:28:40 +01:00
|
|
|
current_stream_sidebar_elem = undefined;
|
|
|
|
}
|
2021-02-28 01:02:37 +01:00
|
|
|
}
|
2017-03-05 17:28:40 +01:00
|
|
|
|
2021-02-28 01:02:37 +01:00
|
|
|
export function hide_topic_popover() {
|
|
|
|
if (topic_popped()) {
|
2017-03-05 17:28:40 +01:00
|
|
|
$(current_topic_sidebar_elem).popover("destroy");
|
2022-10-21 14:23:22 +02:00
|
|
|
hide_left_sidebar_menu_icon();
|
2017-03-05 17:28:40 +01:00
|
|
|
current_topic_sidebar_elem = undefined;
|
|
|
|
}
|
2021-02-28 01:02:37 +01:00
|
|
|
}
|
2017-03-05 17:28:40 +01:00
|
|
|
|
2021-02-28 01:02:37 +01:00
|
|
|
export function hide_all_messages_popover() {
|
|
|
|
if (all_messages_popped()) {
|
2018-02-15 20:38:06 +01:00
|
|
|
$(all_messages_sidebar_elem).popover("destroy");
|
2022-10-21 14:23:22 +02:00
|
|
|
hide_left_sidebar_menu_icon();
|
2018-02-15 20:38:06 +01:00
|
|
|
all_messages_sidebar_elem = undefined;
|
|
|
|
}
|
2021-02-28 01:02:37 +01:00
|
|
|
}
|
2018-02-15 20:38:06 +01:00
|
|
|
|
2021-02-28 01:02:37 +01:00
|
|
|
export function hide_starred_messages_popover() {
|
|
|
|
if (starred_messages_popped()) {
|
2019-02-22 12:28:29 +01:00
|
|
|
$(starred_messages_sidebar_elem).popover("destroy");
|
2022-10-21 14:23:22 +02:00
|
|
|
hide_left_sidebar_menu_icon();
|
2019-02-22 12:28:29 +01:00
|
|
|
starred_messages_sidebar_elem = undefined;
|
|
|
|
}
|
2021-02-28 01:02:37 +01:00
|
|
|
}
|
2019-02-22 12:28:29 +01:00
|
|
|
|
2021-11-12 11:09:12 +01:00
|
|
|
export function hide_drafts_popover() {
|
|
|
|
if (drafts_popped()) {
|
|
|
|
$(drafts_sidebar_elem).popover("destroy");
|
2022-10-21 14:23:22 +02:00
|
|
|
hide_left_sidebar_menu_icon();
|
2021-11-12 11:09:12 +01:00
|
|
|
drafts_sidebar_elem = undefined;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-28 01:02:37 +01:00
|
|
|
export function show_streamlist_sidebar() {
|
2017-03-05 17:28:40 +01:00
|
|
|
$(".app-main .column-left").addClass("expanded");
|
2021-02-28 01:02:37 +01:00
|
|
|
}
|
2017-03-05 17:28:40 +01:00
|
|
|
|
2021-02-28 01:02:37 +01:00
|
|
|
export function hide_streamlist_sidebar() {
|
2017-03-05 17:28:40 +01:00
|
|
|
$(".app-main .column-left").removeClass("expanded");
|
2021-02-28 01:02:37 +01:00
|
|
|
}
|
2017-03-05 17:28:40 +01:00
|
|
|
|
|
|
|
function stream_popover_sub(e) {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $elem = $(e.currentTarget).parents("ul");
|
|
|
|
const stream_id = elem_to_stream_id($elem);
|
2021-04-15 17:02:54 +02:00
|
|
|
const sub = sub_store.get(stream_id);
|
2017-03-05 17:28:40 +01:00
|
|
|
if (!sub) {
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.error("Unknown stream: " + stream_id);
|
2020-09-24 07:50:36 +02:00
|
|
|
return undefined;
|
2017-03-05 17:28:40 +01:00
|
|
|
}
|
|
|
|
return sub;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This little function is a workaround for the fact that
|
|
|
|
// Bootstrap popovers don't properly handle being resized --
|
|
|
|
// so after resizing our popover to add in the spectrum color
|
|
|
|
// picker, we need to adjust its height accordingly.
|
2022-01-25 11:36:19 +01:00
|
|
|
function update_spectrum($popover, update_func) {
|
|
|
|
const initial_height = $popover[0].offsetHeight;
|
2017-03-05 17:28:40 +01:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
const $colorpicker = $popover.find(".colorpicker-container").find(".colorpicker");
|
|
|
|
update_func($colorpicker);
|
|
|
|
const after_height = $popover[0].offsetHeight;
|
2017-03-05 17:28:40 +01:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
const $popover_root = $popover.closest(".popover");
|
|
|
|
const current_top_px = Number.parseFloat($popover_root.css("top").replace("px", ""));
|
2019-11-02 00:06:25 +01:00
|
|
|
const height_delta = after_height - initial_height;
|
|
|
|
let top = current_top_px - height_delta / 2;
|
2019-02-15 01:43:17 +01:00
|
|
|
|
|
|
|
if (top < 0) {
|
|
|
|
top = 0;
|
2022-01-25 11:36:19 +01:00
|
|
|
$popover_root.find("div.arrow").hide();
|
2019-02-15 01:43:17 +01:00
|
|
|
} else if (top + after_height > $(window).height() - 20) {
|
|
|
|
top = $(window).height() - after_height - 20;
|
|
|
|
if (top < 0) {
|
|
|
|
top = 0;
|
|
|
|
}
|
2022-01-25 11:36:19 +01:00
|
|
|
$popover_root.find("div.arrow").hide();
|
2019-02-15 01:43:17 +01:00
|
|
|
}
|
2017-03-05 17:28:40 +01:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
$popover_root.css("top", top + "px");
|
2017-03-05 17:28:40 +01:00
|
|
|
}
|
|
|
|
|
2021-06-24 09:26:39 +02:00
|
|
|
// Builds the `Copy link to topic` topic action.
|
|
|
|
function build_topic_link_clipboard(url) {
|
|
|
|
if (!url) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const copy_event = new ClipboardJS(".sidebar-popover-copy-link-to-topic", {
|
|
|
|
text() {
|
|
|
|
return url;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
// Hide the topic popover once the url is successfully
|
|
|
|
// copied to clipboard.
|
|
|
|
copy_event.on("success", () => {
|
|
|
|
hide_topic_popover();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-02-22 17:07:49 +01:00
|
|
|
function build_stream_popover(opts) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const elt = opts.elt;
|
|
|
|
const stream_id = opts.stream_id;
|
2019-02-22 17:07:49 +01:00
|
|
|
|
2021-02-28 01:02:37 +01:00
|
|
|
if (stream_popped() && current_stream_sidebar_elem === elt) {
|
2017-03-05 17:28:40 +01:00
|
|
|
// If the popover is already shown, clicking again should toggle it.
|
2021-02-28 01:02:37 +01:00
|
|
|
hide_stream_popover();
|
2017-03-05 17:28:40 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
popovers.hide_all();
|
2021-02-28 01:02:37 +01:00
|
|
|
show_streamlist_sidebar();
|
2017-03-05 17:28:40 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const content = render_stream_sidebar_actions({
|
2021-04-15 17:02:54 +02:00
|
|
|
stream: sub_store.get(stream_id),
|
2019-07-09 21:24:00 +02:00
|
|
|
});
|
2017-03-05 17:28:40 +01:00
|
|
|
|
|
|
|
$(elt).popover({
|
2020-07-20 22:18:43 +02:00
|
|
|
content,
|
2019-09-17 23:54:52 +02:00
|
|
|
html: true,
|
2017-03-05 17:28:40 +01:00
|
|
|
trigger: "manual",
|
|
|
|
fixed: true,
|
2019-02-15 01:43:17 +01:00
|
|
|
fix_positions: true,
|
2017-03-05 17:28:40 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
$(elt).popover("show");
|
2022-01-25 11:36:19 +01:00
|
|
|
const $popover = $(`.streams_popover[data-stream-id="${CSS.escape(stream_id)}"]`);
|
2017-03-05 17:28:40 +01:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
update_spectrum($popover, ($colorpicker) => {
|
|
|
|
$colorpicker.spectrum(stream_color.sidebar_popover_colorpicker_options);
|
2017-03-05 17:28:40 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
current_stream_sidebar_elem = elt;
|
2022-10-21 14:23:22 +02:00
|
|
|
show_left_sidebar_menu_icon(elt);
|
2017-03-05 17:28:40 +01:00
|
|
|
}
|
|
|
|
|
2019-02-05 14:48:39 +01:00
|
|
|
function build_topic_popover(opts) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const elt = opts.elt;
|
|
|
|
const stream_id = opts.stream_id;
|
|
|
|
const topic_name = opts.topic_name;
|
2017-03-05 17:28:40 +01:00
|
|
|
|
2021-02-28 01:02:37 +01:00
|
|
|
if (topic_popped() && current_topic_sidebar_elem === elt) {
|
2017-03-05 17:28:40 +01:00
|
|
|
// If the popover is already shown, clicking again should toggle it.
|
2021-02-28 01:02:37 +01:00
|
|
|
hide_topic_popover();
|
2017-03-05 17:28:40 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-04-15 17:02:54 +02:00
|
|
|
const sub = sub_store.get(stream_id);
|
2017-03-05 19:36:36 +01:00
|
|
|
if (!sub) {
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.error("cannot build topic popover for stream: " + stream_id);
|
2017-03-05 19:36:36 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
popovers.hide_all();
|
2021-02-28 01:02:37 +01:00
|
|
|
show_streamlist_sidebar();
|
2017-03-05 19:36:36 +01:00
|
|
|
|
2022-08-14 15:33:13 +02:00
|
|
|
const topic_muted = user_topics.is_topic_muted(sub.stream_id, topic_name);
|
starred messages: Fix "unstar all in topic" is incomplete.
Currently, when there are some old starred messages
in a topic, it is possible that some of them won't be
unstarred on doing "Unstar all messages in topic".
This happens when those messages haven't been fetched
yet from the server, and we have no way to verify if
they actually belong to the topic.
This commit fixes that by changing this mechanism to
first fetch all starred messages in the topic from
the server, and then send their IDs back to the backend
to unstar them.
While doing this, we assume that the user does not
have more than 1000 starred messages in that topic.
Note that, we still depend on the local data to
decide whether or not the "Unstar all messages in
topic" option should be shown in the topic popover.
A method similar to the above cannot be used here, because
making server requests before opening the popover
could visually slow down the popover opening.
Using local data for the topic popover would probably
not be a big problem, because users would want to
unstar all messages in a topic probably after noticing
that there are a lot of them, meaning there was at least
one starred message from that topic which was already
fetched, which is sufficient for us to conclude that
we need to show the option in the topic popover.
Fixes #17790
2021-04-02 08:10:11 +02:00
|
|
|
const has_starred_messages = starred_messages.get_count_in_topic(sub.stream_id, topic_name) > 0;
|
2021-05-13 18:17:57 +02:00
|
|
|
// Arguably, we could offer the "Move topic" option even if users
|
|
|
|
// can only edit the name within a stream.
|
|
|
|
const can_move_topic = settings_data.user_can_move_messages_between_streams();
|
2017-03-05 17:28:40 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const content = render_topic_sidebar_actions({
|
2017-08-17 01:42:07 +02:00
|
|
|
stream_name: sub.name,
|
2017-03-05 19:36:36 +01:00
|
|
|
stream_id: sub.stream_id,
|
2020-07-20 22:18:43 +02:00
|
|
|
topic_name,
|
2021-04-30 08:30:50 +02:00
|
|
|
topic_muted,
|
2021-05-13 18:17:57 +02:00
|
|
|
can_move_topic,
|
2021-04-06 13:37:04 +02:00
|
|
|
is_realm_admin: page_params.is_admin,
|
2022-03-07 22:59:56 +01:00
|
|
|
topic_is_resolved: resolved_topic.is_resolved(topic_name),
|
2020-06-20 17:50:19 +02:00
|
|
|
color: sub.color,
|
2021-03-08 09:25:25 +01:00
|
|
|
has_starred_messages,
|
2017-03-05 17:28:40 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
$(elt).popover({
|
2020-07-20 22:18:43 +02:00
|
|
|
content,
|
2019-09-17 23:54:52 +02:00
|
|
|
html: true,
|
2017-03-05 17:28:40 +01:00
|
|
|
trigger: "manual",
|
|
|
|
fixed: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
$(elt).popover("show");
|
|
|
|
|
|
|
|
current_topic_sidebar_elem = elt;
|
2022-10-21 14:23:22 +02:00
|
|
|
show_left_sidebar_menu_icon(elt);
|
2017-03-05 17:28:40 +01:00
|
|
|
}
|
|
|
|
|
2018-02-15 20:38:06 +01:00
|
|
|
function build_all_messages_popover(e) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const elt = e.target;
|
2018-02-15 20:38:06 +01:00
|
|
|
|
2021-02-28 01:02:37 +01:00
|
|
|
if (all_messages_popped() && all_messages_sidebar_elem === elt) {
|
|
|
|
hide_all_messages_popover();
|
2018-02-15 20:38:06 +01:00
|
|
|
e.stopPropagation();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
popovers.hide_all();
|
2021-03-20 08:59:20 +01:00
|
|
|
show_streamlist_sidebar();
|
2018-02-15 20:38:06 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const content = render_all_messages_sidebar_actions();
|
2018-02-15 20:38:06 +01:00
|
|
|
|
|
|
|
$(elt).popover({
|
2020-07-20 22:18:43 +02:00
|
|
|
content,
|
2019-09-17 23:54:52 +02:00
|
|
|
html: true,
|
2018-02-15 20:38:06 +01:00
|
|
|
trigger: "manual",
|
|
|
|
fixed: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
$(elt).popover("show");
|
|
|
|
all_messages_sidebar_elem = elt;
|
2022-10-21 14:23:22 +02:00
|
|
|
show_left_sidebar_menu_icon(elt);
|
2018-02-15 20:38:06 +01:00
|
|
|
e.stopPropagation();
|
|
|
|
}
|
|
|
|
|
2019-02-22 12:28:29 +01:00
|
|
|
function build_starred_messages_popover(e) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const elt = e.target;
|
2019-02-22 12:28:29 +01:00
|
|
|
|
2021-02-28 01:02:37 +01:00
|
|
|
if (starred_messages_popped() && starred_messages_sidebar_elem === elt) {
|
|
|
|
hide_starred_messages_popover();
|
2019-02-22 12:28:29 +01:00
|
|
|
e.stopPropagation();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
popovers.hide_all();
|
2021-03-20 08:59:20 +01:00
|
|
|
show_streamlist_sidebar();
|
2019-02-22 12:28:29 +01:00
|
|
|
|
2021-03-05 09:48:15 +01:00
|
|
|
const show_unstar_all_button = starred_messages.get_count() > 0;
|
2019-11-02 00:06:25 +01:00
|
|
|
const content = render_starred_messages_sidebar_actions({
|
2021-03-05 09:48:15 +01:00
|
|
|
show_unstar_all_button,
|
2021-07-28 16:00:58 +02:00
|
|
|
starred_message_counts: user_settings.starred_message_counts,
|
2019-07-09 21:24:00 +02:00
|
|
|
});
|
2019-02-22 12:28:29 +01:00
|
|
|
|
|
|
|
$(elt).popover({
|
2020-07-20 22:18:43 +02:00
|
|
|
content,
|
2019-09-17 23:54:52 +02:00
|
|
|
html: true,
|
2019-02-22 12:28:29 +01:00
|
|
|
trigger: "manual",
|
|
|
|
fixed: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
$(elt).popover("show");
|
|
|
|
starred_messages_sidebar_elem = elt;
|
2022-10-21 14:23:22 +02:00
|
|
|
show_left_sidebar_menu_icon(elt);
|
2019-02-22 12:28:29 +01:00
|
|
|
e.stopPropagation();
|
|
|
|
}
|
|
|
|
|
2021-11-12 11:09:12 +01:00
|
|
|
function build_drafts_popover(e) {
|
|
|
|
const elt = e.target;
|
|
|
|
|
|
|
|
if (drafts_popped() && drafts_sidebar_elem === elt) {
|
|
|
|
hide_drafts_popover();
|
|
|
|
e.stopPropagation();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
popovers.hide_all();
|
|
|
|
show_streamlist_sidebar();
|
|
|
|
const content = render_drafts_sidebar_actions({});
|
|
|
|
$(elt).popover({
|
|
|
|
content,
|
|
|
|
html: true,
|
|
|
|
trigger: "manual",
|
|
|
|
fixed: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
$(elt).popover("show");
|
|
|
|
drafts_sidebar_elem = elt;
|
2022-10-21 14:23:22 +02:00
|
|
|
show_left_sidebar_menu_icon(elt);
|
2021-11-12 11:09:12 +01:00
|
|
|
e.stopPropagation();
|
|
|
|
}
|
|
|
|
|
2022-10-03 09:41:13 +02:00
|
|
|
export function build_move_topic_to_stream_popover(current_stream_id, topic_name, message) {
|
2020-05-16 10:09:13 +02:00
|
|
|
const current_stream_name = stream_data.maybe_get_stream_name(current_stream_id);
|
2020-06-03 16:44:57 +02:00
|
|
|
const args = {
|
2020-07-15 00:34:28 +02:00
|
|
|
topic_name,
|
|
|
|
current_stream_id,
|
2020-06-03 16:44:57 +02:00
|
|
|
notify_new_thread: message_edit.notify_new_thread_default,
|
|
|
|
notify_old_thread: message_edit.notify_old_thread_default,
|
2022-10-03 09:41:13 +02:00
|
|
|
from_message_actions_popover: message !== undefined,
|
2020-06-03 16:44:57 +02:00
|
|
|
};
|
2020-02-19 01:38:34 +01:00
|
|
|
|
2022-10-03 09:41:13 +02:00
|
|
|
let modal_heading = $t_html({defaultMessage: "Move topic"});
|
|
|
|
if (message !== undefined) {
|
|
|
|
modal_heading = $t_html({defaultMessage: "Move messages"});
|
2022-10-05 20:03:20 +02:00
|
|
|
// We disable topic input only for modal is opened from the message actions
|
|
|
|
// popover and not when moving the whole topic from left sidebar. This is
|
|
|
|
// because topic editing permission depend on message and we do not have
|
|
|
|
// any message object when opening the modal and the first message of
|
|
|
|
// topic is fetched from the server after clicking submit.
|
|
|
|
// Though, this will be changed soon as we are going to make topic
|
|
|
|
// edit permission independent of message.
|
|
|
|
args.disable_topic_input = !message_edit.is_topic_editable(message);
|
2022-10-03 09:41:13 +02:00
|
|
|
}
|
2020-02-19 01:38:34 +01:00
|
|
|
|
2022-04-14 06:43:38 +02:00
|
|
|
function get_params_from_form() {
|
|
|
|
return Object.fromEntries(
|
2021-07-18 11:18:03 +02:00
|
|
|
$("#move_topic_form")
|
|
|
|
.serializeArray()
|
|
|
|
.map(({name, value}) => [name, value]),
|
|
|
|
);
|
2022-04-14 06:43:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function update_submit_button_disabled_state(select_stream_id) {
|
|
|
|
const {current_stream_id, new_topic_name, old_topic_name} = get_params_from_form();
|
|
|
|
|
2022-04-19 01:21:56 +02:00
|
|
|
// Unlike most topic comparisons in Zulip, we intentionally do
|
|
|
|
// a case-sensitive comparison, since adjusting the
|
|
|
|
// capitalization of a topic is a valid operation.
|
2022-10-05 20:03:20 +02:00
|
|
|
// new_topic_name can be undefined when the new topic input is
|
|
|
|
// disabled in case when user does not have permission to edit
|
|
|
|
// topic and thus submit button is disabled if stream is also
|
|
|
|
// not changed.
|
2022-04-14 06:43:38 +02:00
|
|
|
$("#move_topic_modal .dialog_submit_button")[0].disabled =
|
|
|
|
Number.parseInt(current_stream_id, 10) === Number.parseInt(select_stream_id, 10) &&
|
2022-10-05 20:03:20 +02:00
|
|
|
(new_topic_name === undefined || new_topic_name.trim() === old_topic_name.trim());
|
2022-04-14 06:43:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function move_topic() {
|
|
|
|
const params = get_params_from_form();
|
2021-07-18 11:18:03 +02:00
|
|
|
|
|
|
|
const {old_topic_name} = params;
|
2022-10-03 09:41:13 +02:00
|
|
|
let select_stream_id = stream_widget.value();
|
2021-07-18 11:18:03 +02:00
|
|
|
|
|
|
|
let {
|
|
|
|
current_stream_id,
|
|
|
|
new_topic_name,
|
|
|
|
send_notification_to_new_thread,
|
|
|
|
send_notification_to_old_thread,
|
|
|
|
} = params;
|
|
|
|
send_notification_to_new_thread = send_notification_to_new_thread === "on";
|
|
|
|
send_notification_to_old_thread = send_notification_to_old_thread === "on";
|
|
|
|
current_stream_id = Number.parseInt(current_stream_id, 10);
|
|
|
|
|
2022-10-05 20:03:20 +02:00
|
|
|
if (new_topic_name !== undefined) {
|
|
|
|
// new_topic_name can be undefined when the new topic input is disabled when
|
|
|
|
// user does not have permission to edit topic.
|
|
|
|
new_topic_name = new_topic_name.trim();
|
|
|
|
}
|
|
|
|
if (old_topic_name.trim() === new_topic_name) {
|
2022-10-03 09:41:13 +02:00
|
|
|
// We use `undefined` to tell the server that
|
|
|
|
// there has been no change in the topic name.
|
|
|
|
new_topic_name = undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
let propagate_mode = "change_all";
|
|
|
|
if (message !== undefined) {
|
|
|
|
if (select_stream_id === current_stream_id) {
|
|
|
|
// We use `undefined` to tell the server that
|
|
|
|
// there has been no change in stream. This is
|
|
|
|
// important for cases when changing stream is
|
|
|
|
// not allowed.
|
|
|
|
select_stream_id = undefined;
|
|
|
|
}
|
|
|
|
// We already have the message_id here which means that modal is opened using
|
|
|
|
// message popover.
|
|
|
|
propagate_mode = $("#move_topic_modal select.message_edit_topic_propagate").val();
|
|
|
|
message_edit.move_topic_containing_message_to_stream(
|
|
|
|
message.id,
|
|
|
|
select_stream_id,
|
|
|
|
new_topic_name,
|
|
|
|
send_notification_to_new_thread,
|
|
|
|
send_notification_to_old_thread,
|
|
|
|
propagate_mode,
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-07-18 11:18:03 +02:00
|
|
|
dialog_widget.show_dialog_spinner();
|
2021-07-27 21:14:18 +02:00
|
|
|
message_edit.with_first_message_id(
|
2021-07-18 11:18:03 +02:00
|
|
|
current_stream_id,
|
|
|
|
old_topic_name,
|
|
|
|
(message_id) => {
|
|
|
|
if (old_topic_name && select_stream_id) {
|
|
|
|
message_edit.move_topic_containing_message_to_stream(
|
|
|
|
message_id,
|
|
|
|
select_stream_id,
|
|
|
|
new_topic_name,
|
|
|
|
send_notification_to_new_thread,
|
|
|
|
send_notification_to_old_thread,
|
2022-10-03 09:41:13 +02:00
|
|
|
propagate_mode,
|
2021-07-18 11:18:03 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(xhr) => {
|
|
|
|
dialog_widget.hide_dialog_spinner();
|
2021-11-24 16:03:21 +01:00
|
|
|
ui_report.error(
|
|
|
|
$t_html({defaultMessage: "Error moving topic"}),
|
|
|
|
xhr,
|
|
|
|
$("#move_topic_modal #dialog_error"),
|
|
|
|
);
|
2021-07-18 11:18:03 +02:00
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-02-26 12:28:09 +01:00
|
|
|
function set_stream_topic_typeahead() {
|
|
|
|
const $topic_input = $("#move_topic_form .inline_topic_edit");
|
|
|
|
const new_stream_id = Number(stream_widget.value(), 10);
|
|
|
|
const new_stream_name = sub_store.get(new_stream_id).name;
|
|
|
|
$topic_input.data("typeahead").unlisten();
|
|
|
|
composebox_typeahead.initialize_topic_edit_typeahead($topic_input, new_stream_name, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
function move_topic_on_update() {
|
|
|
|
update_submit_button_disabled_state();
|
|
|
|
set_stream_topic_typeahead();
|
|
|
|
}
|
|
|
|
|
2021-07-18 11:18:03 +02:00
|
|
|
function move_topic_post_render() {
|
2022-02-26 12:28:09 +01:00
|
|
|
const $topic_input = $("#move_topic_form .inline_topic_edit");
|
2022-01-25 11:36:19 +01:00
|
|
|
$stream_header_colorblock = $("#dialog_widget_modal .topic_stream_edit_header").find(
|
2021-07-18 11:18:03 +02:00
|
|
|
".stream_header_colorblock",
|
|
|
|
);
|
2022-01-25 11:36:19 +01:00
|
|
|
stream_bar.decorate(current_stream_name, $stream_header_colorblock, false);
|
2021-12-27 10:27:03 +01:00
|
|
|
const streams_list =
|
|
|
|
message_edit.get_available_streams_for_moving_messages(current_stream_id);
|
2021-07-18 11:18:03 +02:00
|
|
|
const opts = {
|
|
|
|
widget_name: "select_stream",
|
|
|
|
data: streams_list,
|
|
|
|
default_text: $t({defaultMessage: "No streams"}),
|
|
|
|
include_current_item: false,
|
|
|
|
value: current_stream_id,
|
2022-02-26 12:28:09 +01:00
|
|
|
on_update: move_topic_on_update,
|
2021-07-18 11:18:03 +02:00
|
|
|
};
|
|
|
|
stream_widget = new DropdownListWidget(opts);
|
2022-02-26 12:28:09 +01:00
|
|
|
|
|
|
|
composebox_typeahead.initialize_topic_edit_typeahead(
|
|
|
|
$topic_input,
|
|
|
|
current_stream_name,
|
|
|
|
false,
|
|
|
|
);
|
|
|
|
|
2022-04-28 00:12:57 +02:00
|
|
|
stream_widget.setup();
|
2022-04-14 06:43:38 +02:00
|
|
|
|
2022-10-05 20:03:20 +02:00
|
|
|
$("#select_stream_widget .dropdown-toggle").prop(
|
|
|
|
"disabled",
|
|
|
|
!settings_data.user_can_move_messages_between_streams(),
|
|
|
|
);
|
2022-04-14 06:43:38 +02:00
|
|
|
update_submit_button_disabled_state(stream_widget.value());
|
|
|
|
$("#move_topic_modal .inline_topic_edit").on("input", () => {
|
|
|
|
update_submit_button_disabled_state(stream_widget.value());
|
|
|
|
});
|
2021-07-18 11:18:03 +02:00
|
|
|
}
|
2020-05-12 13:41:45 +02:00
|
|
|
|
2021-07-18 11:18:03 +02:00
|
|
|
dialog_widget.launch({
|
2022-10-03 09:41:13 +02:00
|
|
|
html_heading: modal_heading,
|
2021-07-18 11:18:03 +02:00
|
|
|
html_body: render_move_topic_to_stream(args),
|
|
|
|
html_submit_button: $t_html({defaultMessage: "Confirm"}),
|
|
|
|
id: "move_topic_modal",
|
|
|
|
on_click: move_topic,
|
|
|
|
loading_spinner: true,
|
|
|
|
post_render: move_topic_post_render,
|
|
|
|
});
|
2020-02-19 01:38:34 +01:00
|
|
|
}
|
|
|
|
|
2021-02-28 01:02:37 +01:00
|
|
|
export function register_click_handlers() {
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#stream_filters").on("click", ".stream-sidebar-menu-icon", (e) => {
|
2019-02-22 17:07:49 +01:00
|
|
|
e.stopPropagation();
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const elt = e.target;
|
2022-01-25 11:36:19 +01:00
|
|
|
const $stream_li = $(elt).parents("li");
|
|
|
|
const stream_id = elem_to_stream_id($stream_li);
|
2019-02-22 17:07:49 +01:00
|
|
|
|
|
|
|
build_stream_popover({
|
2020-07-20 22:18:43 +02:00
|
|
|
elt,
|
|
|
|
stream_id,
|
2019-02-22 17:07:49 +01:00
|
|
|
});
|
|
|
|
});
|
2019-02-05 14:48:39 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#stream_filters").on("click", ".topic-sidebar-menu-icon", (e) => {
|
2019-02-05 14:48:39 +01:00
|
|
|
e.stopPropagation();
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const elt = $(e.target).closest(".topic-sidebar-menu-icon").expectOne()[0];
|
2022-01-25 11:36:19 +01:00
|
|
|
const $stream_li = $(elt).closest(".narrow-filter").expectOne();
|
|
|
|
const stream_id = elem_to_stream_id($stream_li);
|
2020-07-15 01:29:15 +02:00
|
|
|
const topic_name = $(elt).closest("li").expectOne().attr("data-topic-name");
|
2021-06-24 09:26:39 +02:00
|
|
|
const url = $(elt).closest("li").find(".topic-name").expectOne().prop("href");
|
2019-02-05 14:48:39 +01:00
|
|
|
|
|
|
|
build_topic_popover({
|
2020-07-20 22:18:43 +02:00
|
|
|
elt,
|
|
|
|
stream_id,
|
|
|
|
topic_name,
|
2019-02-05 14:48:39 +01:00
|
|
|
});
|
2021-06-24 09:26:39 +02:00
|
|
|
|
|
|
|
build_topic_link_clipboard(url);
|
2019-02-05 14:48:39 +01:00
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#global_filters").on("click", ".all-messages-sidebar-menu-icon", build_all_messages_popover);
|
2018-02-15 20:38:06 +01:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
$("#global_filters").on(
|
|
|
|
"click",
|
|
|
|
".starred-messages-sidebar-menu-icon",
|
|
|
|
build_starred_messages_popover,
|
|
|
|
);
|
2019-02-22 12:28:29 +01:00
|
|
|
|
2021-11-12 11:09:12 +01:00
|
|
|
$("#global_filters").on("click", ".drafts-sidebar-menu-icon", build_drafts_popover);
|
|
|
|
|
2021-03-28 19:28:30 +02:00
|
|
|
$("body").on("click keypress", ".move-topic-dropdown .list_item", (e) => {
|
|
|
|
// We want the dropdown to collapse once any of the list item is pressed
|
|
|
|
// and thus don't want to kill the natural bubbling of event.
|
|
|
|
e.preventDefault();
|
|
|
|
|
2022-09-28 08:27:24 +02:00
|
|
|
if (e.type === "keypress" && !keydown_util.is_enter_event(e)) {
|
2021-03-28 19:28:30 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
const stream_name = stream_data.maybe_get_stream_name(
|
|
|
|
Number.parseInt(stream_widget.value(), 10),
|
|
|
|
);
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
stream_bar.decorate(stream_name, $stream_header_colorblock, false);
|
2021-03-28 19:28:30 +02:00
|
|
|
});
|
|
|
|
|
2021-02-28 01:02:37 +01:00
|
|
|
register_stream_handlers();
|
|
|
|
register_topic_handlers();
|
|
|
|
}
|
2017-03-05 17:28:40 +01:00
|
|
|
|
2021-02-28 01:02:37 +01:00
|
|
|
export function register_stream_handlers() {
|
2017-03-05 17:28:40 +01:00
|
|
|
// Stream settings
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", ".open_stream_settings", (e) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const sub = stream_popover_sub(e);
|
2021-02-28 01:02:37 +01:00
|
|
|
hide_stream_popover();
|
2017-03-05 17:28:40 +01:00
|
|
|
|
2022-03-01 19:14:26 +01:00
|
|
|
const stream_edit_hash = hash_util.stream_edit_url(sub);
|
2021-03-22 16:09:12 +01:00
|
|
|
browser_history.go_to_location(stream_edit_hash);
|
2017-03-05 17:28:40 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// Pin/unpin
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", ".pin_to_top", (e) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const sub = stream_popover_sub(e);
|
2021-02-28 01:02:37 +01:00
|
|
|
hide_stream_popover();
|
2021-07-09 15:51:31 +02:00
|
|
|
stream_settings_ui.toggle_pin_to_top_stream(sub);
|
2017-03-05 17:28:40 +01:00
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
2018-02-15 20:38:06 +01:00
|
|
|
// Mark all messages in stream as read
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", ".mark_stream_as_read", (e) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const sub = stream_popover_sub(e);
|
2021-02-28 01:02:37 +01:00
|
|
|
hide_stream_popover();
|
2017-08-15 19:34:15 +02:00
|
|
|
unread_ops.mark_stream_as_read(sub.stream_id);
|
2017-03-05 17:28:40 +01:00
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
2018-02-15 20:38:06 +01:00
|
|
|
// Mark all messages as read
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", "#mark_all_messages_as_read", (e) => {
|
2021-02-28 01:02:37 +01:00
|
|
|
hide_all_messages_popover();
|
2020-06-18 08:11:41 +02:00
|
|
|
unread_ops.mark_all_as_read();
|
2018-02-15 20:38:06 +01:00
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
2021-02-26 21:23:32 +01:00
|
|
|
// Unstar all messages
|
|
|
|
$("body").on("click", "#unstar_all_messages", (e) => {
|
2021-02-28 01:02:37 +01:00
|
|
|
hide_starred_messages_popover();
|
2019-02-22 12:28:29 +01:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
2021-03-25 09:45:39 +01:00
|
|
|
starred_messages_ui.confirm_unstar_all_messages();
|
2019-02-22 12:28:29 +01:00
|
|
|
});
|
|
|
|
|
2021-11-12 11:09:12 +01:00
|
|
|
$("body").on("click", "#delete_all_drafts_sidebar", (e) => {
|
|
|
|
hide_drafts_popover();
|
|
|
|
e.stopPropagation();
|
|
|
|
drafts.confirm_delete_all_drafts();
|
|
|
|
});
|
|
|
|
|
2021-03-08 09:25:25 +01:00
|
|
|
// Unstar all messages in topic
|
|
|
|
$("body").on("click", ".sidebar-popover-unstar-all-in-topic", (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
const topic_name = $(".sidebar-popover-unstar-all-in-topic").attr("data-topic-name");
|
|
|
|
const stream_id = $(".sidebar-popover-unstar-all-in-topic").attr("data-stream-id");
|
|
|
|
hide_topic_popover();
|
2021-03-25 09:45:39 +01:00
|
|
|
starred_messages_ui.confirm_unstar_all_messages_in_topic(
|
2021-03-08 09:25:25 +01:00
|
|
|
Number.parseInt(stream_id, 10),
|
|
|
|
topic_name,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2019-03-18 17:46:07 +01:00
|
|
|
// Toggle displaying starred message count
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", "#toggle_display_starred_msg_count", (e) => {
|
2021-02-28 01:02:37 +01:00
|
|
|
hide_starred_messages_popover();
|
2019-03-18 17:46:07 +01:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
2021-07-28 16:00:58 +02:00
|
|
|
const starred_msg_counts = user_settings.starred_message_counts;
|
2019-11-02 00:06:25 +01:00
|
|
|
const data = {};
|
2019-03-18 17:46:07 +01:00
|
|
|
data.starred_message_counts = JSON.stringify(!starred_msg_counts);
|
|
|
|
channel.patch({
|
2021-07-10 21:23:28 +02:00
|
|
|
url: "/json/settings",
|
2020-07-20 22:18:43 +02:00
|
|
|
data,
|
2019-03-18 17:46:07 +01:00
|
|
|
});
|
|
|
|
});
|
2017-03-05 17:28:40 +01:00
|
|
|
// Mute/unmute
|
2020-07-22 02:08:20 +02:00
|
|
|
$("body").on("click", ".toggle_stream_muted", (e) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const sub = stream_popover_sub(e);
|
2021-02-28 01:02:37 +01:00
|
|
|
hide_stream_popover();
|
2021-07-09 15:51:31 +02:00
|
|
|
stream_settings_ui.set_muted(sub, !sub.is_muted);
|
2017-03-05 17:28:40 +01:00
|
|
|
e.stopPropagation();
|
2021-01-19 15:27:49 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// New topic in stream menu
|
|
|
|
$("body").on("click", ".popover_new_topic_button", (e) => {
|
|
|
|
const sub = stream_popover_sub(e);
|
|
|
|
hide_stream_popover();
|
|
|
|
|
2021-04-06 02:38:57 +02:00
|
|
|
compose_actions.start("stream", {
|
|
|
|
trigger: "popover new topic button",
|
|
|
|
stream: sub.name,
|
|
|
|
topic: "",
|
|
|
|
});
|
2021-01-19 15:27:49 +01:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
2017-03-05 17:28:40 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// Unsubscribe
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", ".popover_sub_unsub_button", function (e) {
|
2017-03-05 17:28:40 +01:00
|
|
|
$(this).toggleClass("unsub");
|
|
|
|
$(this).closest(".popover").fadeOut(500).delay(500).remove();
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const sub = stream_popover_sub(e);
|
2021-07-04 08:03:07 +02:00
|
|
|
stream_settings_ui.sub_or_unsub(sub);
|
2017-03-05 17:28:40 +01:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
2020-06-10 18:55:51 +02:00
|
|
|
// Choose a different color.
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", ".choose_stream_color", (e) => {
|
2022-01-25 11:36:19 +01:00
|
|
|
update_spectrum($(e.target).closest(".streams_popover"), ($colorpicker) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
$(".colorpicker-container").show();
|
2022-01-25 11:36:19 +01:00
|
|
|
$colorpicker.spectrum("destroy");
|
|
|
|
$colorpicker.spectrum(stream_color.sidebar_popover_colorpicker_options_full);
|
2017-03-05 17:28:40 +01:00
|
|
|
// In theory this should clean up the old color picker,
|
|
|
|
// but this seems a bit flaky -- the new colorpicker
|
|
|
|
// doesn't fire until you click a button, but the buttons
|
|
|
|
// have been hidden. We work around this by just manually
|
|
|
|
// fixing it up here.
|
2022-01-25 11:36:19 +01:00
|
|
|
$colorpicker.parent().find(".sp-container").removeClass("sp-buttons-disabled");
|
2017-03-05 17:28:40 +01:00
|
|
|
$(e.target).hide();
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$(".streams_popover").on("click", "a.sp-cancel", () => {
|
2021-02-28 01:02:37 +01:00
|
|
|
hide_stream_popover();
|
2017-03-05 17:28:40 +01:00
|
|
|
});
|
2020-10-20 19:43:41 +02:00
|
|
|
if ($(window).width() <= 768) {
|
|
|
|
$(".popover-inner").hide().fadeIn(300);
|
|
|
|
$(".popover").addClass("colorpicker-popover");
|
|
|
|
}
|
2017-03-05 17:28:40 +01:00
|
|
|
});
|
2021-02-28 01:02:37 +01:00
|
|
|
}
|
2017-03-05 17:28:40 +01:00
|
|
|
|
2021-02-28 01:02:37 +01:00
|
|
|
export function register_topic_handlers() {
|
2017-03-05 17:28:40 +01:00
|
|
|
// Mute the topic
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", ".sidebar-popover-mute-topic", (e) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const stream_id = topic_popover_stream_id(e);
|
2018-12-14 17:20:35 +01:00
|
|
|
if (!stream_id) {
|
2017-03-05 19:36:36 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const topic = $(e.currentTarget).attr("data-topic-name");
|
2021-07-08 20:36:52 +02:00
|
|
|
muted_topics_ui.mute_topic(stream_id, topic);
|
2017-03-05 17:28:40 +01:00
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Unmute the topic
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", ".sidebar-popover-unmute-topic", (e) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const stream_id = topic_popover_stream_id(e);
|
2018-12-14 17:20:35 +01:00
|
|
|
if (!stream_id) {
|
2017-03-05 19:36:36 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const topic = $(e.currentTarget).attr("data-topic-name");
|
2021-07-08 20:36:52 +02:00
|
|
|
muted_topics_ui.unmute_topic(stream_id, topic);
|
2017-03-05 17:28:40 +01:00
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Mark all messages as read
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", ".sidebar-popover-mark-topic-read", (e) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const stream_id = topic_popover_stream_id(e);
|
2018-12-14 18:40:57 +01:00
|
|
|
if (!stream_id) {
|
2017-03-05 19:36:36 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const topic = $(e.currentTarget).attr("data-topic-name");
|
2021-02-28 01:02:37 +01:00
|
|
|
hide_topic_popover();
|
2018-12-14 18:40:57 +01:00
|
|
|
unread_ops.mark_topic_as_read(stream_id, topic);
|
2017-03-05 17:28:40 +01:00
|
|
|
e.stopPropagation();
|
|
|
|
});
|
2019-01-18 17:40:54 +01:00
|
|
|
|
|
|
|
// Deleting all message in a topic
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", ".sidebar-popover-delete-topic-messages", (e) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const stream_id = topic_popover_stream_id(e);
|
2019-01-18 17:40:54 +01:00
|
|
|
if (!stream_id) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const topic = $(e.currentTarget).attr("data-topic-name");
|
2019-11-02 00:06:25 +01:00
|
|
|
const args = {
|
2019-01-18 17:40:54 +01:00
|
|
|
topic_name: topic,
|
|
|
|
};
|
|
|
|
|
2021-02-28 01:02:37 +01:00
|
|
|
hide_topic_popover();
|
2019-01-18 17:40:54 +01:00
|
|
|
|
2021-05-07 18:41:12 +02:00
|
|
|
const html_body = render_delete_topic_modal(args);
|
|
|
|
|
|
|
|
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);
|
|
|
|
},
|
2019-01-18 17:40:54 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
2020-02-19 01:38:34 +01:00
|
|
|
|
2021-06-11 20:50:03 +02:00
|
|
|
$("body").on("click", ".sidebar-popover-toggle-resolved", (e) => {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $topic_row = $(e.currentTarget);
|
|
|
|
const stream_id = Number.parseInt($topic_row.attr("data-stream-id"), 10);
|
|
|
|
const topic_name = $topic_row.attr("data-topic-name");
|
2021-07-27 21:14:18 +02:00
|
|
|
message_edit.with_first_message_id(stream_id, topic_name, (message_id) => {
|
2021-06-26 20:46:08 +02:00
|
|
|
message_edit.toggle_resolve_topic(message_id, topic_name);
|
|
|
|
});
|
2021-06-11 20:50:03 +02:00
|
|
|
|
|
|
|
hide_topic_popover();
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", ".sidebar-popover-move-topic-messages", (e) => {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $topic_row = $(e.currentTarget);
|
|
|
|
const stream_id = Number.parseInt($topic_row.attr("data-stream-id"), 10);
|
|
|
|
const topic_name = $topic_row.attr("data-topic-name");
|
2022-10-03 09:41:13 +02:00
|
|
|
hide_topic_popover();
|
2022-10-01 15:09:32 +02:00
|
|
|
build_move_topic_to_stream_popover(stream_id, topic_name);
|
2020-02-19 01:38:34 +01:00
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
2021-02-28 01:02:37 +01:00
|
|
|
}
|