2021-02-28 01:03:09 +01:00
|
|
|
import ClipboardJS from "clipboard";
|
2021-11-02 08:36:31 +01:00
|
|
|
import {add, formatISO, parseISO, set} from "date-fns";
|
2021-02-28 01:03:09 +01:00
|
|
|
import ConfirmDatePlugin from "flatpickr/dist/plugins/confirmDate/confirmDate";
|
2021-03-11 05:43:45 +01:00
|
|
|
import $ from "jquery";
|
2021-07-09 09:02:58 +02:00
|
|
|
import tippy, {hideAll} from "tippy.js";
|
2021-02-28 01:03:09 +01:00
|
|
|
|
|
|
|
import render_actions_popover_content from "../templates/actions_popover_content.hbs";
|
2022-10-05 12:41:38 +02:00
|
|
|
import render_actions_popover_template from "../templates/actions_popover_template.hbs";
|
2021-02-28 01:03:09 +01:00
|
|
|
import render_no_arrow_popover from "../templates/no_arrow_popover.hbs";
|
|
|
|
import render_playground_links_popover_content from "../templates/playground_links_popover_content.hbs";
|
|
|
|
import render_remind_me_popover_content from "../templates/remind_me_popover_content.hbs";
|
|
|
|
import render_user_group_info_popover from "../templates/user_group_info_popover.hbs";
|
|
|
|
import render_user_group_info_popover_content from "../templates/user_group_info_popover_content.hbs";
|
|
|
|
import render_user_info_popover_content from "../templates/user_info_popover_content.hbs";
|
2022-10-03 13:29:59 +02:00
|
|
|
import render_user_info_popover_manage_menu from "../templates/user_info_popover_manage_menu.hbs";
|
2021-02-28 01:03:09 +01:00
|
|
|
import render_user_info_popover_title from "../templates/user_info_popover_title.hbs";
|
|
|
|
|
2021-03-16 23:38:59 +01:00
|
|
|
import * as blueslip from "./blueslip";
|
2021-02-28 01:12:35 +01:00
|
|
|
import * as buddy_data from "./buddy_data";
|
2022-03-18 13:03:26 +01:00
|
|
|
import * as channel from "./channel";
|
2021-02-28 21:32:22 +01:00
|
|
|
import * as compose_actions from "./compose_actions";
|
2021-02-28 01:03:09 +01:00
|
|
|
import * as compose_state from "./compose_state";
|
2021-02-28 01:26:48 +01:00
|
|
|
import * as compose_ui from "./compose_ui";
|
2021-02-28 01:03:09 +01:00
|
|
|
import * as condense from "./condense";
|
2022-10-05 12:41:38 +02:00
|
|
|
import {media_breakpoints_num} from "./css_variables";
|
2022-03-18 13:03:26 +01:00
|
|
|
import * as dialog_widget from "./dialog_widget";
|
2021-02-28 01:26:16 +01:00
|
|
|
import * as emoji_picker from "./emoji_picker";
|
2021-03-31 07:48:11 +02:00
|
|
|
import * as giphy from "./giphy";
|
2021-02-28 01:07:13 +01:00
|
|
|
import * as hash_util from "./hash_util";
|
2022-03-18 13:03:26 +01:00
|
|
|
import {$t, $t_html} from "./i18n";
|
2021-02-28 01:03:09 +01:00
|
|
|
import * as message_edit from "./message_edit";
|
|
|
|
import * as message_edit_history from "./message_edit_history";
|
2021-03-30 02:21:21 +02:00
|
|
|
import * as message_lists from "./message_lists";
|
2021-02-28 01:03:09 +01:00
|
|
|
import * as message_viewport from "./message_viewport";
|
2021-06-27 21:38:26 +02:00
|
|
|
import * as muted_users from "./muted_users";
|
2021-07-08 20:28:14 +02:00
|
|
|
import * as muted_users_ui from "./muted_users_ui";
|
2021-02-28 21:31:57 +01:00
|
|
|
import * as narrow from "./narrow";
|
2021-02-28 01:03:46 +01:00
|
|
|
import * as overlays from "./overlays";
|
2021-03-25 22:35:45 +01:00
|
|
|
import {page_params} from "./page_params";
|
2021-02-28 01:03:09 +01:00
|
|
|
import * as people from "./people";
|
2021-06-17 19:05:34 +02:00
|
|
|
import * as popover_menus from "./popover_menus";
|
2022-11-24 09:01:49 +01:00
|
|
|
import * as popover_menus_data from "./popover_menus_data";
|
2021-06-16 21:15:47 +02:00
|
|
|
import * as read_receipts from "./read_receipts";
|
2021-04-13 08:43:03 +02:00
|
|
|
import * as realm_playground from "./realm_playground";
|
2021-02-28 01:16:59 +01:00
|
|
|
import * as reminder from "./reminder";
|
2021-02-28 01:03:09 +01:00
|
|
|
import * as resize from "./resize";
|
|
|
|
import * as rows from "./rows";
|
2022-07-08 19:10:15 +02:00
|
|
|
import * as settings_bots from "./settings_bots";
|
2022-04-22 20:32:41 +02:00
|
|
|
import * as settings_config from "./settings_config";
|
2021-02-28 01:03:09 +01:00
|
|
|
import * as settings_data from "./settings_data";
|
2021-11-26 13:46:11 +01:00
|
|
|
import * as settings_users from "./settings_users";
|
2021-02-28 01:03:09 +01:00
|
|
|
import * as stream_popover from "./stream_popover";
|
2022-03-18 13:03:26 +01:00
|
|
|
import * as ui_report from "./ui_report";
|
2021-08-05 00:59:03 +02:00
|
|
|
import * as unread_ops from "./unread_ops";
|
2021-02-28 01:03:09 +01:00
|
|
|
import * as user_groups from "./user_groups";
|
2022-07-12 21:25:02 +02:00
|
|
|
import * as user_profile from "./user_profile";
|
2022-09-21 15:49:36 +02:00
|
|
|
import {user_settings} from "./user_settings";
|
2021-02-28 01:03:09 +01:00
|
|
|
import * as user_status from "./user_status";
|
|
|
|
import * as user_status_ui from "./user_status_ui";
|
|
|
|
import * as util from "./util";
|
2020-08-01 03:43:15 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
let $current_actions_popover_elem;
|
2019-11-02 00:06:25 +01:00
|
|
|
let current_flatpickr_instance;
|
2022-01-25 11:36:19 +01:00
|
|
|
let $current_message_info_popover_elem;
|
|
|
|
let $current_user_info_popover_elem;
|
2022-10-03 13:29:59 +02:00
|
|
|
let $current_user_info_popover_manage_menu;
|
2022-01-25 11:36:19 +01:00
|
|
|
let $current_playground_links_popover_elem;
|
2019-11-02 00:06:25 +01:00
|
|
|
let userlist_placement = "right";
|
|
|
|
|
|
|
|
let list_of_popovers = [];
|
2017-01-04 02:44:49 +01:00
|
|
|
|
2021-03-16 11:31:40 +01:00
|
|
|
export function clear_for_testing() {
|
2022-01-25 11:36:19 +01:00
|
|
|
$current_actions_popover_elem = undefined;
|
2021-03-16 11:31:40 +01:00
|
|
|
current_flatpickr_instance = undefined;
|
2022-01-25 11:36:19 +01:00
|
|
|
$current_message_info_popover_elem = undefined;
|
|
|
|
$current_user_info_popover_elem = undefined;
|
2022-10-03 13:29:59 +02:00
|
|
|
$current_user_info_popover_manage_menu = undefined;
|
2022-01-25 11:36:19 +01:00
|
|
|
$current_playground_links_popover_elem = undefined;
|
2021-03-16 11:31:40 +01:00
|
|
|
list_of_popovers.length = 0;
|
|
|
|
userlist_placement = "right";
|
|
|
|
}
|
|
|
|
|
2021-03-06 20:28:43 +01:00
|
|
|
export function clipboard_enable(arg) {
|
|
|
|
// arg is a selector or element
|
|
|
|
// We extract this function for testing purpose.
|
|
|
|
return new ClipboardJS(arg);
|
|
|
|
}
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
export function elem_to_user_id($elem) {
|
|
|
|
return Number.parseInt($elem.attr("data-user-id"), 10);
|
2020-01-12 22:32:29 +01:00
|
|
|
}
|
|
|
|
|
2017-01-04 02:44:49 +01:00
|
|
|
// this utilizes the proxy pattern to intercept all calls to $.fn.popover
|
|
|
|
// and push the $.fn.data($o, "popover") results to an array.
|
|
|
|
// this is needed so that when we try to unload popovers, we can kill all dead
|
|
|
|
// ones that no longer have valid parents in the DOM.
|
2021-05-06 21:49:45 +02:00
|
|
|
const old_popover = $.fn.popover;
|
|
|
|
$.fn.popover = Object.assign(function (...args) {
|
|
|
|
// apply the jQuery object as `this`, and popover function arguments.
|
|
|
|
old_popover.apply(this, args);
|
|
|
|
|
|
|
|
// if there is a valid "popover" key in the jQuery data object then
|
|
|
|
// push it to the array.
|
|
|
|
if (this.data("popover")) {
|
|
|
|
list_of_popovers.push(this.data("popover"));
|
|
|
|
}
|
|
|
|
}, old_popover);
|
2017-01-04 02:44:49 +01:00
|
|
|
|
2018-02-03 17:38:35 +01:00
|
|
|
function copy_email_handler(e) {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $email_el = $(e.trigger.parentElement);
|
|
|
|
const $copy_icon = $email_el.find("i");
|
2018-02-03 17:38:35 +01:00
|
|
|
|
|
|
|
// only change the parent element's text back to email
|
|
|
|
// and not overwrite the tooltip.
|
2022-01-25 11:36:19 +01:00
|
|
|
const email_textnode = $email_el[0].childNodes[2];
|
2018-02-03 17:38:35 +01:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
$email_el.addClass("email_copied");
|
2021-04-13 06:51:54 +02:00
|
|
|
email_textnode.nodeValue = $t({defaultMessage: "Email copied"});
|
2018-02-03 17:38:35 +01:00
|
|
|
|
2020-07-02 01:45:54 +02:00
|
|
|
setTimeout(() => {
|
2022-01-25 11:36:19 +01:00
|
|
|
$email_el.removeClass("email_copied");
|
|
|
|
email_textnode.nodeValue = $copy_icon.attr("data-clipboard-text");
|
2018-02-03 17:38:35 +01:00
|
|
|
}, 1500);
|
|
|
|
e.clearSelection();
|
|
|
|
}
|
|
|
|
|
|
|
|
function init_email_clipboard() {
|
2020-04-08 23:44:20 +02:00
|
|
|
/*
|
|
|
|
This shows (and enables) the copy-text icon for folks
|
|
|
|
who have names that would overflow past the right
|
|
|
|
edge of our user mention popup.
|
|
|
|
*/
|
2020-07-15 01:29:15 +02:00
|
|
|
$(".user_popover_email").each(function () {
|
2018-02-03 17:38:35 +01:00
|
|
|
if (this.clientWidth < this.scrollWidth) {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $email_el = $(this);
|
|
|
|
const $copy_email_icon = $email_el.find("i");
|
2018-02-03 17:38:35 +01:00
|
|
|
|
2020-04-08 23:44:20 +02:00
|
|
|
/*
|
|
|
|
For deactivated users, the copy-email icon will
|
|
|
|
not even be present in the HTML, so we don't do
|
|
|
|
anything. We don't reveal emails for deactivated
|
|
|
|
users.
|
|
|
|
*/
|
2022-01-25 11:36:19 +01:00
|
|
|
if ($copy_email_icon[0]) {
|
|
|
|
$copy_email_icon.removeClass("hide_copy_icon");
|
|
|
|
const copy_email_clipboard = clipboard_enable($copy_email_icon[0]);
|
2020-07-15 01:29:15 +02:00
|
|
|
copy_email_clipboard.on("success", copy_email_handler);
|
2020-04-08 23:44:20 +02:00
|
|
|
}
|
2018-02-03 17:38:35 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-07-09 09:02:58 +02:00
|
|
|
function init_email_tooltip(user) {
|
|
|
|
/*
|
|
|
|
This displays the email tooltip for folks
|
|
|
|
who have names that would overflow past the right
|
|
|
|
edge of our user mention popup.
|
|
|
|
*/
|
|
|
|
|
|
|
|
$(".user_popover_email").each(function () {
|
|
|
|
if (this.clientWidth < this.scrollWidth) {
|
|
|
|
tippy(this, {
|
|
|
|
placement: "bottom",
|
|
|
|
content: people.get_visible_email(user),
|
|
|
|
interactive: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
function load_medium_avatar(user, $elt) {
|
2021-11-06 07:23:26 +01:00
|
|
|
const user_avatar_url = people.medium_avatar_url_for_person(user);
|
2019-11-02 00:06:25 +01:00
|
|
|
const sender_avatar_medium = new Image();
|
2020-04-07 20:09:30 +02:00
|
|
|
|
2017-09-28 01:52:25 +02:00
|
|
|
sender_avatar_medium.src = user_avatar_url;
|
2017-07-26 20:03:38 +02:00
|
|
|
$(sender_avatar_medium).on("load", function () {
|
2022-01-25 11:36:19 +01:00
|
|
|
$elt.css("background-image", "url(" + $(this).attr("src") + ")");
|
2017-03-04 13:43:21 +01:00
|
|
|
});
|
|
|
|
}
|
2017-03-05 04:46:37 +01:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
function calculate_info_popover_placement(size, $elt) {
|
|
|
|
const ypos = $elt.offset().top;
|
2018-05-06 21:43:17 +02:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
if (!(ypos + size / 2 < message_viewport.height() && ypos > size / 2)) {
|
2018-06-06 18:50:09 +02:00
|
|
|
if (ypos + size < message_viewport.height()) {
|
2020-07-15 01:29:15 +02:00
|
|
|
return "bottom";
|
2018-05-06 21:43:17 +02:00
|
|
|
} else if (ypos > size) {
|
2020-07-15 01:29:15 +02:00
|
|
|
return "top";
|
2018-05-06 21:43:17 +02:00
|
|
|
}
|
|
|
|
}
|
2020-09-24 07:50:36 +02:00
|
|
|
|
|
|
|
return undefined;
|
2018-02-14 05:21:46 +01:00
|
|
|
}
|
|
|
|
|
2022-10-03 13:29:59 +02:00
|
|
|
export function hide_user_info_popover_manage_menu() {
|
|
|
|
if ($current_user_info_popover_manage_menu !== undefined) {
|
|
|
|
$current_user_info_popover_manage_menu.popover("destroy");
|
|
|
|
$current_user_info_popover_manage_menu = undefined;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function show_user_info_popover_manage_menu(element, user) {
|
|
|
|
const $last_popover_elem = $current_user_info_popover_manage_menu;
|
|
|
|
hide_user_info_popover_manage_menu();
|
|
|
|
if ($last_popover_elem !== undefined && $last_popover_elem.get()[0] === element) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const is_me = people.is_my_user_id(user.user_id);
|
|
|
|
const is_muted = muted_users.is_user_muted(user.user_id);
|
|
|
|
const is_system_bot = user.is_system_bot;
|
|
|
|
const muting_allowed = !is_me && !user.is_bot;
|
|
|
|
|
|
|
|
const args = {
|
|
|
|
can_mute: muting_allowed && !is_muted,
|
|
|
|
can_manage_user: page_params.is_admin && !is_me && !is_system_bot,
|
|
|
|
can_unmute: muting_allowed && is_muted,
|
|
|
|
is_active: people.is_active_user_for_popover(user.user_id),
|
|
|
|
is_bot: user.is_bot,
|
|
|
|
user_id: user.user_id,
|
|
|
|
};
|
|
|
|
|
|
|
|
const $popover_elt = $(element);
|
|
|
|
$popover_elt.popover({
|
|
|
|
content: render_user_info_popover_manage_menu(args),
|
|
|
|
placement: "bottom",
|
|
|
|
html: true,
|
|
|
|
trigger: "manual",
|
|
|
|
});
|
|
|
|
|
|
|
|
$popover_elt.popover("show");
|
|
|
|
$current_user_info_popover_manage_menu = $popover_elt;
|
|
|
|
}
|
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
function render_user_info_popover(
|
|
|
|
user,
|
|
|
|
popover_element,
|
|
|
|
is_sender_popover,
|
2020-06-27 21:33:09 +02:00
|
|
|
has_message_context,
|
2020-07-15 00:34:28 +02:00
|
|
|
private_msg_class,
|
|
|
|
template_class,
|
|
|
|
popover_placement,
|
|
|
|
) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const is_me = people.is_my_user_id(user.user_id);
|
2018-12-20 15:22:30 +01:00
|
|
|
|
2022-09-21 15:49:36 +02:00
|
|
|
let invisible_mode = false;
|
2018-12-20 15:22:30 +01:00
|
|
|
|
|
|
|
if (is_me) {
|
2022-09-21 15:49:36 +02:00
|
|
|
invisible_mode = !user_settings.presence_enabled;
|
2018-12-20 15:22:30 +01:00
|
|
|
}
|
|
|
|
|
2021-05-08 16:07:29 +02:00
|
|
|
const muting_allowed = !is_me && !user.is_bot;
|
2022-04-22 20:32:41 +02:00
|
|
|
const is_active = people.is_active_user_for_popover(user.user_id);
|
2022-09-28 13:23:28 +02:00
|
|
|
const is_system_bot = user.is_system_bot;
|
2021-06-29 17:21:30 +02:00
|
|
|
const status_text = user_status.get_status_text(user.user_id);
|
|
|
|
const status_emoji_info = user_status.get_status_emoji(user.user_id);
|
2022-10-13 13:38:08 +02:00
|
|
|
const spectator_view = page_params.is_spectator;
|
2021-03-27 13:14:34 +01:00
|
|
|
|
2022-10-03 13:29:59 +02:00
|
|
|
// TODO: The show_manage_menu calculation can get a lot simpler
|
|
|
|
// if/when we allow muting bot users.
|
|
|
|
const can_manage_user = page_params.is_admin && !is_me && !is_system_bot;
|
2022-10-13 13:38:08 +02:00
|
|
|
const show_manage_menu = !spectator_view && (muting_allowed || can_manage_user);
|
2022-10-03 13:29:59 +02:00
|
|
|
|
2021-11-02 08:36:31 +01:00
|
|
|
let date_joined;
|
|
|
|
if (spectator_view) {
|
|
|
|
const dateFormat = new Intl.DateTimeFormat("default", {dateStyle: "long"});
|
|
|
|
date_joined = dateFormat.format(parseISO(user.date_joined));
|
|
|
|
}
|
2022-07-12 21:25:02 +02:00
|
|
|
// Filtering out only those profile fields that can be display in the popover and are not empty.
|
|
|
|
const dateFormat = new Intl.DateTimeFormat("default", {dateStyle: "long"});
|
|
|
|
const field_types = page_params.custom_profile_field_types;
|
|
|
|
const display_profile_fields = page_params.custom_profile_fields
|
|
|
|
.map((f) => user_profile.get_custom_profile_field_data(user, f, field_types, dateFormat))
|
|
|
|
.filter((f) => f.display_in_profile_summary && f.value !== undefined && f.value !== null);
|
2021-11-02 08:36:31 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const args = {
|
2022-09-21 15:49:36 +02:00
|
|
|
invisible_mode,
|
2022-04-22 20:32:41 +02:00
|
|
|
can_send_private_message:
|
|
|
|
is_active &&
|
|
|
|
!is_me &&
|
|
|
|
page_params.realm_private_message_policy !==
|
|
|
|
settings_config.private_message_policy_values.disabled.code,
|
2022-07-12 21:25:02 +02:00
|
|
|
display_profile_fields,
|
2020-06-27 21:33:09 +02:00
|
|
|
has_message_context,
|
2022-04-22 20:32:41 +02:00
|
|
|
is_active,
|
2018-11-02 19:13:22 +01:00
|
|
|
is_bot: user.is_bot,
|
2020-07-20 22:18:43 +02:00
|
|
|
is_me,
|
|
|
|
is_sender_popover,
|
2022-03-01 19:14:26 +01:00
|
|
|
pm_with_url: hash_util.pm_with_url(user.email),
|
2019-02-17 02:10:42 +01:00
|
|
|
user_circle_class: buddy_data.get_user_circle_class(user.user_id),
|
2018-11-02 19:13:22 +01:00
|
|
|
private_message_class: private_msg_class,
|
2022-03-01 19:14:26 +01:00
|
|
|
sent_by_uri: hash_util.by_sender_url(user.email),
|
2020-02-25 12:46:14 +01:00
|
|
|
show_email: settings_data.show_email(),
|
2022-10-03 13:29:59 +02:00
|
|
|
show_manage_menu,
|
2020-04-06 20:14:36 +02:00
|
|
|
user_email: people.get_visible_email(user),
|
2018-11-02 19:13:22 +01:00
|
|
|
user_full_name: user.full_name,
|
|
|
|
user_id: user.user_id,
|
2019-02-28 16:09:03 +01:00
|
|
|
user_last_seen_time_status: buddy_data.user_last_seen_time_status(user.user_id),
|
2018-11-02 19:13:22 +01:00
|
|
|
user_time: people.get_user_time(user.user_id),
|
2018-11-02 19:45:32 +01:00
|
|
|
user_type: people.get_user_type(user.user_id),
|
2021-06-29 17:21:30 +02:00
|
|
|
status_content_available: Boolean(status_text || status_emoji_info),
|
|
|
|
status_text,
|
|
|
|
status_emoji_info,
|
2020-06-27 21:33:09 +02:00
|
|
|
user_mention_syntax: people.get_mention_syntax(user.full_name, user.user_id),
|
2021-11-02 08:36:31 +01:00
|
|
|
date_joined,
|
|
|
|
spectator_view,
|
2018-11-02 19:13:22 +01:00
|
|
|
};
|
|
|
|
|
2019-05-29 05:59:53 +02:00
|
|
|
if (user.is_bot) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const bot_owner_id = user.bot_owner_id;
|
2021-03-07 15:51:55 +01:00
|
|
|
if (is_system_bot) {
|
|
|
|
args.is_system_bot = is_system_bot;
|
2019-05-29 05:59:53 +02:00
|
|
|
} else if (bot_owner_id) {
|
2020-02-05 14:30:59 +01:00
|
|
|
const bot_owner = people.get_by_user_id(bot_owner_id);
|
2019-05-29 05:59:53 +02:00
|
|
|
args.bot_owner = bot_owner;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-03 13:29:59 +02:00
|
|
|
const $popover_content = $(render_user_info_popover_content(args));
|
2018-11-02 19:13:22 +01:00
|
|
|
popover_element.popover({
|
2022-10-03 13:29:59 +02:00
|
|
|
content: $popover_content.get(0),
|
2018-11-02 19:13:22 +01:00
|
|
|
// TODO: Determine whether `fixed` should be applied
|
|
|
|
// unconditionally. Right now, we only do it for the user
|
|
|
|
// sidebar version of the popover.
|
2020-07-15 01:29:15 +02:00
|
|
|
fixed: template_class === "user_popover",
|
2018-11-02 19:13:22 +01:00
|
|
|
placement: popover_placement,
|
2019-07-09 21:24:00 +02:00
|
|
|
template: render_no_arrow_popover({class: template_class}),
|
|
|
|
title: render_user_info_popover_title({
|
2021-11-02 08:41:52 +01:00
|
|
|
// See the load_medium_avatar comment for important background.
|
|
|
|
user_avatar: people.small_avatar_url_for_person(user),
|
2019-07-09 21:24:00 +02:00
|
|
|
user_is_guest: user.is_guest,
|
|
|
|
}),
|
2019-09-17 23:54:52 +02:00
|
|
|
html: true,
|
2018-11-02 19:13:22 +01:00
|
|
|
trigger: "manual",
|
2020-08-26 10:15:02 +02:00
|
|
|
top_offset: $("#userlist-title").offset().top + 15,
|
2019-02-14 16:54:39 +01:00
|
|
|
fix_positions: true,
|
2018-11-02 19:13:22 +01:00
|
|
|
});
|
|
|
|
popover_element.popover("show");
|
|
|
|
|
|
|
|
init_email_clipboard();
|
2021-07-09 09:02:58 +02:00
|
|
|
init_email_tooltip(user);
|
2022-10-03 13:29:59 +02:00
|
|
|
const $user_name_element = $popover_content.find(".user_full_name");
|
2022-10-19 13:03:10 +02:00
|
|
|
const $bot_owner_element = $popover_content.find(".bot_owner");
|
2022-10-03 13:29:59 +02:00
|
|
|
if ($user_name_element.prop("clientWidth") < $user_name_element.prop("scrollWidth")) {
|
|
|
|
$user_name_element.addClass("tippy-zulip-tooltip");
|
|
|
|
}
|
2022-10-19 13:03:10 +02:00
|
|
|
if (
|
|
|
|
args.bot_owner &&
|
|
|
|
$bot_owner_element.prop("clientWidth") < $bot_owner_element.prop("scrollWidth")
|
|
|
|
) {
|
|
|
|
$bot_owner_element.addClass("tippy-zulip-tooltip");
|
|
|
|
}
|
2021-07-09 09:02:58 +02:00
|
|
|
|
2021-11-02 08:41:52 +01:00
|
|
|
// Note: We pass the normal-size avatar in initial rendering, and
|
|
|
|
// then query the server to replace it with the medium-size
|
|
|
|
// avatar. The purpose of this double-fetch approach is to take
|
|
|
|
// advantage of the fact that the browser should already have the
|
|
|
|
// low-resolution image cached and thus display a low-resolution
|
|
|
|
// avatar rather than a blank area during the network delay for
|
|
|
|
// fetching the medium-size one.
|
2018-11-02 19:13:22 +01:00
|
|
|
load_medium_avatar(user, $(".popover-avatar"));
|
|
|
|
}
|
|
|
|
|
2018-02-14 05:21:46 +01:00
|
|
|
// exporting for testability
|
2021-02-28 01:03:09 +01:00
|
|
|
export const _test_calculate_info_popover_placement = calculate_info_popover_placement;
|
2018-02-14 05:21:46 +01:00
|
|
|
|
2017-09-30 17:25:49 +02:00
|
|
|
// element is the target element to pop off of
|
|
|
|
// user is the user whose profile to show
|
|
|
|
// message is the message containing it, which should be selected
|
2020-06-25 14:18:37 +02:00
|
|
|
function show_user_info_popover_for_message(element, user, message) {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $last_popover_elem = $current_message_info_popover_elem;
|
2021-02-28 01:03:09 +01:00
|
|
|
hide_all();
|
2022-01-25 11:36:19 +01:00
|
|
|
if ($last_popover_elem !== undefined && $last_popover_elem.get()[0] === element) {
|
2013-06-28 22:38:40 +02:00
|
|
|
// We want it to be the case that a user can dismiss a popover
|
|
|
|
// by clicking on the same element that caused the popover.
|
|
|
|
return;
|
|
|
|
}
|
2021-03-30 02:21:21 +02:00
|
|
|
message_lists.current.select_id(message.id);
|
2022-01-25 11:36:19 +01:00
|
|
|
const $elt = $(element);
|
|
|
|
if ($elt.data("popover") === undefined) {
|
2017-09-30 17:31:49 +02:00
|
|
|
if (user === undefined) {
|
2017-11-06 15:32:31 +01:00
|
|
|
// This is never supposed to happen, not even for deactivated
|
|
|
|
// users, so we'll need to debug this error if it occurs.
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.error("Bad sender in message" + message.sender_id);
|
2017-09-30 17:31:49 +02:00
|
|
|
return;
|
2017-02-07 02:54:01 +01:00
|
|
|
}
|
|
|
|
|
2020-07-16 23:29:01 +02:00
|
|
|
const is_sender_popover = message.sender_id === user.user_id;
|
2020-07-15 00:34:28 +02:00
|
|
|
render_user_info_popover(
|
|
|
|
user,
|
2022-01-25 11:36:19 +01:00
|
|
|
$elt,
|
2020-07-15 00:34:28 +02:00
|
|
|
is_sender_popover,
|
2020-06-27 21:33:09 +02:00
|
|
|
true,
|
2020-07-15 00:34:28 +02:00
|
|
|
"respond_personal_button",
|
|
|
|
"message-info-popover",
|
|
|
|
"right",
|
|
|
|
);
|
2017-03-03 21:57:06 +01:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
$current_message_info_popover_elem = $elt;
|
2013-07-11 23:06:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-28 01:03:09 +01:00
|
|
|
export function show_user_info_popover(element, user) {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $last_popover_elem = $current_user_info_popover_elem;
|
2021-02-28 01:03:09 +01:00
|
|
|
hide_all();
|
2022-01-25 11:36:19 +01:00
|
|
|
if ($last_popover_elem !== undefined && $last_popover_elem.get()[0] === element) {
|
2020-06-25 21:35:01 +02:00
|
|
|
return;
|
|
|
|
}
|
2022-01-25 11:36:19 +01:00
|
|
|
const $elt = $(element);
|
2020-06-25 21:35:01 +02:00
|
|
|
render_user_info_popover(
|
|
|
|
user,
|
2022-01-25 11:36:19 +01:00
|
|
|
$elt,
|
2020-06-25 21:35:01 +02:00
|
|
|
false,
|
|
|
|
false,
|
|
|
|
"compose_private_message",
|
|
|
|
"user-info-popover",
|
|
|
|
"right",
|
|
|
|
);
|
2022-01-25 11:36:19 +01:00
|
|
|
$current_user_info_popover_elem = $elt;
|
2021-02-28 01:03:09 +01:00
|
|
|
}
|
2020-06-25 21:35:01 +02:00
|
|
|
|
2020-09-19 18:31:41 +02:00
|
|
|
function get_user_info_popover_for_message_items() {
|
2022-01-25 11:36:19 +01:00
|
|
|
if (!$current_message_info_popover_elem) {
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.error("Trying to get menu items when action popover is closed.");
|
2020-09-24 07:50:36 +02:00
|
|
|
return undefined;
|
2018-06-12 11:32:42 +02:00
|
|
|
}
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
const popover_data = $current_message_info_popover_elem.data("popover");
|
2018-06-12 11:32:42 +02:00
|
|
|
if (!popover_data) {
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.error("Cannot find popover data for actions menu.");
|
2020-09-24 07:50:36 +02:00
|
|
|
return undefined;
|
2018-06-12 11:32:42 +02:00
|
|
|
}
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
return $("li:not(.divider):visible a", popover_data.$tip);
|
2018-06-12 11:32:42 +02:00
|
|
|
}
|
|
|
|
|
2020-09-22 19:19:40 +02:00
|
|
|
function get_user_info_popover_items() {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $popover_elt = $("div.user-info-popover");
|
|
|
|
if (!$current_user_info_popover_elem || !$popover_elt.length) {
|
2020-09-22 19:19:40 +02:00
|
|
|
blueslip.error("Trying to get menu items when action popover is closed.");
|
2020-09-24 07:50:36 +02:00
|
|
|
return undefined;
|
2020-09-22 19:19:40 +02:00
|
|
|
}
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
if ($popover_elt.length >= 2) {
|
2020-09-22 19:19:40 +02:00
|
|
|
blueslip.error("More than one user info popovers cannot be opened at same time.");
|
2020-09-24 07:50:36 +02:00
|
|
|
return undefined;
|
2020-09-22 19:19:40 +02:00
|
|
|
}
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
return $("li:not(.divider):visible a", $popover_elt);
|
2020-09-22 19:19:40 +02:00
|
|
|
}
|
|
|
|
|
2022-10-03 13:29:59 +02:00
|
|
|
function get_user_info_popover_manage_menu_items() {
|
|
|
|
if (!$current_user_info_popover_manage_menu) {
|
|
|
|
blueslip.error("Trying to get menu items when action popover is closed.");
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
const popover_data = $current_user_info_popover_manage_menu.data("popover");
|
|
|
|
if (!popover_data) {
|
|
|
|
blueslip.error("Cannot find popover data for actions menu.");
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $(".user_info_popover_manage_menu li:not(.divider):visible a", popover_data.$tip);
|
|
|
|
}
|
|
|
|
|
2018-02-14 05:21:46 +01:00
|
|
|
function fetch_group_members(member_ids) {
|
|
|
|
return member_ids
|
2020-07-02 01:45:54 +02:00
|
|
|
.map((m) => people.get_by_user_id(m))
|
|
|
|
.filter((m) => m !== undefined)
|
2020-12-22 00:37:36 +01:00
|
|
|
.map((p) => ({
|
|
|
|
...p,
|
|
|
|
user_circle_class: buddy_data.get_user_circle_class(p.user_id),
|
|
|
|
is_active: people.is_active_user_for_popover(p.user_id),
|
|
|
|
user_last_seen_time_status: buddy_data.user_last_seen_time_status(p.user_id),
|
|
|
|
}));
|
2018-02-14 05:21:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function sort_group_members(members) {
|
2021-06-12 11:31:36 +02:00
|
|
|
return members.sort((a, b) => util.strcmp(a.full_name, b.fullname));
|
2018-02-14 05:21:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// exporting these functions for testing purposes
|
2021-02-28 01:03:09 +01:00
|
|
|
export const _test_fetch_group_members = fetch_group_members;
|
|
|
|
|
|
|
|
export const _test_sort_group_members = sort_group_members;
|
2018-02-14 05:21:46 +01:00
|
|
|
|
|
|
|
// element is the target element to pop off of
|
|
|
|
// user is the user whose profile to show
|
|
|
|
// message is the message containing it, which should be selected
|
|
|
|
function show_user_group_info_popover(element, group, message) {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $last_popover_elem = $current_message_info_popover_elem;
|
2018-02-14 05:21:46 +01:00
|
|
|
// hardcoded pixel height of the popover
|
|
|
|
// note that the actual size varies (in group size), but this is about as big as it gets
|
2019-11-02 00:06:25 +01:00
|
|
|
const popover_size = 390;
|
2021-02-28 01:03:09 +01:00
|
|
|
hide_all();
|
2022-01-25 11:36:19 +01:00
|
|
|
if ($last_popover_elem !== undefined && $last_popover_elem.get()[0] === element) {
|
2018-02-14 05:21:46 +01:00
|
|
|
// We want it to be the case that a user can dismiss a popover
|
|
|
|
// by clicking on the same element that caused the popover.
|
|
|
|
return;
|
|
|
|
}
|
2021-03-30 02:21:21 +02:00
|
|
|
message_lists.current.select_id(message.id);
|
2022-01-25 11:36:19 +01:00
|
|
|
const $elt = $(element);
|
|
|
|
if ($elt.data("popover") === undefined) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const args = {
|
2018-02-14 05:21:46 +01:00
|
|
|
group_name: group.name,
|
|
|
|
group_description: group.description,
|
2020-02-04 23:46:56 +01:00
|
|
|
members: sort_group_members(fetch_group_members(Array.from(group.members))),
|
2018-02-14 05:21:46 +01:00
|
|
|
};
|
2022-01-25 11:36:19 +01:00
|
|
|
$elt.popover({
|
|
|
|
placement: calculate_info_popover_placement(popover_size, $elt),
|
2019-07-09 21:24:00 +02:00
|
|
|
template: render_user_group_info_popover({class: "message-info-popover"}),
|
|
|
|
content: render_user_group_info_popover_content(args),
|
2019-09-17 23:54:52 +02:00
|
|
|
html: true,
|
2018-02-14 05:21:46 +01:00
|
|
|
trigger: "manual",
|
|
|
|
});
|
2022-01-25 11:36:19 +01:00
|
|
|
$elt.popover("show");
|
|
|
|
$current_message_info_popover_elem = $elt;
|
2018-02-14 05:21:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-28 01:03:09 +01:00
|
|
|
export function toggle_actions_popover(element, id) {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $last_popover_elem = $current_actions_popover_elem;
|
2021-02-28 01:03:09 +01:00
|
|
|
hide_all();
|
2022-01-25 11:36:19 +01:00
|
|
|
if ($last_popover_elem !== undefined && $last_popover_elem.get()[0] === element) {
|
2013-07-11 23:06:58 +02:00
|
|
|
// We want it to be the case that a user can dismiss a popover
|
|
|
|
// by clicking on the same element that caused the popover.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$(element).closest(".message_row").toggleClass("has_popover has_actions_popover");
|
2021-03-30 02:21:21 +02:00
|
|
|
message_lists.current.select_id(id);
|
2022-01-25 11:36:19 +01:00
|
|
|
const $elt = $(element);
|
|
|
|
if ($elt.data("popover") === undefined) {
|
2022-11-24 09:01:49 +01:00
|
|
|
const args = popover_menus_data.get_actions_popover_content_context(id);
|
2013-07-11 23:06:58 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
const ypos = $elt.offset().top;
|
|
|
|
$elt.popover({
|
2017-03-13 17:17:47 +01:00
|
|
|
// Popover height with 7 items in it is ~190 px
|
2020-07-15 01:29:15 +02:00
|
|
|
placement: message_viewport.height() - ypos < 220 ? "top" : "bottom",
|
2018-12-18 19:34:45 +01:00
|
|
|
title: "",
|
2019-07-09 21:24:00 +02:00
|
|
|
content: render_actions_popover_content(args),
|
2022-10-05 12:41:38 +02:00
|
|
|
template: render_actions_popover_template(),
|
2019-09-17 23:54:52 +02:00
|
|
|
html: true,
|
2018-12-18 19:34:45 +01:00
|
|
|
trigger: "manual",
|
2013-06-28 22:38:40 +02:00
|
|
|
});
|
2022-01-25 11:36:19 +01:00
|
|
|
$elt.popover("show");
|
|
|
|
$current_actions_popover_elem = $elt;
|
2013-06-28 22:38:40 +02:00
|
|
|
}
|
2022-10-05 12:41:38 +02:00
|
|
|
|
|
|
|
if (window.innerWidth < media_breakpoints_num.xl) {
|
|
|
|
// This ensures that the popover doesn't overflow to the right of the window.
|
|
|
|
const actions_popover_left = window.innerWidth - $(".actions_popover_wrapper").outerWidth();
|
|
|
|
$(".actions_popover_wrapper").css("left", actions_popover_left);
|
|
|
|
}
|
2021-02-28 01:03:09 +01:00
|
|
|
}
|
2013-07-11 23:06:58 +02:00
|
|
|
|
2013-11-07 18:12:48 +01:00
|
|
|
function get_action_menu_menu_items() {
|
2022-01-25 11:36:19 +01:00
|
|
|
if (!$current_actions_popover_elem) {
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.error("Trying to get menu items when action popover is closed.");
|
2020-09-24 07:50:36 +02:00
|
|
|
return undefined;
|
2017-05-12 18:40:29 +02:00
|
|
|
}
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
const popover_data = $current_actions_popover_elem.data("popover");
|
2017-05-12 18:40:29 +02:00
|
|
|
if (!popover_data) {
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.error("Cannot find popover data for actions menu.");
|
2020-09-24 07:50:36 +02:00
|
|
|
return undefined;
|
2017-05-12 18:40:29 +02:00
|
|
|
}
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
return $("li:not(.divider):visible a", popover_data.$tip);
|
2013-11-07 18:12:48 +01:00
|
|
|
}
|
|
|
|
|
2022-10-03 13:29:59 +02:00
|
|
|
export function focus_first_popover_item($items, index = 0) {
|
2022-01-25 11:36:19 +01:00
|
|
|
if (!$items) {
|
2017-05-12 18:40:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-10-03 13:29:59 +02:00
|
|
|
$items.eq(index).expectOne().trigger("focus");
|
2021-02-28 01:03:09 +01:00
|
|
|
}
|
2013-11-07 18:12:48 +01:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
export function popover_items_handle_keyboard(key, $items) {
|
|
|
|
if (!$items) {
|
2018-06-12 11:20:39 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
let index = $items.index($items.filter(":focus"));
|
2018-06-12 11:20:39 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
if (key === "enter" && index >= 0 && index < $items.length) {
|
|
|
|
$items[index].click();
|
2022-10-03 13:29:59 +02:00
|
|
|
if ($current_user_info_popover_manage_menu) {
|
|
|
|
const $items = get_user_info_popover_manage_menu_items();
|
|
|
|
focus_first_popover_item($items);
|
|
|
|
}
|
2020-09-24 07:50:36 +02:00
|
|
|
return;
|
2018-06-12 11:20:39 +02:00
|
|
|
}
|
|
|
|
if (index === -1) {
|
2022-10-03 13:29:59 +02:00
|
|
|
if ($(".user_info_popover_manage_menu_btn").is(":visible")) {
|
|
|
|
index = 1;
|
|
|
|
} else {
|
|
|
|
index = 0;
|
|
|
|
}
|
2022-01-25 11:36:19 +01:00
|
|
|
} else if ((key === "down_arrow" || key === "vim_down") && index < $items.length - 1) {
|
2018-06-12 11:20:39 +02:00
|
|
|
index += 1;
|
2020-07-15 01:29:15 +02:00
|
|
|
} else if ((key === "up_arrow" || key === "vim_up") && index > 0) {
|
2018-06-12 11:20:39 +02:00
|
|
|
index -= 1;
|
|
|
|
}
|
2022-01-25 11:36:19 +01:00
|
|
|
$items.eq(index).trigger("focus");
|
2021-02-28 01:03:09 +01:00
|
|
|
}
|
2018-06-12 11:20:39 +02:00
|
|
|
|
|
|
|
function focus_first_action_popover_item() {
|
|
|
|
// For now I recommend only calling this when the user opens the menu with a hotkey.
|
|
|
|
// Our popup menus act kind of funny when you mix keyboard and mouse.
|
2022-01-25 11:36:19 +01:00
|
|
|
const $items = get_action_menu_menu_items();
|
|
|
|
focus_first_popover_item($items);
|
2018-06-12 11:20:39 +02:00
|
|
|
}
|
|
|
|
|
2021-02-28 01:03:09 +01:00
|
|
|
export function open_message_menu(message) {
|
2017-12-16 15:42:26 +01:00
|
|
|
if (message.locally_echoed) {
|
|
|
|
// Don't open the popup for locally echoed messages for now.
|
|
|
|
// It creates bugs with things like keyboard handlers when
|
|
|
|
// we get the server response.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-01-16 22:27:27 +01:00
|
|
|
const message_id = message.id;
|
2021-02-28 01:03:09 +01:00
|
|
|
toggle_actions_popover($(".selected_message .actions_hover")[0], message_id);
|
2022-01-25 11:36:19 +01:00
|
|
|
if ($current_actions_popover_elem) {
|
2013-11-08 18:28:22 +01:00
|
|
|
focus_first_action_popover_item();
|
|
|
|
}
|
2013-11-07 18:12:48 +01:00
|
|
|
return true;
|
2021-02-28 01:03:09 +01:00
|
|
|
}
|
2013-11-07 18:12:48 +01:00
|
|
|
|
2021-02-28 01:03:09 +01:00
|
|
|
export function actions_menu_handle_keyboard(key) {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $items = get_action_menu_menu_items();
|
|
|
|
popover_items_handle_keyboard(key, $items);
|
2021-02-28 01:03:09 +01:00
|
|
|
}
|
2013-06-28 22:38:40 +02:00
|
|
|
|
2021-02-28 01:03:09 +01:00
|
|
|
export function actions_popped() {
|
2022-01-25 11:36:19 +01:00
|
|
|
return $current_actions_popover_elem !== undefined;
|
2021-02-28 01:03:09 +01:00
|
|
|
}
|
2013-06-28 22:38:40 +02:00
|
|
|
|
2021-02-28 01:03:09 +01:00
|
|
|
export function hide_actions_popover() {
|
|
|
|
if (actions_popped()) {
|
2020-07-15 01:29:15 +02:00
|
|
|
$(".has_popover").removeClass("has_popover has_actions_popover");
|
2022-01-25 11:36:19 +01:00
|
|
|
$current_actions_popover_elem.popover("destroy");
|
|
|
|
$current_actions_popover_elem = undefined;
|
2013-06-28 22:38:40 +02:00
|
|
|
}
|
2018-01-15 03:02:23 +01:00
|
|
|
if (current_flatpickr_instance !== undefined) {
|
|
|
|
current_flatpickr_instance.destroy();
|
|
|
|
current_flatpickr_instance = undefined;
|
|
|
|
}
|
2021-02-28 01:03:09 +01:00
|
|
|
}
|
2013-06-28 22:38:40 +02:00
|
|
|
|
2021-02-28 01:03:09 +01:00
|
|
|
export function message_info_popped() {
|
2022-01-25 11:36:19 +01:00
|
|
|
return $current_message_info_popover_elem !== undefined;
|
2021-02-28 01:03:09 +01:00
|
|
|
}
|
2013-07-11 23:06:58 +02:00
|
|
|
|
2021-02-28 01:03:09 +01:00
|
|
|
export function hide_message_info_popover() {
|
|
|
|
if (message_info_popped()) {
|
2022-01-25 11:36:19 +01:00
|
|
|
$current_message_info_popover_elem.popover("destroy");
|
|
|
|
$current_message_info_popover_elem = undefined;
|
2013-07-11 23:06:58 +02:00
|
|
|
}
|
2021-02-28 01:03:09 +01:00
|
|
|
}
|
2013-07-11 23:06:58 +02:00
|
|
|
|
2021-02-28 01:03:09 +01:00
|
|
|
export function user_info_popped() {
|
2022-01-25 11:36:19 +01:00
|
|
|
return $current_user_info_popover_elem !== undefined;
|
2021-02-28 01:03:09 +01:00
|
|
|
}
|
2020-06-25 21:35:01 +02:00
|
|
|
|
2022-10-03 13:29:59 +02:00
|
|
|
export function user_info_manage_menu_popped() {
|
|
|
|
return $current_user_info_popover_manage_menu !== undefined;
|
|
|
|
}
|
|
|
|
|
2021-02-28 01:03:09 +01:00
|
|
|
export function hide_user_info_popover() {
|
|
|
|
if (user_info_popped()) {
|
2022-01-25 11:36:19 +01:00
|
|
|
$current_user_info_popover_elem.popover("destroy");
|
|
|
|
$current_user_info_popover_elem = undefined;
|
2020-06-25 21:35:01 +02:00
|
|
|
}
|
2021-02-28 01:03:09 +01:00
|
|
|
}
|
2020-06-25 21:35:01 +02:00
|
|
|
|
2021-02-28 01:03:09 +01:00
|
|
|
export function hide_userlist_sidebar() {
|
2013-08-22 20:17:07 +02:00
|
|
|
$(".app-main .column-right").removeClass("expanded");
|
2021-02-28 01:03:09 +01:00
|
|
|
}
|
2013-07-11 23:06:58 +02:00
|
|
|
|
2021-02-28 01:03:09 +01:00
|
|
|
export function hide_pm_list_sidebar() {
|
2015-11-25 18:41:32 +01:00
|
|
|
$(".app-main .column-left").removeClass("expanded");
|
2021-02-28 01:03:09 +01:00
|
|
|
}
|
2015-11-25 18:41:32 +01:00
|
|
|
|
2021-02-28 01:03:09 +01:00
|
|
|
export function show_userlist_sidebar() {
|
2013-08-23 21:33:43 +02:00
|
|
|
$(".app-main .column-right").addClass("expanded");
|
2014-03-13 19:03:31 +01:00
|
|
|
resize.resize_page_components();
|
2021-02-28 01:03:09 +01:00
|
|
|
}
|
2013-08-23 21:33:43 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let current_user_sidebar_user_id;
|
|
|
|
let current_user_sidebar_popover;
|
2013-06-28 22:38:40 +02:00
|
|
|
|
2021-02-28 01:03:09 +01:00
|
|
|
export function user_sidebar_popped() {
|
|
|
|
return current_user_sidebar_popover !== undefined;
|
|
|
|
}
|
2013-06-28 22:38:40 +02:00
|
|
|
|
2021-02-28 01:03:09 +01:00
|
|
|
export function hide_user_sidebar_popover() {
|
|
|
|
if (user_sidebar_popped()) {
|
2013-12-04 03:30:27 +01:00
|
|
|
// this hide_* method looks different from all the others since
|
2022-02-08 00:13:33 +01:00
|
|
|
// the presence list may be redrawn. Due to funkiness with jQuery's .data()
|
2013-12-04 03:30:27 +01:00
|
|
|
// this would confuse $.popover("destroy"), which looks at the .data() attached
|
2016-12-02 15:16:33 +01:00
|
|
|
// to a certain element. We thus save off the .data("popover") in the
|
|
|
|
// show_user_sidebar_popover and inject it here before calling destroy.
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#user_presences").data("popover", current_user_sidebar_popover);
|
|
|
|
$("#user_presences").popover("destroy");
|
2016-11-17 23:16:29 +01:00
|
|
|
current_user_sidebar_user_id = undefined;
|
2013-12-04 03:30:27 +01:00
|
|
|
current_user_sidebar_popover = undefined;
|
2013-06-28 22:38:40 +02:00
|
|
|
}
|
2021-02-28 01:03:09 +01:00
|
|
|
}
|
2013-06-28 22:38:40 +02:00
|
|
|
|
2022-04-14 21:13:59 +02:00
|
|
|
function hide_all_user_info_popovers() {
|
2022-10-03 13:29:59 +02:00
|
|
|
hide_user_info_popover_manage_menu();
|
2022-04-14 21:13:59 +02:00
|
|
|
hide_message_info_popover();
|
|
|
|
hide_user_sidebar_popover();
|
|
|
|
hide_user_info_popover();
|
|
|
|
}
|
|
|
|
|
2018-06-12 11:40:27 +02:00
|
|
|
function focus_user_info_popover_item() {
|
|
|
|
// For now I recommend only calling this when the user opens the menu with a hotkey.
|
|
|
|
// Our popup menus act kind of funny when you mix keyboard and mouse.
|
2022-01-25 11:36:19 +01:00
|
|
|
const $items = get_user_info_popover_for_message_items();
|
2022-10-03 13:29:59 +02:00
|
|
|
|
|
|
|
if ($(".user_info_popover_manage_menu_btn").is(":visible")) {
|
|
|
|
focus_first_popover_item($items, 1);
|
|
|
|
} else {
|
|
|
|
focus_first_popover_item($items);
|
|
|
|
}
|
2018-06-12 11:40:27 +02:00
|
|
|
}
|
|
|
|
|
2020-07-09 16:59:01 +02:00
|
|
|
function get_user_sidebar_popover_items() {
|
|
|
|
if (!current_user_sidebar_popover) {
|
|
|
|
blueslip.error("Trying to get menu items when user sidebar popover is closed.");
|
2020-09-24 07:50:36 +02:00
|
|
|
return undefined;
|
2020-07-09 16:59:01 +02:00
|
|
|
}
|
|
|
|
|
2022-10-03 13:29:59 +02:00
|
|
|
return $("li:not(.divider):visible a", current_user_sidebar_popover.$tip);
|
2020-07-09 16:59:01 +02:00
|
|
|
}
|
|
|
|
|
2021-02-28 01:03:09 +01:00
|
|
|
export function user_sidebar_popover_handle_keyboard(key) {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $items = get_user_sidebar_popover_items();
|
|
|
|
popover_items_handle_keyboard(key, $items);
|
2021-02-28 01:03:09 +01:00
|
|
|
}
|
2020-07-09 16:59:01 +02:00
|
|
|
|
2021-02-28 01:03:09 +01:00
|
|
|
export function user_info_popover_for_message_handle_keyboard(key) {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $items = get_user_info_popover_for_message_items();
|
|
|
|
popover_items_handle_keyboard(key, $items);
|
2021-02-28 01:03:09 +01:00
|
|
|
}
|
2018-06-12 12:29:34 +02:00
|
|
|
|
2021-02-28 01:03:09 +01:00
|
|
|
export function user_info_popover_handle_keyboard(key) {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $items = get_user_info_popover_items();
|
|
|
|
popover_items_handle_keyboard(key, $items);
|
2021-02-28 01:03:09 +01:00
|
|
|
}
|
2020-09-22 19:19:40 +02:00
|
|
|
|
2022-10-03 13:29:59 +02:00
|
|
|
export function user_info_popover_manage_menu_handle_keyboard(key) {
|
|
|
|
const $items = get_user_info_popover_manage_menu_items();
|
|
|
|
popover_items_handle_keyboard(key, $items);
|
|
|
|
}
|
|
|
|
|
2021-02-28 01:03:09 +01:00
|
|
|
export function show_sender_info() {
|
2019-11-02 00:06:25 +01:00
|
|
|
const $message = $(".selected_message");
|
2020-07-15 01:29:15 +02:00
|
|
|
const $sender = $message.find(".sender_info_hover");
|
2019-03-07 16:16:29 +01:00
|
|
|
|
2021-03-30 02:21:21 +02:00
|
|
|
const message = message_lists.current.get(rows.id($message));
|
2020-02-05 14:30:59 +01:00
|
|
|
const user = people.get_by_user_id(message.sender_id);
|
2020-06-25 14:18:37 +02:00
|
|
|
show_user_info_popover_for_message($sender[0], user, message);
|
2022-01-25 11:36:19 +01:00
|
|
|
if ($current_message_info_popover_elem && !page_params.is_spectator) {
|
2018-06-12 11:40:27 +02:00
|
|
|
focus_user_info_popover_item();
|
|
|
|
}
|
2021-02-28 01:03:09 +01:00
|
|
|
}
|
2017-05-23 20:01:24 +02:00
|
|
|
|
2019-03-15 04:02:27 +01:00
|
|
|
// On mobile web, opening the keyboard can trigger a resize event
|
|
|
|
// (which in turn can trigger a scroll event). This will have the
|
|
|
|
// side effect of closing popovers, which we don't want. So we
|
|
|
|
// suppress the first hide from scrolling after a resize using this
|
|
|
|
// variable.
|
2019-11-02 00:06:25 +01:00
|
|
|
let suppress_scroll_hide = false;
|
2019-03-15 04:02:27 +01:00
|
|
|
|
2021-02-28 01:03:09 +01:00
|
|
|
export function set_suppress_scroll_hide() {
|
2019-03-15 04:02:27 +01:00
|
|
|
suppress_scroll_hide = true;
|
2021-02-28 01:03:09 +01:00
|
|
|
}
|
2019-03-15 04:02:27 +01:00
|
|
|
|
2020-09-26 13:10:05 +02:00
|
|
|
// Playground_info contains all the data we need to generate a popover of
|
|
|
|
// playground links for each code block. The element is the target element
|
|
|
|
// to pop off of.
|
2021-02-28 01:03:09 +01:00
|
|
|
export function toggle_playground_link_popover(element, playground_info) {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $last_popover_elem = $current_playground_links_popover_elem;
|
2021-02-28 01:03:09 +01:00
|
|
|
hide_all();
|
2022-01-25 11:36:19 +01:00
|
|
|
if ($last_popover_elem !== undefined && $last_popover_elem.get()[0] === element) {
|
2020-09-26 13:10:05 +02:00
|
|
|
// We want it to be the case that a user can dismiss a popover
|
|
|
|
// by clicking on the same element that caused the popover.
|
|
|
|
return;
|
|
|
|
}
|
2022-01-25 11:36:19 +01:00
|
|
|
const $elt = $(element);
|
|
|
|
if ($elt.data("popover") === undefined) {
|
|
|
|
const ypos = $elt.offset().top;
|
|
|
|
$elt.popover({
|
2020-09-26 13:10:05 +02:00
|
|
|
// It's unlikely we'll have more than 3-4 playground links
|
|
|
|
// for one language, so it should be OK to hardcode 120 here.
|
|
|
|
placement: message_viewport.height() - ypos < 120 ? "top" : "bottom",
|
|
|
|
title: "",
|
|
|
|
content: render_playground_links_popover_content({playground_info}),
|
|
|
|
html: true,
|
|
|
|
trigger: "manual",
|
|
|
|
});
|
2022-01-25 11:36:19 +01:00
|
|
|
$elt.popover("show");
|
|
|
|
$current_playground_links_popover_elem = $elt;
|
2020-09-26 13:10:05 +02:00
|
|
|
}
|
2021-02-28 01:03:09 +01:00
|
|
|
}
|
2020-09-26 13:10:05 +02:00
|
|
|
|
2021-02-28 01:03:09 +01:00
|
|
|
export function hide_playground_links_popover() {
|
2022-01-25 11:36:19 +01:00
|
|
|
if ($current_playground_links_popover_elem !== undefined) {
|
|
|
|
$current_playground_links_popover_elem.popover("destroy");
|
|
|
|
$current_playground_links_popover_elem = undefined;
|
2020-09-26 13:10:05 +02:00
|
|
|
}
|
2021-02-28 01:03:09 +01:00
|
|
|
}
|
2020-09-26 13:10:05 +02:00
|
|
|
|
2021-02-28 01:03:09 +01:00
|
|
|
export function register_click_handlers() {
|
2013-06-28 22:38:40 +02:00
|
|
|
$("#main_div").on("click", ".actions_hover", function (e) {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $row = $(this).closest(".message_row");
|
2013-06-28 22:38:40 +02:00
|
|
|
e.stopPropagation();
|
2022-01-25 11:36:19 +01:00
|
|
|
toggle_actions_popover(this, rows.id($row));
|
2013-06-28 22:38:40 +02:00
|
|
|
});
|
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
$("#main_div").on(
|
|
|
|
"click",
|
|
|
|
".sender_name, .sender_name-in-status, .inline_profile_picture",
|
|
|
|
function (e) {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $row = $(this).closest(".message_row");
|
2020-07-15 00:34:28 +02:00
|
|
|
e.stopPropagation();
|
2022-01-25 11:36:19 +01:00
|
|
|
const message = message_lists.current.get(rows.id($row));
|
2020-07-15 00:34:28 +02:00
|
|
|
const user = people.get_by_user_id(message.sender_id);
|
2020-06-25 14:18:37 +02:00
|
|
|
show_user_info_popover_for_message(this, user, message);
|
2020-07-15 00:34:28 +02:00
|
|
|
},
|
|
|
|
);
|
2013-07-11 23:06:58 +02:00
|
|
|
|
2017-09-30 19:19:24 +02:00
|
|
|
$("#main_div").on("click", ".user-mention", function (e) {
|
2020-07-15 01:29:15 +02:00
|
|
|
const id_string = $(this).attr("data-user-id");
|
2020-08-11 01:47:49 +02:00
|
|
|
// We fallback to email to handle legacy Markdown that was rendered
|
2018-03-06 07:31:45 +01:00
|
|
|
// before we cut over to using data-user-id
|
2020-07-15 01:29:15 +02:00
|
|
|
const email = $(this).attr("data-user-email");
|
|
|
|
if (id_string === "*" || email === "*") {
|
2018-02-03 13:33:22 +01:00
|
|
|
return;
|
|
|
|
}
|
2022-01-25 11:36:19 +01:00
|
|
|
const $row = $(this).closest(".message_row");
|
2017-09-30 19:19:24 +02:00
|
|
|
e.stopPropagation();
|
2022-01-25 11:36:19 +01:00
|
|
|
const message = message_lists.current.get(rows.id($row));
|
2019-11-02 00:06:25 +01:00
|
|
|
let user;
|
2020-01-16 20:40:20 +01:00
|
|
|
if (id_string) {
|
2020-10-07 09:17:30 +02:00
|
|
|
const user_id = Number.parseInt(id_string, 10);
|
2020-02-05 14:30:59 +01:00
|
|
|
user = people.get_by_user_id(user_id);
|
2018-03-06 07:31:45 +01:00
|
|
|
} else {
|
|
|
|
user = people.get_by_email(email);
|
|
|
|
}
|
2020-06-25 14:18:37 +02:00
|
|
|
show_user_info_popover_for_message(this, user, message);
|
2017-09-30 19:19:24 +02:00
|
|
|
});
|
|
|
|
|
2018-02-14 05:21:46 +01:00
|
|
|
$("#main_div").on("click", ".user-group-mention", function (e) {
|
2020-10-07 09:17:30 +02:00
|
|
|
const user_group_id = Number.parseInt($(this).attr("data-user-group-id"), 10);
|
2022-01-25 11:36:19 +01:00
|
|
|
const $row = $(this).closest(".message_row");
|
2018-02-14 05:21:46 +01:00
|
|
|
e.stopPropagation();
|
2022-01-25 11:36:19 +01:00
|
|
|
const message = message_lists.current.get(rows.id($row));
|
2021-08-03 18:21:15 +02:00
|
|
|
try {
|
|
|
|
const group = user_groups.get_user_group_from_id(user_group_id);
|
|
|
|
show_user_group_info_popover(this, group, message);
|
|
|
|
} catch {
|
2019-02-15 23:50:28 +01:00
|
|
|
// This user group has likely been deleted.
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.info("Unable to find user group in message" + message.sender_id);
|
2018-02-14 05:21:46 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-02-22 10:35:06 +01:00
|
|
|
$("#main_div, #preview_content, #message-history").on(
|
|
|
|
"click",
|
|
|
|
".code_external_link",
|
|
|
|
function (e) {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $view_in_playground_button = $(this);
|
|
|
|
const $codehilite_div = $(this).closest(".codehilite");
|
2022-02-22 10:35:06 +01:00
|
|
|
e.stopPropagation();
|
|
|
|
const playground_info = realm_playground.get_playground_info_for_languages(
|
2022-01-25 11:36:19 +01:00
|
|
|
$codehilite_div.data("code-language"),
|
2022-02-22 10:35:06 +01:00
|
|
|
);
|
|
|
|
// We do the code extraction here and set the target href combining the url_prefix
|
|
|
|
// and the extracted code. Depending on whether the language has multiple playground
|
|
|
|
// links configured, a popover is show.
|
2022-01-25 11:36:19 +01:00
|
|
|
const extracted_code = $codehilite_div.find("code").text();
|
2022-02-22 10:35:06 +01:00
|
|
|
if (playground_info.length === 1) {
|
|
|
|
const url_prefix = playground_info[0].url_prefix;
|
2022-01-25 11:36:19 +01:00
|
|
|
$view_in_playground_button.attr(
|
2022-02-22 10:35:06 +01:00
|
|
|
"href",
|
|
|
|
url_prefix + encodeURIComponent(extracted_code),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
for (const $playground of playground_info) {
|
|
|
|
$playground.playground_url =
|
|
|
|
$playground.url_prefix + encodeURIComponent(extracted_code);
|
|
|
|
}
|
|
|
|
toggle_playground_link_popover(this, playground_info);
|
2021-01-22 22:29:08 +01:00
|
|
|
}
|
2022-02-22 10:35:06 +01:00
|
|
|
},
|
|
|
|
);
|
2020-09-26 13:10:05 +02:00
|
|
|
|
|
|
|
$("body").on("click", ".popover_playground_link", (e) => {
|
2021-02-28 01:03:09 +01:00
|
|
|
hide_playground_links_popover();
|
2020-09-26 13:10:05 +02:00
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", ".info_popover_actions .narrow_to_private_messages", (e) => {
|
|
|
|
const user_id = elem_to_user_id($(e.target).parents("ul"));
|
2020-02-05 14:30:59 +01:00
|
|
|
const email = people.get_by_user_id(user_id).email;
|
2021-02-28 01:03:09 +01:00
|
|
|
hide_all();
|
2020-06-25 21:35:01 +02:00
|
|
|
if (overlays.settings_open()) {
|
|
|
|
overlays.close_overlay("settings");
|
|
|
|
}
|
2020-07-15 01:29:15 +02:00
|
|
|
narrow.by("pm-with", email, {trigger: "user sidebar popover"});
|
2013-06-28 22:38:40 +02:00
|
|
|
e.stopPropagation();
|
2018-02-27 20:40:07 +01:00
|
|
|
e.preventDefault();
|
2013-06-28 22:38:40 +02:00
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", ".info_popover_actions .narrow_to_messages_sent", (e) => {
|
|
|
|
const user_id = elem_to_user_id($(e.target).parents("ul"));
|
2020-02-05 14:30:59 +01:00
|
|
|
const email = people.get_by_user_id(user_id).email;
|
2021-02-28 01:03:09 +01:00
|
|
|
hide_all();
|
2020-06-25 21:35:01 +02:00
|
|
|
if (overlays.settings_open()) {
|
|
|
|
overlays.close_overlay("settings");
|
|
|
|
}
|
2020-07-15 01:29:15 +02:00
|
|
|
narrow.by("sender", email, {trigger: "user sidebar popover"});
|
2013-06-28 22:38:40 +02:00
|
|
|
e.stopPropagation();
|
2017-03-04 13:43:21 +01:00
|
|
|
e.preventDefault();
|
2013-06-28 22:38:40 +02:00
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", ".user_popover .mention_user", (e) => {
|
2018-02-27 20:48:43 +01:00
|
|
|
if (!compose_state.composing()) {
|
2020-07-15 01:29:15 +02:00
|
|
|
compose_actions.start("stream", {trigger: "sidebar user actions"});
|
2018-02-27 20:48:43 +01:00
|
|
|
}
|
2020-07-15 01:29:15 +02:00
|
|
|
const user_id = elem_to_user_id($(e.target).parents("ul"));
|
2020-02-05 14:30:59 +01:00
|
|
|
const name = people.get_by_user_id(user_id).full_name;
|
2019-11-02 00:06:25 +01:00
|
|
|
const mention = people.get_mention_syntax(name, user_id);
|
2018-10-13 02:35:58 +02:00
|
|
|
compose_ui.insert_syntax_and_focus(mention);
|
2021-02-28 01:03:09 +01:00
|
|
|
hide_user_sidebar_popover();
|
|
|
|
hide_userlist_sidebar();
|
2016-12-28 06:29:13 +01:00
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", ".message-info-popover .mention_user", (e) => {
|
2018-02-27 20:48:43 +01:00
|
|
|
if (!compose_state.composing()) {
|
2020-07-15 01:29:15 +02:00
|
|
|
compose_actions.respond_to_message({trigger: "user sidebar popover"});
|
2018-02-27 20:48:43 +01:00
|
|
|
}
|
2020-07-15 01:29:15 +02:00
|
|
|
const user_id = elem_to_user_id($(e.target).parents("ul"));
|
2020-02-05 14:30:59 +01:00
|
|
|
const name = people.get_by_user_id(user_id).full_name;
|
2019-11-02 00:06:25 +01:00
|
|
|
const mention = people.get_mention_syntax(name, user_id);
|
2018-10-13 02:35:58 +02:00
|
|
|
compose_ui.insert_syntax_and_focus(mention);
|
2021-02-28 01:03:09 +01:00
|
|
|
hide_message_info_popover();
|
2016-12-28 06:29:13 +01:00
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", ".info_popover_actions .clear_status", (e) => {
|
2019-02-23 00:46:51 +01:00
|
|
|
e.preventDefault();
|
2020-07-15 01:29:15 +02:00
|
|
|
const me = elem_to_user_id($(e.target).parents("ul"));
|
2022-09-21 15:49:36 +02:00
|
|
|
user_status.server_update_status({
|
2019-02-23 00:46:51 +01:00
|
|
|
user_id: me,
|
2020-07-15 01:29:15 +02:00
|
|
|
status_text: "",
|
2021-06-29 17:21:30 +02:00
|
|
|
emoji_name: "",
|
|
|
|
emoji_code: "",
|
2020-07-20 22:18:43 +02:00
|
|
|
success() {
|
2022-08-18 00:30:47 +02:00
|
|
|
$(".info_popover_actions #status_message").empty();
|
2019-02-23 00:46:51 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-09-19 15:15:44 +02:00
|
|
|
$("body").on("click", ".view_user_profile", (e) => {
|
2022-04-26 07:44:33 +02:00
|
|
|
const user_id = Number.parseInt($(e.currentTarget).attr("data-user-id"), 10);
|
2020-02-05 14:30:59 +01:00
|
|
|
const user = people.get_by_user_id(user_id);
|
2021-02-28 01:03:09 +01:00
|
|
|
show_user_info_popover(e.target, user);
|
2020-09-19 15:15:44 +02:00
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
2019-05-29 05:59:53 +02:00
|
|
|
});
|
|
|
|
|
2021-06-18 12:44:54 +02:00
|
|
|
/* These click handlers are implemented as just deep links to the
|
|
|
|
* relevant part of the Zulip UI, so we don't want preventDefault,
|
|
|
|
* but we do want to close the modal when you click them. */
|
|
|
|
|
2022-09-21 15:49:36 +02:00
|
|
|
$("body").on("click", ".invisible_mode_turn_on", (e) => {
|
2021-02-28 01:03:09 +01:00
|
|
|
hide_all();
|
2022-09-21 15:49:36 +02:00
|
|
|
user_status.server_invisible_mode_on();
|
2018-12-20 15:22:30 +01:00
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
|
2022-09-21 15:49:36 +02:00
|
|
|
$("body").on("click", ".invisible_mode_turn_off", (e) => {
|
2021-02-28 01:03:09 +01:00
|
|
|
hide_all();
|
2022-09-21 15:49:36 +02:00
|
|
|
user_status.server_invisible_mode_off();
|
2018-12-20 15:22:30 +01:00
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
|
2021-08-05 11:15:02 +02:00
|
|
|
function open_user_status_modal(e) {
|
2021-02-28 01:03:09 +01:00
|
|
|
hide_all();
|
2019-01-26 21:14:33 +01:00
|
|
|
|
2021-06-24 18:46:59 +02:00
|
|
|
user_status_ui.open_user_status_modal();
|
2019-01-26 21:14:33 +01:00
|
|
|
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
2021-08-05 11:15:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$("body").on("click", ".update_status_text", open_user_status_modal);
|
|
|
|
|
|
|
|
// Clicking on one's own status emoji should open the user status modal.
|
|
|
|
$("#user_presences").on(
|
|
|
|
"click",
|
|
|
|
".user_sidebar_entry_me .status_emoji",
|
|
|
|
open_user_status_modal,
|
|
|
|
);
|
2019-01-26 21:14:33 +01:00
|
|
|
|
2022-10-03 13:29:59 +02:00
|
|
|
$("body").on("click", ".sidebar-popover-mute-user", (e) => {
|
2021-03-27 13:14:34 +01:00
|
|
|
const user_id = elem_to_user_id($(e.target).parents("ul"));
|
2022-04-14 21:13:59 +02:00
|
|
|
hide_all_user_info_popovers();
|
2021-03-27 13:14:34 +01:00
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
2021-07-08 20:28:14 +02:00
|
|
|
muted_users_ui.confirm_mute_user(user_id);
|
2021-03-27 13:14:34 +01:00
|
|
|
});
|
|
|
|
|
2022-10-03 13:29:59 +02:00
|
|
|
$("body").on("click", ".sidebar-popover-unmute-user", (e) => {
|
2021-03-27 13:14:34 +01:00
|
|
|
const user_id = elem_to_user_id($(e.target).parents("ul"));
|
2022-04-14 21:13:59 +02:00
|
|
|
hide_all_user_info_popovers();
|
2021-07-08 20:28:14 +02:00
|
|
|
muted_users_ui.unmute_user(user_id);
|
2021-03-27 13:14:34 +01:00
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
|
2022-03-18 13:03:26 +01:00
|
|
|
$("body").on("click", ".info_popover_actions .sidebar-popover-reactivate-user", (e) => {
|
|
|
|
const user_id = elem_to_user_id($(e.target).parents("ul"));
|
|
|
|
hide_all();
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
function handle_confirm() {
|
|
|
|
const url = "/json/users/" + encodeURIComponent(user_id) + "/reactivate";
|
|
|
|
channel.post({
|
|
|
|
url,
|
|
|
|
success() {
|
|
|
|
dialog_widget.close_modal();
|
|
|
|
},
|
|
|
|
error(xhr) {
|
|
|
|
ui_report.error($t_html({defaultMessage: "Failed"}), xhr, $("#dialog_error"));
|
|
|
|
dialog_widget.hide_dialog_spinner();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
settings_users.confirm_reactivation(user_id, handle_confirm, true);
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#user_presences").on("click", ".user-list-sidebar-menu-icon", function (e) {
|
2013-12-04 03:30:27 +01:00
|
|
|
e.stopPropagation();
|
2013-12-03 23:05:38 +01:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
const $target = $(this).closest("li");
|
|
|
|
const user_id = elem_to_user_id($target.find("a"));
|
2022-11-10 01:18:42 +01:00
|
|
|
// Hiding popovers may mutate current_user_sidebar_user_id.
|
|
|
|
const previous_user_sidebar_id = current_user_sidebar_user_id;
|
2013-12-04 03:30:27 +01:00
|
|
|
|
2022-11-10 01:18:42 +01:00
|
|
|
// Hide popovers, but we don't want to hide the sidebars on
|
|
|
|
// smaller browser windows.
|
|
|
|
hide_all_except_sidebars();
|
|
|
|
|
|
|
|
if (previous_user_sidebar_id === user_id) {
|
2013-12-03 23:05:38 +01:00
|
|
|
// If the popover is already shown, clicking again should toggle it.
|
|
|
|
return;
|
|
|
|
}
|
2017-03-04 13:43:21 +01:00
|
|
|
|
2020-02-05 14:30:59 +01:00
|
|
|
const user = people.get_by_user_id(user_id);
|
2019-11-02 00:06:25 +01:00
|
|
|
const popover_placement = userlist_placement === "left" ? "right" : "left";
|
2017-03-04 13:43:21 +01:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
render_user_info_popover(
|
|
|
|
user,
|
2022-01-25 11:36:19 +01:00
|
|
|
$target,
|
2020-07-15 00:34:28 +02:00
|
|
|
false,
|
2020-06-27 21:33:09 +02:00
|
|
|
false,
|
2020-07-15 00:34:28 +02:00
|
|
|
"compose_private_message",
|
|
|
|
"user_popover",
|
|
|
|
popover_placement,
|
|
|
|
);
|
2017-03-04 13:43:21 +01:00
|
|
|
|
2018-11-12 23:53:54 +01:00
|
|
|
current_user_sidebar_user_id = user.user_id;
|
2022-01-25 11:36:19 +01:00
|
|
|
current_user_sidebar_popover = $target.data("popover");
|
2017-12-13 20:45:06 +01:00
|
|
|
});
|
2013-12-04 03:30:27 +01:00
|
|
|
|
2021-08-05 00:59:03 +02:00
|
|
|
$("body").on("click", ".mark_as_unread", (e) => {
|
|
|
|
hide_actions_popover();
|
|
|
|
const message_id = $(e.currentTarget).data("message-id");
|
|
|
|
|
|
|
|
unread_ops.mark_as_unread_from_here(message_id);
|
|
|
|
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", ".respond_button", (e) => {
|
2018-01-31 04:23:02 +01:00
|
|
|
// Arguably, we should fetch the message ID to respond to from
|
|
|
|
// e.target, but that should always be the current selected
|
|
|
|
// message in the current message list (and
|
|
|
|
// compose_actions.respond_to_message doesn't take a message
|
|
|
|
// argument).
|
2020-07-15 01:29:15 +02:00
|
|
|
compose_actions.quote_and_reply({trigger: "popover respond"});
|
2021-02-28 01:03:09 +01:00
|
|
|
hide_actions_popover();
|
2013-06-28 22:38:40 +02:00
|
|
|
e.stopPropagation();
|
2018-01-15 03:02:23 +01:00
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", ".remind.custom", (e) => {
|
2018-01-15 03:02:23 +01:00
|
|
|
$(e.currentTarget)[0]._flatpickr.toggle();
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
|
2018-01-16 02:01:23 +01:00
|
|
|
function reminder_click_handler(datestr, e) {
|
2020-07-15 01:29:15 +02:00
|
|
|
const message_id = $(".remind.custom").data("message-id");
|
2020-01-16 22:27:27 +01:00
|
|
|
reminder.do_set_reminder_for_message(message_id, datestr);
|
2021-02-28 01:03:09 +01:00
|
|
|
hide_all();
|
2018-01-16 02:01:23 +01:00
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", ".remind.in_20m", (e) => {
|
2020-09-29 22:20:46 +02:00
|
|
|
const datestr = formatISO(add(new Date(), {minutes: 20}));
|
2018-01-16 02:01:23 +01:00
|
|
|
reminder_click_handler(datestr, e);
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", ".remind.in_1h", (e) => {
|
2020-09-29 22:20:46 +02:00
|
|
|
const datestr = formatISO(add(new Date(), {hours: 1}));
|
2018-01-16 02:01:23 +01:00
|
|
|
reminder_click_handler(datestr, e);
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", ".remind.in_3h", (e) => {
|
2020-09-29 22:20:46 +02:00
|
|
|
const datestr = formatISO(add(new Date(), {hours: 3}));
|
2018-01-16 02:01:23 +01:00
|
|
|
reminder_click_handler(datestr, e);
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", ".remind.tomo", (e) => {
|
2020-09-29 22:20:46 +02:00
|
|
|
const datestr = formatISO(
|
|
|
|
set(add(new Date(), {days: 1}), {hours: 9, minutes: 0, seconds: 0}),
|
|
|
|
);
|
2018-01-16 02:01:23 +01:00
|
|
|
reminder_click_handler(datestr, e);
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", ".remind.nxtw", (e) => {
|
2020-09-29 22:20:46 +02:00
|
|
|
const datestr = formatISO(
|
|
|
|
set(add(new Date(), {weeks: 1}), {hours: 9, minutes: 0, seconds: 0}),
|
|
|
|
);
|
2018-01-16 02:01:23 +01:00
|
|
|
reminder_click_handler(datestr, e);
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", ".flatpickr-calendar", (e) => {
|
2018-01-15 03:02:23 +01:00
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", ".flatpickr-confirm", (e) => {
|
2021-11-11 14:35:43 +01:00
|
|
|
if ($(".remind.custom")[0]) {
|
|
|
|
const datestr = $(".remind.custom")[0].value;
|
|
|
|
reminder_click_handler(datestr, e);
|
|
|
|
}
|
2018-01-15 03:02:23 +01:00
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", ".respond_personal_button, .compose_private_message", (e) => {
|
|
|
|
const user_id = elem_to_user_id($(e.target).parents("ul"));
|
2020-02-05 14:30:59 +01:00
|
|
|
const email = people.get_by_user_id(user_id).email;
|
2020-07-15 01:29:15 +02:00
|
|
|
compose_actions.start("private", {
|
|
|
|
trigger: "popover send private",
|
2020-07-15 00:34:28 +02:00
|
|
|
private_message_recipient: email,
|
|
|
|
});
|
2021-02-28 01:03:09 +01:00
|
|
|
hide_all();
|
2020-06-25 21:35:01 +02:00
|
|
|
if (overlays.settings_open()) {
|
|
|
|
overlays.close_overlay("settings");
|
|
|
|
}
|
2013-06-28 22:38:40 +02:00
|
|
|
e.stopPropagation();
|
2013-07-11 23:06:58 +02:00
|
|
|
e.preventDefault();
|
2013-06-28 22:38:40 +02:00
|
|
|
});
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", ".popover_toggle_collapse", (e) => {
|
|
|
|
const message_id = $(e.currentTarget).data("message-id");
|
2022-01-25 11:36:19 +01:00
|
|
|
const $row = message_lists.current.get_row(message_id);
|
|
|
|
const message = message_lists.current.get(rows.id($row));
|
2013-06-28 22:38:40 +02:00
|
|
|
|
2021-02-28 01:03:09 +01:00
|
|
|
hide_actions_popover();
|
2014-04-19 00:32:41 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
if ($row) {
|
2014-04-19 00:32:41 +02:00
|
|
|
if (message.collapsed) {
|
2022-01-25 11:36:19 +01:00
|
|
|
condense.uncollapse($row);
|
2014-04-19 00:32:41 +02:00
|
|
|
} else {
|
2022-01-25 11:36:19 +01:00
|
|
|
condense.collapse($row);
|
2014-04-19 00:32:41 +02:00
|
|
|
}
|
2016-03-13 19:05:10 +01:00
|
|
|
}
|
2013-06-28 22:38:40 +02:00
|
|
|
|
|
|
|
e.stopPropagation();
|
2013-07-11 23:06:58 +02:00
|
|
|
e.preventDefault();
|
2013-06-28 22:38:40 +02:00
|
|
|
});
|
2022-10-03 09:41:13 +02:00
|
|
|
$("body").on("click", ".popover_edit_message, .popover_view_source", (e) => {
|
|
|
|
const message_id = $(e.currentTarget).data("message-id");
|
|
|
|
const $row = message_lists.current.get_row(message_id);
|
|
|
|
hide_actions_popover();
|
|
|
|
message_edit.start($row);
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
$("body").on("click", ".popover_move_message", (e) => {
|
|
|
|
const message_id = $(e.currentTarget).data("message-id");
|
|
|
|
const message = message_lists.current.get(message_id);
|
|
|
|
hide_actions_popover();
|
|
|
|
stream_popover.build_move_topic_to_stream_popover(
|
|
|
|
message.stream_id,
|
|
|
|
message.topic,
|
|
|
|
message,
|
|
|
|
);
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
2021-05-20 11:37:57 +02:00
|
|
|
$("body").on("click", ".rehide_muted_user_message", (e) => {
|
|
|
|
const message_id = $(e.currentTarget).data("message-id");
|
2022-01-25 11:36:19 +01:00
|
|
|
const $row = message_lists.current.get_row(message_id);
|
|
|
|
const message = message_lists.current.get(rows.id($row));
|
2021-05-20 11:37:57 +02:00
|
|
|
const message_container = message_lists.current.view.message_containers.get(message.id);
|
|
|
|
|
|
|
|
hide_actions_popover();
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
if ($row && !message_container.is_hidden) {
|
2021-05-20 11:37:57 +02:00
|
|
|
message_lists.current.view.hide_revealed_message(message_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", ".view_edit_history", (e) => {
|
|
|
|
const message_id = $(e.currentTarget).data("message-id");
|
2022-01-25 11:36:19 +01:00
|
|
|
const $row = message_lists.current.get_row(message_id);
|
|
|
|
const message = message_lists.current.get(rows.id($row));
|
2017-02-20 02:37:58 +01:00
|
|
|
|
2021-02-28 01:03:09 +01:00
|
|
|
hide_actions_popover();
|
2020-06-07 04:50:31 +02:00
|
|
|
message_edit_history.show_history(message);
|
2021-06-16 15:20:20 +02:00
|
|
|
$("#message-history-cancel").trigger("focus");
|
2017-02-20 02:37:58 +01:00
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
2013-06-28 22:38:40 +02:00
|
|
|
|
2021-06-16 21:15:47 +02:00
|
|
|
$("body").on("click", ".view_read_receipts", (e) => {
|
|
|
|
const message_id = $(e.currentTarget).data("message-id");
|
|
|
|
hide_actions_popover();
|
|
|
|
read_receipts.show_user_list(message_id);
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", ".delete_message", (e) => {
|
|
|
|
const message_id = $(e.currentTarget).data("message-id");
|
2021-02-28 01:03:09 +01:00
|
|
|
hide_actions_popover();
|
2019-08-28 17:46:10 +02:00
|
|
|
message_edit.delete_message(message_id);
|
2017-05-14 21:14:26 +02:00
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
|
2021-06-29 16:35:39 +02:00
|
|
|
clipboard_enable(".copy_link").on("success", (e) => {
|
2021-02-28 01:03:09 +01:00
|
|
|
hide_actions_popover();
|
2021-06-29 16:35:39 +02:00
|
|
|
// e.trigger returns the DOM element triggering the copy action
|
2022-01-24 23:48:18 +01:00
|
|
|
const message_id = e.trigger.dataset.messageId;
|
2022-01-25 11:36:19 +01:00
|
|
|
const $row = $(`[zid='${CSS.escape(message_id)}']`);
|
|
|
|
$row.find(".alert-msg")
|
2021-04-13 06:51:54 +02:00
|
|
|
.text($t({defaultMessage: "Copied!"}))
|
2017-08-23 21:08:49 +02:00
|
|
|
.css("display", "block")
|
2020-07-15 00:34:28 +02:00
|
|
|
.delay(1000)
|
|
|
|
.fadeOut(300);
|
2017-05-08 22:46:25 +02:00
|
|
|
|
2020-07-02 01:45:54 +02:00
|
|
|
setTimeout(() => {
|
2022-02-08 00:13:33 +01:00
|
|
|
// The Clipboard library works by focusing to a hidden textarea.
|
2017-06-20 06:25:20 +02:00
|
|
|
// We unfocus this so keyboard shortcuts, etc., will work again.
|
2020-07-20 21:24:26 +02:00
|
|
|
$(":focus").trigger("blur");
|
2017-06-20 06:25:20 +02:00
|
|
|
}, 0);
|
2017-05-08 22:46:25 +02:00
|
|
|
});
|
|
|
|
|
2021-03-06 20:28:43 +01:00
|
|
|
clipboard_enable(".copy_mention_syntax");
|
2020-06-27 21:33:09 +02:00
|
|
|
|
|
|
|
$("body").on("click", ".copy_mention_syntax", (e) => {
|
2021-02-28 01:03:09 +01:00
|
|
|
hide_all();
|
2020-06-27 21:33:09 +02:00
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
|
2021-05-06 21:49:45 +02:00
|
|
|
{
|
2019-11-02 00:06:25 +01:00
|
|
|
let last_scroll = 0;
|
2017-01-26 19:57:27 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$(".app").on("scroll", () => {
|
2019-03-15 04:02:27 +01:00
|
|
|
if (suppress_scroll_hide) {
|
|
|
|
suppress_scroll_hide = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-12-22 11:54:49 +01:00
|
|
|
const date = Date.now();
|
2017-01-26 19:57:27 +01:00
|
|
|
|
|
|
|
// only run `popovers.hide_all()` if the last scroll was more
|
|
|
|
// than 250ms ago.
|
|
|
|
if (date - last_scroll > 250) {
|
2021-02-28 01:03:09 +01:00
|
|
|
hide_all();
|
2017-01-26 19:57:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// update the scroll time on every event to make sure it doesn't
|
|
|
|
// retrigger `hide_all` while still scrolling.
|
|
|
|
last_scroll = date;
|
|
|
|
});
|
2021-05-06 21:49:45 +02:00
|
|
|
}
|
2021-11-26 13:46:11 +01:00
|
|
|
|
|
|
|
$("body").on("click", ".sidebar-popover-manage-user", (e) => {
|
|
|
|
hide_all();
|
|
|
|
const user_id = elem_to_user_id($(e.target).parents("ul"));
|
2022-07-22 20:42:08 +02:00
|
|
|
const user = people.get_by_user_id(user_id);
|
|
|
|
if (user.is_bot) {
|
2022-07-08 19:10:15 +02:00
|
|
|
settings_bots.show_edit_bot_info_modal(user_id, true);
|
2022-07-22 20:42:08 +02:00
|
|
|
} else {
|
|
|
|
settings_users.show_edit_user_info_modal(user_id, true);
|
|
|
|
}
|
2021-11-26 13:46:11 +01:00
|
|
|
});
|
2022-10-03 13:29:59 +02:00
|
|
|
|
|
|
|
$("body").on("click", ".user_info_popover_manage_menu_btn", (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
const user_id = elem_to_user_id($(e.target).parents("ul"));
|
|
|
|
const user = people.get_by_user_id(user_id);
|
|
|
|
show_user_info_popover_manage_menu(e.target, user);
|
|
|
|
});
|
2021-02-28 01:03:09 +01:00
|
|
|
}
|
2013-06-28 22:38:40 +02:00
|
|
|
|
2021-02-28 01:03:09 +01:00
|
|
|
export function any_active() {
|
2013-06-28 22:38:40 +02:00
|
|
|
// True if any popover (that this module manages) is currently shown.
|
2017-10-11 05:07:03 +02:00
|
|
|
// Expanded sidebars on mobile view count as popovers as well.
|
2020-07-15 00:34:28 +02:00
|
|
|
return (
|
2021-11-10 14:27:27 +01:00
|
|
|
popover_menus.any_active() ||
|
2021-02-28 01:03:09 +01:00
|
|
|
actions_popped() ||
|
|
|
|
user_sidebar_popped() ||
|
2020-07-15 00:34:28 +02:00
|
|
|
stream_popover.stream_popped() ||
|
|
|
|
stream_popover.topic_popped() ||
|
2021-02-28 01:03:09 +01:00
|
|
|
message_info_popped() ||
|
|
|
|
user_info_popped() ||
|
2020-07-15 00:34:28 +02:00
|
|
|
emoji_picker.reactions_popped() ||
|
|
|
|
$("[class^='column-'].expanded").length
|
|
|
|
);
|
2021-02-28 01:03:09 +01:00
|
|
|
}
|
2013-06-28 22:38:40 +02:00
|
|
|
|
2019-07-10 01:54:39 +02:00
|
|
|
// This function will hide all true popovers (the streamlist and
|
|
|
|
// userlist sidebars use the popover infrastructure, but doesn't work
|
|
|
|
// like a popover structurally).
|
2021-06-17 00:49:50 +02:00
|
|
|
export function hide_all_except_sidebars(opts) {
|
2020-07-15 01:29:15 +02:00
|
|
|
$(".has_popover").removeClass("has_popover has_actions_popover has_emoji_popover");
|
2021-06-17 00:49:50 +02:00
|
|
|
if (!opts || !opts.not_hide_tippy_instances) {
|
|
|
|
hideAll();
|
|
|
|
} else if (opts.exclude_tippy_instance) {
|
|
|
|
hideAll({exclude: opts.exclude_tippy_instance});
|
|
|
|
}
|
2021-02-28 01:03:09 +01:00
|
|
|
hide_actions_popover();
|
2017-04-28 22:26:22 +02:00
|
|
|
emoji_picker.hide_emoji_popover();
|
2021-03-31 07:48:11 +02:00
|
|
|
giphy.hide_giphy_popover();
|
2017-03-05 17:28:40 +01:00
|
|
|
stream_popover.hide_stream_popover();
|
|
|
|
stream_popover.hide_topic_popover();
|
2018-02-15 20:38:06 +01:00
|
|
|
stream_popover.hide_all_messages_popover();
|
2019-02-22 12:28:29 +01:00
|
|
|
stream_popover.hide_starred_messages_popover();
|
2021-11-25 17:02:19 +01:00
|
|
|
stream_popover.hide_drafts_popover();
|
2022-04-14 21:13:59 +02:00
|
|
|
hide_all_user_info_popovers();
|
2021-02-28 01:03:09 +01:00
|
|
|
hide_playground_links_popover();
|
2017-01-04 02:44:49 +01:00
|
|
|
|
|
|
|
// look through all the popovers that have been added and removed.
|
2021-01-22 22:29:08 +01:00
|
|
|
for (const $o of list_of_popovers) {
|
2017-01-04 02:44:49 +01:00
|
|
|
if (!document.body.contains($o.$element[0]) && $o.$tip) {
|
|
|
|
$o.$tip.remove();
|
|
|
|
}
|
2021-01-22 22:29:08 +01:00
|
|
|
}
|
2018-02-16 20:16:10 +01:00
|
|
|
list_of_popovers = [];
|
2021-02-28 01:03:09 +01:00
|
|
|
}
|
2013-06-28 22:38:40 +02:00
|
|
|
|
2019-07-10 01:54:39 +02:00
|
|
|
// This function will hide all the popovers, including the mobile web
|
|
|
|
// or narrow window sidebars.
|
2021-06-17 00:49:50 +02:00
|
|
|
export function hide_all(not_hide_tippy_instances) {
|
2021-02-28 01:03:09 +01:00
|
|
|
hide_userlist_sidebar();
|
2019-07-10 01:56:25 +02:00
|
|
|
stream_popover.hide_streamlist_sidebar();
|
2021-06-17 00:49:50 +02:00
|
|
|
hide_all_except_sidebars({
|
|
|
|
exclude_tippy_instance: undefined,
|
|
|
|
not_hide_tippy_instances,
|
|
|
|
});
|
2021-02-28 01:03:09 +01:00
|
|
|
}
|
2019-02-08 14:37:04 +01:00
|
|
|
|
2021-02-28 01:03:09 +01:00
|
|
|
export function set_userlist_placement(placement) {
|
2013-09-12 22:02:55 +02:00
|
|
|
userlist_placement = placement || "right";
|
2021-02-28 01:03:09 +01:00
|
|
|
}
|
2013-09-12 22:02:55 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
export function compute_placement(
|
|
|
|
$elt,
|
|
|
|
popover_height,
|
|
|
|
popover_width,
|
|
|
|
prefer_vertical_positioning,
|
|
|
|
) {
|
|
|
|
const client_rect = $elt.get(0).getBoundingClientRect();
|
2019-11-02 00:06:25 +01:00
|
|
|
const distance_from_top = client_rect.top;
|
|
|
|
const distance_from_bottom = message_viewport.height() - client_rect.bottom;
|
|
|
|
const distance_from_left = client_rect.left;
|
|
|
|
const distance_from_right = message_viewport.width() - client_rect.right;
|
2017-08-01 00:36:09 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const elt_will_fit_horizontally =
|
2022-01-25 11:36:19 +01:00
|
|
|
distance_from_left + $elt.width() / 2 > popover_width / 2 &&
|
|
|
|
distance_from_right + $elt.width() / 2 > popover_width / 2;
|
2017-08-01 00:36:09 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const elt_will_fit_vertically =
|
2022-01-25 11:36:19 +01:00
|
|
|
distance_from_bottom + $elt.height() / 2 > popover_height / 2 &&
|
|
|
|
distance_from_top + $elt.height() / 2 > popover_height / 2;
|
2017-08-01 00:36:09 +02:00
|
|
|
|
|
|
|
// default to placing the popover in the center of the screen
|
2020-07-15 01:29:15 +02:00
|
|
|
let placement = "viewport_center";
|
2017-08-01 00:36:09 +02:00
|
|
|
|
|
|
|
// prioritize left/right over top/bottom
|
|
|
|
if (distance_from_top > popover_height && elt_will_fit_horizontally) {
|
2020-07-15 01:29:15 +02:00
|
|
|
placement = "top";
|
2017-07-27 21:21:14 +02:00
|
|
|
}
|
2017-08-01 00:36:09 +02:00
|
|
|
if (distance_from_bottom > popover_height && elt_will_fit_horizontally) {
|
2020-07-15 01:29:15 +02:00
|
|
|
placement = "bottom";
|
2017-08-01 00:36:09 +02:00
|
|
|
}
|
2017-08-25 19:59:23 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
if (prefer_vertical_positioning && placement !== "viewport_center") {
|
2017-11-09 16:26:38 +01:00
|
|
|
// If vertical positioning is preferred and the popover fits in
|
2017-08-25 19:59:23 +02:00
|
|
|
// either top or bottom position then return.
|
|
|
|
return placement;
|
|
|
|
}
|
|
|
|
|
2017-08-01 00:36:09 +02:00
|
|
|
if (distance_from_left > popover_width && elt_will_fit_vertically) {
|
2020-07-15 01:29:15 +02:00
|
|
|
placement = "left";
|
2017-07-27 21:21:14 +02:00
|
|
|
}
|
2017-08-01 00:36:09 +02:00
|
|
|
if (distance_from_right > popover_width && elt_will_fit_vertically) {
|
2020-07-15 01:29:15 +02:00
|
|
|
placement = "right";
|
2017-07-27 21:21:14 +02:00
|
|
|
}
|
2017-08-01 00:36:09 +02:00
|
|
|
|
2017-07-27 21:21:14 +02:00
|
|
|
return placement;
|
2021-02-28 01:03:09 +01:00
|
|
|
}
|