2020-07-15 01:29:15 +02:00
|
|
|
const render_all_messages_sidebar_actions = require("../templates/all_messages_sidebar_actions.hbs");
|
|
|
|
const render_delete_topic_modal = require("../templates/delete_topic_modal.hbs");
|
2020-07-24 06:02:07 +02:00
|
|
|
const render_move_topic_to_stream = require("../templates/move_topic_to_stream.hbs");
|
2020-07-15 01:29:15 +02:00
|
|
|
const render_starred_messages_sidebar_actions = require("../templates/starred_messages_sidebar_actions.hbs");
|
|
|
|
const render_stream_sidebar_actions = require("../templates/stream_sidebar_actions.hbs");
|
|
|
|
const render_topic_sidebar_actions = require("../templates/topic_sidebar_actions.hbs");
|
2019-11-02 00:06:25 +01:00
|
|
|
const render_unstar_messages_modal = require("../templates/unstar_messages_modal.hbs");
|
2019-07-09 21:24:00 +02: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;
|
2017-03-05 17:28:40 +01:00
|
|
|
|
2020-01-12 13:39:37 +01:00
|
|
|
function elem_to_stream_id(elem) {
|
2020-07-15 01:29:15 +02:00
|
|
|
const stream_id = 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));
|
|
|
|
}
|
|
|
|
|
2017-03-05 17:28:40 +01:00
|
|
|
exports.stream_popped = function () {
|
|
|
|
return current_stream_sidebar_elem !== undefined;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.topic_popped = function () {
|
|
|
|
return current_topic_sidebar_elem !== undefined;
|
|
|
|
};
|
|
|
|
|
2018-02-15 20:38:06 +01:00
|
|
|
exports.all_messages_popped = function () {
|
|
|
|
return all_messages_sidebar_elem !== undefined;
|
|
|
|
};
|
|
|
|
|
2019-02-22 12:28:29 +01:00
|
|
|
exports.starred_messages_popped = function () {
|
|
|
|
return starred_messages_sidebar_elem !== undefined;
|
|
|
|
};
|
|
|
|
|
2017-03-05 17:28:40 +01:00
|
|
|
exports.hide_stream_popover = function () {
|
|
|
|
if (exports.stream_popped()) {
|
|
|
|
$(current_stream_sidebar_elem).popover("destroy");
|
|
|
|
current_stream_sidebar_elem = undefined;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.hide_topic_popover = function () {
|
|
|
|
if (exports.topic_popped()) {
|
|
|
|
$(current_topic_sidebar_elem).popover("destroy");
|
|
|
|
current_topic_sidebar_elem = undefined;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-02-15 20:38:06 +01:00
|
|
|
exports.hide_all_messages_popover = function () {
|
|
|
|
if (exports.all_messages_popped()) {
|
|
|
|
$(all_messages_sidebar_elem).popover("destroy");
|
|
|
|
all_messages_sidebar_elem = undefined;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-02-22 12:28:29 +01:00
|
|
|
exports.hide_starred_messages_popover = function () {
|
|
|
|
if (exports.starred_messages_popped()) {
|
|
|
|
$(starred_messages_sidebar_elem).popover("destroy");
|
|
|
|
starred_messages_sidebar_elem = undefined;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-03-05 17:28:40 +01:00
|
|
|
// These are the only two functions that is really shared by the
|
|
|
|
// two popovers, so we could split out topic stuff to
|
|
|
|
// another module pretty easily.
|
2017-03-08 23:39:39 +01:00
|
|
|
exports.show_streamlist_sidebar = function () {
|
2017-03-05 17:28:40 +01:00
|
|
|
$(".app-main .column-left").addClass("expanded");
|
|
|
|
resize.resize_page_components();
|
|
|
|
};
|
|
|
|
|
2019-07-10 01:56:25 +02:00
|
|
|
exports.hide_streamlist_sidebar = function () {
|
2017-03-05 17:28:40 +01:00
|
|
|
$(".app-main .column-left").removeClass("expanded");
|
|
|
|
};
|
|
|
|
|
|
|
|
function stream_popover_sub(e) {
|
2020-07-15 01:29:15 +02:00
|
|
|
const elem = $(e.currentTarget).parents("ul");
|
2020-01-12 13:39:37 +01:00
|
|
|
const stream_id = elem_to_stream_id(elem);
|
2019-11-02 00:06:25 +01:00
|
|
|
const sub = stream_data.get_sub_by_id(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);
|
2017-03-05 17:28:40 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
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.
|
|
|
|
function update_spectrum(popover, update_func) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const initial_height = popover[0].offsetHeight;
|
2017-03-05 17:28:40 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const colorpicker = popover.find(".colorpicker-container").find(".colorpicker");
|
2017-03-05 17:28:40 +01:00
|
|
|
update_func(colorpicker);
|
2019-11-02 00:06:25 +01:00
|
|
|
const after_height = popover[0].offsetHeight;
|
2017-03-05 17:28:40 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const popover_root = popover.closest(".popover");
|
2020-07-15 01:29:15 +02:00
|
|
|
const current_top_px = 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;
|
|
|
|
popover_root.find("div.arrow").hide();
|
|
|
|
} else if (top + after_height > $(window).height() - 20) {
|
|
|
|
top = $(window).height() - after_height - 20;
|
|
|
|
if (top < 0) {
|
|
|
|
top = 0;
|
|
|
|
}
|
|
|
|
popover_root.find("div.arrow").hide();
|
|
|
|
}
|
2017-03-05 17:28:40 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
popover_root.css("top", top + "px");
|
2017-03-05 17:28:40 +01:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
if (exports.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.
|
|
|
|
exports.hide_stream_popover();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
popovers.hide_all();
|
2017-03-08 23:39:39 +01:00
|
|
|
exports.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({
|
2019-07-09 21:24:00 +02:00
|
|
|
stream: stream_data.get_sub_by_id(stream_id),
|
|
|
|
});
|
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");
|
2020-07-15 01:29:15 +02:00
|
|
|
const popover = $(".streams_popover[data-stream-id=" + stream_id + "]");
|
2017-03-05 17:28:40 +01:00
|
|
|
|
2020-07-02 01:45:54 +02:00
|
|
|
update_spectrum(popover, (colorpicker) => {
|
2017-03-05 17:28:40 +01:00
|
|
|
colorpicker.spectrum(stream_color.sidebar_popover_colorpicker_options);
|
|
|
|
});
|
|
|
|
|
|
|
|
current_stream_sidebar_elem = elt;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
if (exports.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.
|
2017-03-09 08:25:22 +01:00
|
|
|
exports.hide_topic_popover();
|
2017-03-05 17:28:40 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const sub = stream_data.get_sub_by_id(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();
|
2017-03-08 23:39:39 +01:00
|
|
|
exports.show_streamlist_sidebar();
|
2017-03-05 19:36:36 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const is_muted = muting.is_topic_muted(sub.stream_id, topic_name);
|
|
|
|
const can_mute_topic = !is_muted;
|
|
|
|
const can_unmute_topic = is_muted;
|
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,
|
|
|
|
can_mute_topic,
|
|
|
|
can_unmute_topic,
|
2019-01-18 17:40:54 +01:00
|
|
|
is_admin: sub.is_admin,
|
2020-06-20 17:50:19 +02:00
|
|
|
color: sub.color,
|
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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
if (exports.all_messages_popped() && all_messages_sidebar_elem === elt) {
|
2018-02-15 20:38:06 +01:00
|
|
|
exports.hide_all_messages_popover();
|
|
|
|
e.stopPropagation();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
popovers.hide_all();
|
|
|
|
|
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;
|
|
|
|
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
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
if (exports.starred_messages_popped() && starred_messages_sidebar_elem === elt) {
|
2019-02-22 12:28:29 +01:00
|
|
|
exports.hide_starred_messages_popover();
|
|
|
|
e.stopPropagation();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
popovers.hide_all();
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const content = render_starred_messages_sidebar_actions({
|
2019-07-09 21:24:00 +02:00
|
|
|
starred_message_counts: page_params.starred_message_counts,
|
|
|
|
});
|
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;
|
|
|
|
e.stopPropagation();
|
|
|
|
}
|
|
|
|
|
2020-02-19 01:38:34 +01:00
|
|
|
function build_move_topic_to_stream_popover(e, current_stream_id, topic_name) {
|
|
|
|
// TODO: Add support for keyboard-alphabet navigation. Some orgs
|
|
|
|
// many streams and scrolling can be a painful process in that
|
|
|
|
// case.
|
|
|
|
//
|
|
|
|
// NOTE: Private streams are also included in this list. We
|
|
|
|
// likely will make it possible to move messages to/from private
|
|
|
|
// streams in the future.
|
2020-07-15 00:34:28 +02:00
|
|
|
const available_streams = stream_data
|
|
|
|
.subscribed_subs()
|
2020-07-02 01:39:34 +02:00
|
|
|
.filter((s) => s.stream_id !== current_stream_id);
|
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
|
|
|
available_streams,
|
|
|
|
topic_name,
|
|
|
|
current_stream_id,
|
|
|
|
current_stream_name,
|
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,
|
|
|
|
};
|
2020-02-19 01:38:34 +01:00
|
|
|
|
|
|
|
exports.hide_topic_popover();
|
|
|
|
|
|
|
|
$("#move-a-topic-modal-holder").html(render_move_topic_to_stream(args));
|
2020-05-12 13:41:45 +02:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
const stream_header_colorblock = $(".topic_stream_edit_header").find(
|
|
|
|
".stream_header_colorblock",
|
|
|
|
);
|
2020-05-16 10:09:13 +02:00
|
|
|
ui_util.decorate_stream_bar(current_stream_name, stream_header_colorblock, false);
|
2020-07-20 21:26:58 +02:00
|
|
|
$("#select_stream_id").on("change", function () {
|
2020-05-12 13:41:45 +02:00
|
|
|
const stream_name = stream_data.maybe_get_stream_name(parseInt(this.value, 10));
|
|
|
|
ui_util.decorate_stream_bar(stream_name, stream_header_colorblock, false);
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#move_topic_modal").modal("show");
|
2020-02-19 01:38:34 +01:00
|
|
|
e.stopPropagation();
|
|
|
|
}
|
|
|
|
|
2017-03-05 17:28:40 +01:00
|
|
|
exports.register_click_handlers = function () {
|
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;
|
2020-07-15 01:29:15 +02:00
|
|
|
const stream_li = $(elt).parents("li");
|
2020-01-12 13:39:37 +01:00
|
|
|
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];
|
|
|
|
const stream_li = $(elt).closest(".narrow-filter").expectOne();
|
2020-01-12 13:39:37 +01:00
|
|
|
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");
|
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
|
|
|
});
|
|
|
|
});
|
|
|
|
|
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
|
|
|
|
2017-03-05 17:28:40 +01:00
|
|
|
exports.register_stream_handlers();
|
|
|
|
exports.register_topic_handlers();
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.register_stream_handlers = function () {
|
|
|
|
// 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);
|
2017-03-05 17:28:40 +01:00
|
|
|
exports.hide_stream_popover();
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const stream_edit_hash = hash_util.stream_edit_uri(sub);
|
2018-12-02 19:59:59 +01:00
|
|
|
hashchange.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);
|
2017-03-05 17:28:40 +01:00
|
|
|
exports.hide_stream_popover();
|
|
|
|
subs.toggle_pin_to_top_stream(sub);
|
|
|
|
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);
|
2017-03-05 17:28:40 +01:00
|
|
|
exports.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) => {
|
2018-02-15 20:38:06 +01:00
|
|
|
exports.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();
|
|
|
|
});
|
|
|
|
|
2019-02-22 12:28:29 +01:00
|
|
|
// Unstar all messages
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", "#unstar_all_messages", (e) => {
|
2019-02-22 12:28:29 +01:00
|
|
|
exports.hide_starred_messages_popover();
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
$(".left-sidebar-modal-holder").empty();
|
2019-07-09 21:24:00 +02:00
|
|
|
$(".left-sidebar-modal-holder").html(render_unstar_messages_modal());
|
2019-02-22 12:28:29 +01:00
|
|
|
$("#unstar-messages-modal").modal("show");
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", "#do_unstar_messages_button", (e) => {
|
2019-02-22 12:28:29 +01:00
|
|
|
$("#unstar-messages-modal").modal("hide");
|
|
|
|
message_flags.unstar_all_messages();
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
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) => {
|
2019-03-18 17:46:07 +01:00
|
|
|
exports.hide_starred_messages_popover();
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
2019-11-02 00:06:25 +01:00
|
|
|
const starred_msg_counts = page_params.starred_message_counts;
|
|
|
|
const data = {};
|
2019-03-18 17:46:07 +01:00
|
|
|
data.starred_message_counts = JSON.stringify(!starred_msg_counts);
|
|
|
|
channel.patch({
|
2020-07-15 01:29:15 +02:00
|
|
|
url: "/json/settings/display",
|
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);
|
2017-03-05 17:28:40 +01:00
|
|
|
exports.hide_stream_popover();
|
2020-07-22 00:43:11 +02:00
|
|
|
subs.set_muted(sub, !sub.is_muted);
|
2017-03-05 17:28:40 +01:00
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
|
|
|
// 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);
|
2017-03-05 17:28:40 +01:00
|
|
|
subs.sub_or_unsub(sub);
|
|
|
|
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) => {
|
|
|
|
update_spectrum($(e.target).closest(".streams_popover"), (colorpicker) => {
|
|
|
|
$(".colorpicker-container").show();
|
2017-03-05 17:28:40 +01:00
|
|
|
colorpicker.spectrum("destroy");
|
|
|
|
colorpicker.spectrum(stream_color.sidebar_popover_colorpicker_options_full);
|
|
|
|
// 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.
|
2020-07-15 01:29:15 +02: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", () => {
|
2017-03-05 17:28:40 +01:00
|
|
|
exports.hide_stream_popover();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2018-12-14 17:20:35 +01:00
|
|
|
function topic_popover_sub(e) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const stream_id = topic_popover_stream_id(e);
|
2017-03-05 19:36:36 +01:00
|
|
|
if (!stream_id) {
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.error("cannot find stream id");
|
2017-03-05 19:36:36 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const sub = stream_data.get_sub_by_id(stream_id);
|
2017-03-05 19:36:36 +01:00
|
|
|
if (!sub) {
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.error("Unknown stream: " + stream_id);
|
2017-03-05 19:36:36 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
return sub;
|
|
|
|
}
|
|
|
|
|
2017-03-05 17:28:40 +01:00
|
|
|
exports.register_topic_handlers = function () {
|
|
|
|
// Narrow to topic
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", ".narrow_to_topic", (e) => {
|
2017-03-05 17:28:40 +01:00
|
|
|
exports.hide_topic_popover();
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const sub = topic_popover_sub(e);
|
2017-03-05 19:36:36 +01:00
|
|
|
if (!sub) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const topic = $(e.currentTarget).attr("data-topic-name");
|
2017-03-05 17:28:40 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const operators = [
|
2020-07-15 01:29:15 +02:00
|
|
|
{operator: "stream", operand: sub.name},
|
|
|
|
{operator: "topic", operand: topic},
|
2017-03-05 17:28:40 +01:00
|
|
|
];
|
2020-07-15 01:29:15 +02:00
|
|
|
narrow.activate(operators, {trigger: "sidebar"});
|
2017-03-05 17:28:40 +01:00
|
|
|
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
|
|
|
// 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");
|
2018-12-14 17:20:35 +01:00
|
|
|
muting_ui.mute(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");
|
2018-12-14 17:20:35 +01:00
|
|
|
muting_ui.unmute(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");
|
2017-03-05 17:28:40 +01:00
|
|
|
exports.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,
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.hide_topic_popover();
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#delete-topic-modal-holder").html(render_delete_topic_modal(args));
|
2019-01-18 17:40:54 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#do_delete_topic_button").on("click", () => {
|
2019-01-18 17:40:54 +01:00
|
|
|
message_edit.delete_topic(stream_id, topic);
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#delete_topic_modal").modal("show");
|
2019-01-18 17:40:54 +01:00
|
|
|
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
2020-02-19 01:38:34 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", ".sidebar-popover-move-topic-messages", (e) => {
|
2020-02-19 01:38:34 +01:00
|
|
|
const topic_row = $(e.currentTarget);
|
2020-07-15 01:29:15 +02:00
|
|
|
const stream_id = parseInt(topic_row.attr("data-stream-id"), 10);
|
|
|
|
const topic_name = topic_row.attr("data-topic-name");
|
2020-02-19 01:38:34 +01:00
|
|
|
build_move_topic_to_stream_popover(e, stream_id, topic_name);
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", "#topic_stream_edit_form_error .send-status-close", () => {
|
2020-02-19 01:38:34 +01:00
|
|
|
$("#topic_stream_edit_form_error").hide();
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", "#do_move_topic_button", (e) => {
|
2020-05-16 09:58:55 +02:00
|
|
|
function show_error_msg(msg) {
|
|
|
|
$("#topic_stream_edit_form_error .error-msg").text(msg);
|
|
|
|
$("#topic_stream_edit_form_error").show();
|
|
|
|
}
|
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
const params = $("#move_topic_form")
|
|
|
|
.serializeArray()
|
|
|
|
.reduce((obj, item) => {
|
|
|
|
obj[item.name] = item.value;
|
|
|
|
return obj;
|
|
|
|
}, {});
|
2020-02-19 01:38:34 +01:00
|
|
|
|
|
|
|
const {old_topic_name, select_stream_id} = params;
|
2020-07-15 00:34:28 +02:00
|
|
|
let {
|
|
|
|
current_stream_id,
|
|
|
|
new_topic_name,
|
|
|
|
send_notification_to_new_thread,
|
|
|
|
send_notification_to_old_thread,
|
|
|
|
} = params;
|
2020-06-03 16:29:07 +02:00
|
|
|
new_topic_name = new_topic_name.trim();
|
2020-07-15 01:29:15 +02:00
|
|
|
send_notification_to_new_thread = send_notification_to_new_thread === "on";
|
|
|
|
send_notification_to_old_thread = send_notification_to_old_thread === "on";
|
2020-02-19 01:38:34 +01:00
|
|
|
current_stream_id = parseInt(current_stream_id, 10);
|
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
if (
|
|
|
|
current_stream_id === parseInt(select_stream_id, 10) &&
|
|
|
|
new_topic_name.toLowerCase() === old_topic_name.toLowerCase()
|
|
|
|
) {
|
2020-05-16 10:09:13 +02:00
|
|
|
show_error_msg("Please select a different stream or change topic name.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-02-19 01:38:34 +01:00
|
|
|
// The API endpoint for editing messages to change their
|
|
|
|
// content, topic, or stream requires a message ID.
|
|
|
|
//
|
|
|
|
// Because we don't have full data in the browser client, it's
|
|
|
|
// possible that we might display a topic in the left sidebar
|
|
|
|
// (and thus expose the UI for moving its topic to another
|
|
|
|
// stream) without having a message ID that is definitely
|
|
|
|
// within the topic. (The comments in stream_topic_history.js
|
|
|
|
// discuss the tricky issues around message deletion that are
|
|
|
|
// involved here).
|
|
|
|
//
|
|
|
|
// To ensure this option works reliably at a small latency
|
|
|
|
// cost for a rare operation, we just ask the server for the
|
|
|
|
// latest message ID in the topic.
|
|
|
|
const data = {
|
2020-07-15 01:29:15 +02:00
|
|
|
anchor: "newest",
|
2020-02-19 01:38:34 +01:00
|
|
|
num_before: 1,
|
|
|
|
num_after: 0,
|
2020-07-15 00:34:28 +02:00
|
|
|
narrow: JSON.stringify([
|
|
|
|
{operator: "stream", operand: current_stream_id},
|
|
|
|
{operator: "topic", operand: old_topic_name},
|
|
|
|
]),
|
2020-02-19 01:38:34 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
channel.get({
|
2020-07-15 01:29:15 +02:00
|
|
|
url: "/json/messages",
|
2020-07-20 22:18:43 +02:00
|
|
|
data,
|
2020-02-19 01:38:34 +01:00
|
|
|
idempotent: true,
|
2020-07-20 22:18:43 +02:00
|
|
|
success(data) {
|
2020-02-19 01:38:34 +01:00
|
|
|
const message_id = data.messages[0].id;
|
|
|
|
|
|
|
|
if (old_topic_name.trim() === new_topic_name.trim()) {
|
|
|
|
// We use `undefined` to tell the server that
|
|
|
|
// there has been no change in the topic name.
|
|
|
|
new_topic_name = undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (old_topic_name && select_stream_id) {
|
|
|
|
message_edit.move_topic_containing_message_to_stream(
|
2020-07-15 00:34:28 +02:00
|
|
|
message_id,
|
|
|
|
select_stream_id,
|
|
|
|
new_topic_name,
|
2020-06-03 16:44:57 +02:00
|
|
|
send_notification_to_new_thread,
|
2020-07-15 00:34:28 +02:00
|
|
|
send_notification_to_old_thread,
|
|
|
|
);
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#move_topic_modal").modal("hide");
|
2020-02-19 01:38:34 +01:00
|
|
|
}
|
|
|
|
},
|
2020-07-20 22:18:43 +02:00
|
|
|
error(xhr) {
|
2020-05-16 09:58:55 +02:00
|
|
|
show_error_msg(xhr.responseJSON.msg);
|
2020-02-19 01:38:34 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
2017-03-05 17:28:40 +01:00
|
|
|
};
|
|
|
|
|
2019-10-25 09:45:13 +02:00
|
|
|
window.stream_popover = exports;
|