2021-06-23 20:48:49 +02:00
|
|
|
import {parseISO} from "date-fns";
|
|
|
|
import $ from "jquery";
|
|
|
|
|
|
|
|
import render_user_group_list_item from "../templates/user_group_list_item.hbs";
|
|
|
|
import render_user_profile_modal from "../templates/user_profile_modal.hbs";
|
|
|
|
import render_user_stream_list_item from "../templates/user_stream_list_item.hbs";
|
|
|
|
|
2021-06-30 23:07:02 +02:00
|
|
|
import * as browser_history from "./browser_history";
|
2021-06-23 20:48:49 +02:00
|
|
|
import * as buddy_data from "./buddy_data";
|
2021-06-30 23:07:02 +02:00
|
|
|
import * as channel from "./channel";
|
2021-06-23 20:48:49 +02:00
|
|
|
import * as components from "./components";
|
2023-09-08 19:37:58 +02:00
|
|
|
import * as dropdown_widget from "./dropdown_widget";
|
2021-06-23 20:48:49 +02:00
|
|
|
import * as hash_util from "./hash_util";
|
2021-06-30 23:07:02 +02:00
|
|
|
import {$t, $t_html} from "./i18n";
|
2021-06-23 20:48:49 +02:00
|
|
|
import * as ListWidget from "./list_widget";
|
|
|
|
import * as overlays from "./overlays";
|
|
|
|
import {page_params} from "./page_params";
|
|
|
|
import * as people from "./people";
|
|
|
|
import * as popovers from "./popovers";
|
|
|
|
import * as settings_account from "./settings_account";
|
2022-08-24 13:46:25 +02:00
|
|
|
import * as settings_bots from "./settings_bots";
|
2021-06-23 20:48:49 +02:00
|
|
|
import * as settings_profile_fields from "./settings_profile_fields";
|
settings_users: Migrate manage user modal to full profile modal.
This commit migrates the "manage user" modal to the "Full Profile"
modal. Refactored the show_edit_user_info_modal function since
earlier, we used to have a separate "Manage User" modal.
Consequently, we checked if we were coming from the
user_info_popover and then built the dialog widget accordingly.
However, with this new change, we no longer need to build the
dialog widget. Therefore, removed that part and now just pass
the container of the 'user profile modal' to get the content.
Previously, for deactivation, we used to have a separate dialog
widget. But now, since we have a dedicated function to handle
this case, refactored the deactivation code to use the
'confirm_deactivation' function.
Additionally, created two new functions to handle the loading
spinner. Since we will need these functions in the future for
the "Manage Bot" modal, we marked them as exported.
"Since we do not want to show the 'Manage User' tab to the user
looking at their own profile, in the 'can_manage_user' function
that we use to render the 'Manage User' tab, we check if the user
profile popover belongs to the same user. If it does, we set it to
'false' instead of 'true,' ensuring that the 'Manage User' tab is
not visible.
Added a new tab in the user profile modal 'manage user'.
Fixes: #21806
2023-09-09 12:42:04 +02:00
|
|
|
import * as settings_users from "./settings_users";
|
2021-06-23 20:48:49 +02:00
|
|
|
import * as stream_data from "./stream_data";
|
2023-08-23 20:57:31 +02:00
|
|
|
import * as stream_ui_updates from "./stream_ui_updates";
|
2021-06-30 23:07:02 +02:00
|
|
|
import * as sub_store from "./sub_store";
|
2022-02-21 15:28:56 +01:00
|
|
|
import * as subscriber_api from "./subscriber_api";
|
2023-01-08 18:08:49 +01:00
|
|
|
import * as timerender from "./timerender";
|
2021-06-30 23:07:02 +02:00
|
|
|
import * as ui_report from "./ui_report";
|
2021-06-23 20:48:49 +02:00
|
|
|
import * as user_groups from "./user_groups";
|
2022-08-24 13:46:25 +02:00
|
|
|
import * as user_pill from "./user_pill";
|
2021-06-23 20:48:49 +02:00
|
|
|
import * as util from "./util";
|
|
|
|
|
2023-07-29 02:37:35 +02:00
|
|
|
let user_streams_list_widget;
|
2023-09-08 19:37:58 +02:00
|
|
|
let user_profile_subscribe_widget;
|
2023-07-29 02:37:35 +02:00
|
|
|
|
2021-06-23 20:48:49 +02:00
|
|
|
function compare_by_name(a, b) {
|
|
|
|
return util.strcmp(a.name, b.name);
|
|
|
|
}
|
|
|
|
|
2023-08-16 15:00:29 +02:00
|
|
|
export function get_user_id_if_user_profile_modal_open() {
|
|
|
|
if (overlays.is_modal_open() && overlays.active_modal() === "#user-profile-modal") {
|
|
|
|
const user_id = $("#user-profile-modal").data("user-id");
|
|
|
|
return user_id;
|
|
|
|
}
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
2023-07-29 02:37:35 +02:00
|
|
|
export function update_user_profile_streams_list_for_users(user_ids) {
|
|
|
|
const user_id = get_user_id_if_user_profile_modal_open();
|
|
|
|
if (user_id && user_ids.includes(user_id) && user_streams_list_widget !== undefined) {
|
|
|
|
const user_streams = stream_data.get_streams_for_user(user_id).subscribed;
|
2022-10-11 14:20:27 +02:00
|
|
|
user_streams.sort(compare_by_name);
|
2023-07-29 02:37:35 +02:00
|
|
|
user_streams_list_widget.replace_list_data(user_streams);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-24 13:46:25 +02:00
|
|
|
function initialize_bot_owner(element_id, bot_id) {
|
|
|
|
const user_pills = new Map();
|
|
|
|
const bot = people.get_by_user_id(bot_id);
|
|
|
|
const bot_owner = people.get_bot_owner_user(bot);
|
2022-11-14 18:02:55 +01:00
|
|
|
// Bot owner's pill displaying on bot's profile modal.
|
2022-08-24 13:46:25 +02:00
|
|
|
if (bot_owner) {
|
|
|
|
const $pill_container = $(element_id)
|
|
|
|
.find(
|
|
|
|
`.bot_owner_user_field[data-field-id="${CSS.escape(
|
|
|
|
bot_owner.user_id,
|
|
|
|
)}"] .pill-container`,
|
|
|
|
)
|
|
|
|
.expectOne();
|
|
|
|
const pills = user_pill.create_pills($pill_container);
|
|
|
|
|
|
|
|
user_pill.append_user(bot_owner, pills);
|
|
|
|
user_pills.set(bot_owner.user_id, pills);
|
|
|
|
}
|
|
|
|
return user_pills;
|
|
|
|
}
|
|
|
|
|
2023-09-08 19:37:58 +02:00
|
|
|
function render_user_profile_subscribe_widget() {
|
|
|
|
const opts = {
|
|
|
|
widget_name: "user_profile_subscribe",
|
|
|
|
get_options: get_user_unsub_streams,
|
|
|
|
item_click_callback: change_state_of_subscribe_button,
|
|
|
|
$events_container: $("#user-profile-modal"),
|
|
|
|
tippy_props: {
|
|
|
|
placement: "bottom-start",
|
|
|
|
},
|
|
|
|
};
|
|
|
|
user_profile_subscribe_widget = new dropdown_widget.DropdownWidget(opts);
|
|
|
|
user_profile_subscribe_widget.setup();
|
|
|
|
}
|
|
|
|
|
|
|
|
function change_state_of_subscribe_button(event, dropdown) {
|
|
|
|
dropdown.hide();
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
user_profile_subscribe_widget.render();
|
|
|
|
const $subscribe_button = $("#user-profile-modal .add-subscription-button");
|
2023-08-23 20:57:31 +02:00
|
|
|
$subscribe_button.parent()[0]._tippy?.destroy();
|
2023-09-08 19:37:58 +02:00
|
|
|
$subscribe_button.prop("disabled", false);
|
|
|
|
}
|
|
|
|
|
2023-09-08 16:35:13 +02:00
|
|
|
function reset_subscribe_widget() {
|
|
|
|
$("#user-profile-modal .add-subscription-button").prop("disabled", true);
|
|
|
|
stream_ui_updates.initialize_disable_btn_hint_popover(
|
|
|
|
$("#user-profile-modal .add-subscription-button-wrapper"),
|
|
|
|
$t({defaultMessage: "Select a stream to subscribe"}),
|
|
|
|
);
|
|
|
|
$("#user_profile_subscribe_widget .dropdown_widget_value").text(
|
|
|
|
$t({defaultMessage: "Select a stream"}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-09-08 19:37:58 +02:00
|
|
|
export function get_user_unsub_streams() {
|
|
|
|
const target_user_id = Number.parseInt($("#user-profile-modal").attr("data-user-id"), 10);
|
|
|
|
return stream_data
|
|
|
|
.get_streams_for_user(target_user_id)
|
|
|
|
.can_subscribe.filter((stream) => stream_data.can_subscribe_others(stream))
|
|
|
|
.map((stream) => ({
|
|
|
|
name: stream.name,
|
|
|
|
unique_id: stream.stream_id.toString(),
|
|
|
|
stream,
|
|
|
|
}))
|
|
|
|
.sort((a, b) => {
|
|
|
|
if (a.name.toLowerCase() < b.name.toLowerCase()) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (a.name.toLowerCase() > b.name.toLowerCase()) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-06-25 11:51:33 +02:00
|
|
|
function format_user_stream_list_item(stream, user) {
|
2021-06-30 08:35:25 +02:00
|
|
|
const show_unsubscribe_button =
|
2023-02-05 21:21:37 +01:00
|
|
|
people.can_admin_user(user) || stream_data.can_unsubscribe_others(stream);
|
2021-06-30 08:35:25 +02:00
|
|
|
const show_private_stream_unsub_tooltip =
|
|
|
|
people.is_my_user_id(user.user_id) && stream.invite_only;
|
2021-06-23 20:48:49 +02:00
|
|
|
return render_user_stream_list_item({
|
|
|
|
name: stream.name,
|
|
|
|
stream_id: stream.stream_id,
|
|
|
|
stream_color: stream.color,
|
|
|
|
invite_only: stream.invite_only,
|
|
|
|
is_web_public: stream.is_web_public,
|
2021-06-30 23:07:02 +02:00
|
|
|
show_unsubscribe_button,
|
2021-06-30 08:35:25 +02:00
|
|
|
show_private_stream_unsub_tooltip,
|
2022-03-01 19:14:26 +01:00
|
|
|
stream_edit_url: hash_util.stream_edit_url(stream),
|
2021-06-23 20:48:49 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function format_user_group_list_item(group) {
|
|
|
|
return render_user_group_list_item({
|
|
|
|
group_id: group.id,
|
|
|
|
name: group.name,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function render_user_stream_list(streams, user) {
|
2023-07-20 12:06:58 +02:00
|
|
|
$("#user-profile-modal .modal__footer").hide();
|
2021-06-23 20:48:49 +02:00
|
|
|
streams.sort(compare_by_name);
|
2022-01-25 11:36:19 +01:00
|
|
|
const $container = $("#user-profile-modal .user-stream-list");
|
|
|
|
$container.empty();
|
2023-07-29 02:37:35 +02:00
|
|
|
user_streams_list_widget = ListWidget.create($container, streams, {
|
2021-06-23 20:48:49 +02:00
|
|
|
name: `user-${user.user_id}-stream-list`,
|
2023-05-01 13:44:40 +02:00
|
|
|
get_item: ListWidget.default_get_item,
|
2021-06-23 20:48:49 +02:00
|
|
|
modifier(item) {
|
2021-06-25 11:51:33 +02:00
|
|
|
return format_user_stream_list_item(item, user);
|
2021-06-23 20:48:49 +02:00
|
|
|
},
|
2021-06-30 18:47:04 +02:00
|
|
|
filter: {
|
2022-01-25 11:36:19 +01:00
|
|
|
$element: $("#user-profile-streams-tab .stream-search"),
|
2021-06-30 18:47:04 +02:00
|
|
|
predicate(item, value) {
|
|
|
|
return item && item.name.toLocaleLowerCase().includes(value);
|
|
|
|
},
|
|
|
|
},
|
2022-01-25 11:36:19 +01:00
|
|
|
$simplebar_container: $("#user-profile-modal .modal__body"),
|
2021-06-23 20:48:49 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function render_user_group_list(groups, user) {
|
2023-07-20 12:06:58 +02:00
|
|
|
$("#user-profile-modal .modal__footer").hide();
|
2021-06-23 20:48:49 +02:00
|
|
|
groups.sort(compare_by_name);
|
2022-01-25 11:36:19 +01:00
|
|
|
const $container = $("#user-profile-modal .user-group-list");
|
|
|
|
$container.empty();
|
|
|
|
ListWidget.create($container, groups, {
|
2021-06-23 20:48:49 +02:00
|
|
|
name: `user-${user.user_id}-group-list`,
|
2023-05-01 13:44:40 +02:00
|
|
|
get_item: ListWidget.default_get_item,
|
2021-06-23 20:48:49 +02:00
|
|
|
modifier(item) {
|
|
|
|
return format_user_group_list_item(item);
|
|
|
|
},
|
2022-01-25 11:36:19 +01:00
|
|
|
$simplebar_container: $("#user-profile-modal .modal__body"),
|
2021-06-23 20:48:49 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
settings_users: Migrate manage user modal to full profile modal.
This commit migrates the "manage user" modal to the "Full Profile"
modal. Refactored the show_edit_user_info_modal function since
earlier, we used to have a separate "Manage User" modal.
Consequently, we checked if we were coming from the
user_info_popover and then built the dialog widget accordingly.
However, with this new change, we no longer need to build the
dialog widget. Therefore, removed that part and now just pass
the container of the 'user profile modal' to get the content.
Previously, for deactivation, we used to have a separate dialog
widget. But now, since we have a dedicated function to handle
this case, refactored the deactivation code to use the
'confirm_deactivation' function.
Additionally, created two new functions to handle the loading
spinner. Since we will need these functions in the future for
the "Manage Bot" modal, we marked them as exported.
"Since we do not want to show the 'Manage User' tab to the user
looking at their own profile, in the 'can_manage_user' function
that we use to render the 'Manage User' tab, we check if the user
profile popover belongs to the same user. If it does, we set it to
'false' instead of 'true,' ensuring that the 'Manage User' tab is
not visible.
Added a new tab in the user profile modal 'manage user'.
Fixes: #21806
2023-09-09 12:42:04 +02:00
|
|
|
function render_manage_profile_content(user) {
|
|
|
|
const $container = $("#manage-profile-tab");
|
|
|
|
$container.empty();
|
2023-07-20 13:50:04 +02:00
|
|
|
if (user.is_bot) {
|
|
|
|
settings_bots.show_edit_bot_info_modal(user.user_id, $container);
|
|
|
|
} else {
|
|
|
|
settings_users.show_edit_user_info_modal(user.user_id, $container);
|
|
|
|
}
|
2023-07-20 12:06:58 +02:00
|
|
|
$("#user-profile-modal .modal__footer").show();
|
settings_users: Migrate manage user modal to full profile modal.
This commit migrates the "manage user" modal to the "Full Profile"
modal. Refactored the show_edit_user_info_modal function since
earlier, we used to have a separate "Manage User" modal.
Consequently, we checked if we were coming from the
user_info_popover and then built the dialog widget accordingly.
However, with this new change, we no longer need to build the
dialog widget. Therefore, removed that part and now just pass
the container of the 'user profile modal' to get the content.
Previously, for deactivation, we used to have a separate dialog
widget. But now, since we have a dedicated function to handle
this case, refactored the deactivation code to use the
'confirm_deactivation' function.
Additionally, created two new functions to handle the loading
spinner. Since we will need these functions in the future for
the "Manage Bot" modal, we marked them as exported.
"Since we do not want to show the 'Manage User' tab to the user
looking at their own profile, in the 'can_manage_user' function
that we use to render the 'Manage User' tab, we check if the user
profile popover belongs to the same user. If it does, we set it to
'false' instead of 'true,' ensuring that the 'Manage User' tab is
not visible.
Added a new tab in the user profile modal 'manage user'.
Fixes: #21806
2023-09-09 12:42:04 +02:00
|
|
|
}
|
|
|
|
|
2023-01-08 18:08:49 +01:00
|
|
|
export function get_custom_profile_field_data(user, field, field_types) {
|
2021-06-23 20:48:49 +02:00
|
|
|
const field_value = people.get_custom_profile_data(user.user_id, field.id);
|
|
|
|
const field_type = field.type;
|
|
|
|
const profile_field = {};
|
|
|
|
|
|
|
|
if (!field_value) {
|
|
|
|
return profile_field;
|
|
|
|
}
|
|
|
|
if (!field_value.value) {
|
|
|
|
return profile_field;
|
|
|
|
}
|
2023-03-22 10:10:58 +01:00
|
|
|
profile_field.id = field.id;
|
2021-06-23 20:48:49 +02:00
|
|
|
profile_field.name = field.name;
|
|
|
|
profile_field.is_user_field = false;
|
|
|
|
profile_field.is_link = field_type === field_types.URL.id;
|
|
|
|
profile_field.is_external_account = field_type === field_types.EXTERNAL_ACCOUNT.id;
|
|
|
|
profile_field.type = field_type;
|
2022-07-12 21:25:02 +02:00
|
|
|
profile_field.display_in_profile_summary = field.display_in_profile_summary;
|
2021-06-23 20:48:49 +02:00
|
|
|
|
|
|
|
switch (field_type) {
|
|
|
|
case field_types.DATE.id:
|
2023-01-08 18:08:49 +01:00
|
|
|
profile_field.value = timerender.get_localized_date_or_time_for_format(
|
|
|
|
parseISO(field_value.value),
|
|
|
|
"dayofyear_year",
|
|
|
|
);
|
2021-06-23 20:48:49 +02:00
|
|
|
break;
|
|
|
|
case field_types.USER.id:
|
|
|
|
profile_field.is_user_field = true;
|
|
|
|
profile_field.value = field_value.value;
|
|
|
|
break;
|
|
|
|
case field_types.SELECT.id: {
|
|
|
|
const field_choice_dict = JSON.parse(field.field_data);
|
|
|
|
profile_field.value = field_choice_dict[field_value.value].text;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case field_types.SHORT_TEXT.id:
|
|
|
|
case field_types.LONG_TEXT.id:
|
|
|
|
profile_field.value = field_value.value;
|
|
|
|
profile_field.rendered_value = field_value.rendered_value;
|
|
|
|
break;
|
|
|
|
case field_types.EXTERNAL_ACCOUNT.id:
|
|
|
|
profile_field.value = field_value.value;
|
|
|
|
profile_field.field_data = JSON.parse(field.field_data);
|
2022-07-12 21:25:02 +02:00
|
|
|
profile_field.subtype = profile_field.field_data.subtype;
|
2021-06-23 20:48:49 +02:00
|
|
|
profile_field.link = settings_profile_fields.get_external_account_link(profile_field);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
profile_field.value = field_value.value;
|
|
|
|
}
|
|
|
|
return profile_field;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function hide_user_profile() {
|
2023-07-29 02:37:35 +02:00
|
|
|
user_streams_list_widget = undefined;
|
2023-05-10 10:09:08 +02:00
|
|
|
overlays.close_modal_if_open("user-profile-modal");
|
2021-06-23 20:48:49 +02:00
|
|
|
}
|
|
|
|
|
2022-09-11 15:14:06 +02:00
|
|
|
function initialize_user_type_fields(user) {
|
|
|
|
// Avoid duplicate pill fields, by removing existing ones.
|
|
|
|
$("#user-profile-modal .pill").remove();
|
|
|
|
if (!user.is_bot) {
|
|
|
|
settings_account.initialize_custom_user_type_fields(
|
|
|
|
"#user-profile-modal #content",
|
|
|
|
user.user_id,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
initialize_bot_owner("#user-profile-modal #content", user.user_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-24 10:54:02 +02:00
|
|
|
export function show_user_profile(user, default_tab_key = "profile-tab") {
|
2021-06-23 20:48:49 +02:00
|
|
|
popovers.hide_all();
|
|
|
|
|
|
|
|
const field_types = page_params.custom_profile_field_types;
|
|
|
|
const profile_data = page_params.custom_profile_fields
|
2023-01-08 18:08:49 +01:00
|
|
|
.map((f) => get_custom_profile_field_data(user, f, field_types))
|
2021-06-23 20:48:49 +02:00
|
|
|
.filter((f) => f.name !== undefined);
|
2023-07-29 00:49:51 +02:00
|
|
|
const user_streams = stream_data.get_streams_for_user(user.user_id).subscribed;
|
2023-09-08 19:37:58 +02:00
|
|
|
// We only show the subscribe widget if the user is an admin, the user has opened their own profile,
|
|
|
|
// or if the user profile belongs to a bot whose owner has opened the user profile. However, we don't
|
|
|
|
// want to show the subscribe widget for generic bots since they are system bots and for deactivated users.
|
|
|
|
// Therefore, we also check for that condition.
|
|
|
|
const show_user_subscribe_widget =
|
|
|
|
(people.can_admin_user(user) || page_params.is_admin) &&
|
|
|
|
!user.is_system_bot &&
|
|
|
|
people.is_person_active(user.user_id);
|
2021-06-23 20:48:49 +02:00
|
|
|
const groups_of_user = user_groups.get_user_groups_of_user(user.user_id);
|
2023-07-20 13:50:04 +02:00
|
|
|
// We currently have the main UI for editing your own profile in
|
|
|
|
// settings, so can_manage_profile is artificially false for those.
|
settings_users: Migrate manage user modal to full profile modal.
This commit migrates the "manage user" modal to the "Full Profile"
modal. Refactored the show_edit_user_info_modal function since
earlier, we used to have a separate "Manage User" modal.
Consequently, we checked if we were coming from the
user_info_popover and then built the dialog widget accordingly.
However, with this new change, we no longer need to build the
dialog widget. Therefore, removed that part and now just pass
the container of the 'user profile modal' to get the content.
Previously, for deactivation, we used to have a separate dialog
widget. But now, since we have a dedicated function to handle
this case, refactored the deactivation code to use the
'confirm_deactivation' function.
Additionally, created two new functions to handle the loading
spinner. Since we will need these functions in the future for
the "Manage Bot" modal, we marked them as exported.
"Since we do not want to show the 'Manage User' tab to the user
looking at their own profile, in the 'can_manage_user' function
that we use to render the 'Manage User' tab, we check if the user
profile popover belongs to the same user. If it does, we set it to
'false' instead of 'true,' ensuring that the 'Manage User' tab is
not visible.
Added a new tab in the user profile modal 'manage user'.
Fixes: #21806
2023-09-09 12:42:04 +02:00
|
|
|
const can_manage_profile =
|
2023-07-20 13:50:04 +02:00
|
|
|
(people.can_admin_user(user) || page_params.is_admin) &&
|
|
|
|
!user.is_system_bot &&
|
settings_users: Migrate manage user modal to full profile modal.
This commit migrates the "manage user" modal to the "Full Profile"
modal. Refactored the show_edit_user_info_modal function since
earlier, we used to have a separate "Manage User" modal.
Consequently, we checked if we were coming from the
user_info_popover and then built the dialog widget accordingly.
However, with this new change, we no longer need to build the
dialog widget. Therefore, removed that part and now just pass
the container of the 'user profile modal' to get the content.
Previously, for deactivation, we used to have a separate dialog
widget. But now, since we have a dedicated function to handle
this case, refactored the deactivation code to use the
'confirm_deactivation' function.
Additionally, created two new functions to handle the loading
spinner. Since we will need these functions in the future for
the "Manage Bot" modal, we marked them as exported.
"Since we do not want to show the 'Manage User' tab to the user
looking at their own profile, in the 'can_manage_user' function
that we use to render the 'Manage User' tab, we check if the user
profile popover belongs to the same user. If it does, we set it to
'false' instead of 'true,' ensuring that the 'Manage User' tab is
not visible.
Added a new tab in the user profile modal 'manage user'.
Fixes: #21806
2023-09-09 12:42:04 +02:00
|
|
|
!people.is_my_user_id(user.user_id);
|
2021-06-23 20:48:49 +02:00
|
|
|
const args = {
|
2021-06-24 13:15:57 +02:00
|
|
|
user_id: user.user_id,
|
2021-06-23 20:48:49 +02:00
|
|
|
full_name: user.full_name,
|
2021-10-26 15:43:39 +02:00
|
|
|
email: user.delivery_email,
|
2021-06-23 20:48:49 +02:00
|
|
|
profile_data,
|
2021-11-06 07:23:26 +01:00
|
|
|
user_avatar: people.medium_avatar_url_for_person(user),
|
2021-06-23 20:48:49 +02:00
|
|
|
is_me: people.is_current_user(user.email),
|
2022-08-24 13:46:25 +02:00
|
|
|
is_bot: user.is_bot,
|
2023-01-08 18:08:49 +01:00
|
|
|
date_joined: timerender.get_localized_date_or_time_for_format(
|
|
|
|
parseISO(user.date_joined),
|
|
|
|
"dayofyear_year",
|
|
|
|
),
|
2022-06-05 16:37:04 +02:00
|
|
|
user_circle_class: buddy_data.get_user_circle_class(user.user_id),
|
2021-06-23 20:48:49 +02:00
|
|
|
last_seen: buddy_data.user_last_seen_time_status(user.user_id),
|
|
|
|
user_time: people.get_user_time(user.user_id),
|
|
|
|
user_type: people.get_user_type(user.user_id),
|
|
|
|
user_is_guest: user.is_guest,
|
2023-09-08 19:37:58 +02:00
|
|
|
show_user_subscribe_widget,
|
2021-06-23 20:48:49 +02:00
|
|
|
};
|
|
|
|
|
2022-08-24 13:46:25 +02:00
|
|
|
if (user.is_bot) {
|
|
|
|
const is_system_bot = user.is_system_bot;
|
|
|
|
const bot_owner_id = user.bot_owner_id;
|
|
|
|
if (is_system_bot) {
|
|
|
|
args.is_system_bot = is_system_bot;
|
|
|
|
} else if (bot_owner_id) {
|
|
|
|
const bot_owner = people.get_by_user_id(bot_owner_id);
|
|
|
|
args.bot_owner = bot_owner;
|
|
|
|
}
|
|
|
|
args.bot_type = settings_bots.type_id_to_string(user.bot_type);
|
|
|
|
}
|
|
|
|
|
2021-06-23 20:48:49 +02:00
|
|
|
$("#user-profile-modal-holder").html(render_user_profile_modal(args));
|
2022-07-23 00:15:37 +02:00
|
|
|
overlays.open_modal("user-profile-modal", {autoremove: true});
|
2021-06-23 20:48:49 +02:00
|
|
|
$(".tabcontent").hide();
|
2022-08-24 10:54:02 +02:00
|
|
|
|
|
|
|
let default_tab = 0;
|
settings_users: Migrate manage user modal to full profile modal.
This commit migrates the "manage user" modal to the "Full Profile"
modal. Refactored the show_edit_user_info_modal function since
earlier, we used to have a separate "Manage User" modal.
Consequently, we checked if we were coming from the
user_info_popover and then built the dialog widget accordingly.
However, with this new change, we no longer need to build the
dialog widget. Therefore, removed that part and now just pass
the container of the 'user profile modal' to get the content.
Previously, for deactivation, we used to have a separate dialog
widget. But now, since we have a dedicated function to handle
this case, refactored the deactivation code to use the
'confirm_deactivation' function.
Additionally, created two new functions to handle the loading
spinner. Since we will need these functions in the future for
the "Manage Bot" modal, we marked them as exported.
"Since we do not want to show the 'Manage User' tab to the user
looking at their own profile, in the 'can_manage_user' function
that we use to render the 'Manage User' tab, we check if the user
profile popover belongs to the same user. If it does, we set it to
'false' instead of 'true,' ensuring that the 'Manage User' tab is
not visible.
Added a new tab in the user profile modal 'manage user'.
Fixes: #21806
2023-09-09 12:42:04 +02:00
|
|
|
|
2022-08-24 10:54:02 +02:00
|
|
|
if (default_tab_key === "user-profile-streams-tab") {
|
|
|
|
default_tab = 1;
|
settings_users: Migrate manage user modal to full profile modal.
This commit migrates the "manage user" modal to the "Full Profile"
modal. Refactored the show_edit_user_info_modal function since
earlier, we used to have a separate "Manage User" modal.
Consequently, we checked if we were coming from the
user_info_popover and then built the dialog widget accordingly.
However, with this new change, we no longer need to build the
dialog widget. Therefore, removed that part and now just pass
the container of the 'user profile modal' to get the content.
Previously, for deactivation, we used to have a separate dialog
widget. But now, since we have a dedicated function to handle
this case, refactored the deactivation code to use the
'confirm_deactivation' function.
Additionally, created two new functions to handle the loading
spinner. Since we will need these functions in the future for
the "Manage Bot" modal, we marked them as exported.
"Since we do not want to show the 'Manage User' tab to the user
looking at their own profile, in the 'can_manage_user' function
that we use to render the 'Manage User' tab, we check if the user
profile popover belongs to the same user. If it does, we set it to
'false' instead of 'true,' ensuring that the 'Manage User' tab is
not visible.
Added a new tab in the user profile modal 'manage user'.
Fixes: #21806
2023-09-09 12:42:04 +02:00
|
|
|
} else if (default_tab_key === "manage-profile-tab") {
|
|
|
|
default_tab = 3;
|
2022-08-24 10:54:02 +02:00
|
|
|
}
|
|
|
|
|
2021-06-23 20:48:49 +02:00
|
|
|
const opts = {
|
2022-08-24 10:54:02 +02:00
|
|
|
selected: default_tab,
|
2021-06-23 20:48:49 +02:00
|
|
|
child_wants_focus: true,
|
|
|
|
values: [
|
|
|
|
{label: $t({defaultMessage: "Profile"}), key: "profile-tab"},
|
2021-07-02 21:25:50 +02:00
|
|
|
{label: $t({defaultMessage: "Streams"}), key: "user-profile-streams-tab"},
|
2021-07-02 21:38:15 +02:00
|
|
|
{label: $t({defaultMessage: "User groups"}), key: "user-profile-groups-tab"},
|
2021-06-23 20:48:49 +02:00
|
|
|
],
|
2023-06-29 21:59:08 +02:00
|
|
|
callback(_name, key) {
|
2021-06-23 20:48:49 +02:00
|
|
|
$(".tabcontent").hide();
|
2023-04-01 01:42:40 +02:00
|
|
|
$(`#${CSS.escape(key)}`).show();
|
2021-06-23 20:48:49 +02:00
|
|
|
switch (key) {
|
2022-09-11 15:14:06 +02:00
|
|
|
case "profile-tab":
|
2023-07-20 12:06:58 +02:00
|
|
|
$("#user-profile-modal .modal__footer").hide();
|
2022-09-11 15:14:06 +02:00
|
|
|
initialize_user_type_fields(user);
|
|
|
|
break;
|
2021-07-02 21:38:15 +02:00
|
|
|
case "user-profile-groups-tab":
|
2021-06-23 20:48:49 +02:00
|
|
|
render_user_group_list(groups_of_user, user);
|
|
|
|
break;
|
2021-07-02 21:25:50 +02:00
|
|
|
case "user-profile-streams-tab":
|
2023-09-08 19:37:58 +02:00
|
|
|
if (show_user_subscribe_widget) {
|
|
|
|
render_user_profile_subscribe_widget();
|
|
|
|
}
|
2021-06-23 20:48:49 +02:00
|
|
|
render_user_stream_list(user_streams, user);
|
|
|
|
break;
|
settings_users: Migrate manage user modal to full profile modal.
This commit migrates the "manage user" modal to the "Full Profile"
modal. Refactored the show_edit_user_info_modal function since
earlier, we used to have a separate "Manage User" modal.
Consequently, we checked if we were coming from the
user_info_popover and then built the dialog widget accordingly.
However, with this new change, we no longer need to build the
dialog widget. Therefore, removed that part and now just pass
the container of the 'user profile modal' to get the content.
Previously, for deactivation, we used to have a separate dialog
widget. But now, since we have a dedicated function to handle
this case, refactored the deactivation code to use the
'confirm_deactivation' function.
Additionally, created two new functions to handle the loading
spinner. Since we will need these functions in the future for
the "Manage Bot" modal, we marked them as exported.
"Since we do not want to show the 'Manage User' tab to the user
looking at their own profile, in the 'can_manage_user' function
that we use to render the 'Manage User' tab, we check if the user
profile popover belongs to the same user. If it does, we set it to
'false' instead of 'true,' ensuring that the 'Manage User' tab is
not visible.
Added a new tab in the user profile modal 'manage user'.
Fixes: #21806
2023-09-09 12:42:04 +02:00
|
|
|
case "manage-profile-tab":
|
|
|
|
render_manage_profile_content(user);
|
|
|
|
break;
|
2021-06-23 20:48:49 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
settings_users: Migrate manage user modal to full profile modal.
This commit migrates the "manage user" modal to the "Full Profile"
modal. Refactored the show_edit_user_info_modal function since
earlier, we used to have a separate "Manage User" modal.
Consequently, we checked if we were coming from the
user_info_popover and then built the dialog widget accordingly.
However, with this new change, we no longer need to build the
dialog widget. Therefore, removed that part and now just pass
the container of the 'user profile modal' to get the content.
Previously, for deactivation, we used to have a separate dialog
widget. But now, since we have a dedicated function to handle
this case, refactored the deactivation code to use the
'confirm_deactivation' function.
Additionally, created two new functions to handle the loading
spinner. Since we will need these functions in the future for
the "Manage Bot" modal, we marked them as exported.
"Since we do not want to show the 'Manage User' tab to the user
looking at their own profile, in the 'can_manage_user' function
that we use to render the 'Manage User' tab, we check if the user
profile popover belongs to the same user. If it does, we set it to
'false' instead of 'true,' ensuring that the 'Manage User' tab is
not visible.
Added a new tab in the user profile modal 'manage user'.
Fixes: #21806
2023-09-09 12:42:04 +02:00
|
|
|
if (can_manage_profile) {
|
2023-07-20 13:50:04 +02:00
|
|
|
const manage_profile_label = user.is_bot
|
|
|
|
? $t({defaultMessage: "Manage bot"})
|
|
|
|
: $t({defaultMessage: "Manage user"});
|
settings_users: Migrate manage user modal to full profile modal.
This commit migrates the "manage user" modal to the "Full Profile"
modal. Refactored the show_edit_user_info_modal function since
earlier, we used to have a separate "Manage User" modal.
Consequently, we checked if we were coming from the
user_info_popover and then built the dialog widget accordingly.
However, with this new change, we no longer need to build the
dialog widget. Therefore, removed that part and now just pass
the container of the 'user profile modal' to get the content.
Previously, for deactivation, we used to have a separate dialog
widget. But now, since we have a dedicated function to handle
this case, refactored the deactivation code to use the
'confirm_deactivation' function.
Additionally, created two new functions to handle the loading
spinner. Since we will need these functions in the future for
the "Manage Bot" modal, we marked them as exported.
"Since we do not want to show the 'Manage User' tab to the user
looking at their own profile, in the 'can_manage_user' function
that we use to render the 'Manage User' tab, we check if the user
profile popover belongs to the same user. If it does, we set it to
'false' instead of 'true,' ensuring that the 'Manage User' tab is
not visible.
Added a new tab in the user profile modal 'manage user'.
Fixes: #21806
2023-09-09 12:42:04 +02:00
|
|
|
const manage_profile_tab = {
|
2023-07-20 13:50:04 +02:00
|
|
|
label: manage_profile_label,
|
settings_users: Migrate manage user modal to full profile modal.
This commit migrates the "manage user" modal to the "Full Profile"
modal. Refactored the show_edit_user_info_modal function since
earlier, we used to have a separate "Manage User" modal.
Consequently, we checked if we were coming from the
user_info_popover and then built the dialog widget accordingly.
However, with this new change, we no longer need to build the
dialog widget. Therefore, removed that part and now just pass
the container of the 'user profile modal' to get the content.
Previously, for deactivation, we used to have a separate dialog
widget. But now, since we have a dedicated function to handle
this case, refactored the deactivation code to use the
'confirm_deactivation' function.
Additionally, created two new functions to handle the loading
spinner. Since we will need these functions in the future for
the "Manage Bot" modal, we marked them as exported.
"Since we do not want to show the 'Manage User' tab to the user
looking at their own profile, in the 'can_manage_user' function
that we use to render the 'Manage User' tab, we check if the user
profile popover belongs to the same user. If it does, we set it to
'false' instead of 'true,' ensuring that the 'Manage User' tab is
not visible.
Added a new tab in the user profile modal 'manage user'.
Fixes: #21806
2023-09-09 12:42:04 +02:00
|
|
|
key: "manage-profile-tab",
|
|
|
|
};
|
|
|
|
opts.values.push(manage_profile_tab);
|
|
|
|
}
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
const $elem = components.toggle(opts).get();
|
|
|
|
$elem.addClass("large allow-overflow");
|
|
|
|
$("#tab-toggle").append($elem);
|
2023-09-08 19:37:58 +02:00
|
|
|
if (show_user_subscribe_widget) {
|
2023-09-08 16:35:13 +02:00
|
|
|
reset_subscribe_widget();
|
2023-09-08 19:37:58 +02:00
|
|
|
}
|
2021-06-23 20:48:49 +02:00
|
|
|
}
|
|
|
|
|
2021-06-30 23:07:02 +02:00
|
|
|
function handle_remove_stream_subscription(target_user_id, sub, success, failure) {
|
|
|
|
if (people.is_my_user_id(target_user_id)) {
|
|
|
|
// Self unsubscribe.
|
|
|
|
channel.del({
|
|
|
|
url: "/json/users/me/subscriptions",
|
|
|
|
data: {subscriptions: JSON.stringify([sub.name])},
|
|
|
|
success,
|
|
|
|
error: failure,
|
|
|
|
});
|
|
|
|
} else {
|
2022-02-21 15:28:56 +01:00
|
|
|
subscriber_api.remove_user_id_from_stream(target_user_id, sub, success, failure);
|
2021-06-30 23:07:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-23 20:48:49 +02:00
|
|
|
export function register_click_handlers() {
|
|
|
|
$("body").on("click", ".info_popover_actions .view_full_user_profile", (e) => {
|
|
|
|
const user_id = popovers.elem_to_user_id($(e.target).parents("ul"));
|
|
|
|
const user = people.get_by_user_id(user_id);
|
|
|
|
show_user_profile(user);
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
|
2023-09-08 19:37:58 +02:00
|
|
|
$("body").on("click", "#user-profile-modal .add-subscription-button", (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
const stream_id = Number.parseInt(user_profile_subscribe_widget.value(), 10);
|
|
|
|
const sub = sub_store.get(stream_id);
|
|
|
|
const target_user_id = Number.parseInt($("#user-profile-modal").attr("data-user-id"), 10);
|
|
|
|
const $alert_box = $("#user-profile-streams-tab .stream_list_info");
|
|
|
|
function addition_success(data) {
|
|
|
|
if (Object.keys(data.subscribed).length > 0) {
|
2023-09-08 16:35:13 +02:00
|
|
|
reset_subscribe_widget();
|
2023-09-08 19:37:58 +02:00
|
|
|
ui_report.success(
|
|
|
|
$t_html({defaultMessage: "Subscribed successfully!"}),
|
|
|
|
$alert_box,
|
|
|
|
1200,
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
ui_report.client_error(
|
|
|
|
$t_html({defaultMessage: "Already subscribed."}),
|
|
|
|
$alert_box,
|
|
|
|
1200,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function addition_failure(xhr) {
|
|
|
|
ui_report.error("", xhr, $alert_box, 1200);
|
|
|
|
}
|
|
|
|
subscriber_api.add_user_ids_to_stream(
|
|
|
|
[target_user_id],
|
|
|
|
sub,
|
|
|
|
addition_success,
|
|
|
|
addition_failure,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-06-30 23:07:02 +02:00
|
|
|
$("body").on("click", "#user-profile-modal .remove-subscription-button", (e) => {
|
|
|
|
e.preventDefault();
|
2022-01-25 11:36:19 +01:00
|
|
|
const $stream_row = $(e.currentTarget).closest("[data-stream-id]");
|
|
|
|
const stream_id = Number.parseInt($stream_row.attr("data-stream-id"), 10);
|
2021-06-30 23:07:02 +02:00
|
|
|
const sub = sub_store.get(stream_id);
|
2023-09-10 19:47:48 +02:00
|
|
|
const target_user_id = Number.parseInt($("#user-profile-modal").attr("data-user-id"), 10);
|
2022-01-25 11:36:19 +01:00
|
|
|
const $alert_box = $("#user-profile-streams-tab .stream_list_info");
|
2021-06-30 23:07:02 +02:00
|
|
|
|
|
|
|
function removal_success(data) {
|
|
|
|
if (data.removed.length > 0) {
|
|
|
|
ui_report.success(
|
|
|
|
$t_html({defaultMessage: "Unsubscribed successfully!"}),
|
2022-01-25 11:36:19 +01:00
|
|
|
$alert_box,
|
2021-06-30 23:07:02 +02:00
|
|
|
1200,
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
ui_report.client_error(
|
|
|
|
$t_html({defaultMessage: "Already not subscribed."}),
|
2022-01-25 11:36:19 +01:00
|
|
|
$alert_box,
|
2021-06-30 23:07:02 +02:00
|
|
|
1200,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function removal_failure() {
|
|
|
|
let error_message;
|
|
|
|
if (people.is_my_user_id(target_user_id)) {
|
|
|
|
error_message = $t(
|
|
|
|
{defaultMessage: "Error in unsubscribing from #{stream_name}"},
|
|
|
|
{stream_name: sub.name},
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
error_message = $t(
|
|
|
|
{defaultMessage: "Error removing user from #{stream_name}"},
|
|
|
|
{stream_name: sub.name},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
ui_report.client_error(error_message, $alert_box, 1200);
|
2021-06-30 23:07:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (sub.invite_only && people.is_my_user_id(target_user_id)) {
|
2022-03-01 19:14:26 +01:00
|
|
|
const new_hash = hash_util.stream_edit_url(sub);
|
2021-06-30 23:07:02 +02:00
|
|
|
hide_user_profile();
|
|
|
|
browser_history.go_to_location(new_hash);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
handle_remove_stream_subscription(target_user_id, sub, removal_success, removal_failure);
|
|
|
|
});
|
|
|
|
|
2021-06-30 22:17:19 +02:00
|
|
|
$("body").on("click", "#user-profile-modal #clear_stream_search", (e) => {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $input = $("#user-profile-streams-tab .stream-search");
|
|
|
|
$input.val("");
|
2021-06-30 22:17:19 +02:00
|
|
|
|
|
|
|
// This is a hack to rerender complete
|
|
|
|
// stream list once the text is cleared.
|
2022-01-25 11:36:19 +01:00
|
|
|
$input.trigger("input");
|
2021-06-30 22:17:19 +02:00
|
|
|
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
2021-06-23 20:48:49 +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. */
|
2023-02-11 11:06:47 +01:00
|
|
|
$("body").on("click", "#user-profile-modal #name .user_profile_edit_button", () => {
|
2021-06-23 20:48:49 +02:00
|
|
|
hide_user_profile();
|
|
|
|
});
|
|
|
|
|
|
|
|
$("body").on("click", "#user-profile-modal .stream_list_item", () => {
|
|
|
|
hide_user_profile();
|
|
|
|
});
|
2021-06-30 22:17:19 +02:00
|
|
|
|
2021-07-02 21:25:50 +02:00
|
|
|
$("body").on("input", "#user-profile-streams-tab .stream-search", () => {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $input = $("#user-profile-streams-tab .stream-search");
|
|
|
|
if ($input.val().trim().length > 0) {
|
2021-07-02 21:25:50 +02:00
|
|
|
$("#user-profile-streams-tab #clear_stream_search").show();
|
2022-01-25 11:36:19 +01:00
|
|
|
$input.css("margin-right", "-20px");
|
2021-06-30 22:17:19 +02:00
|
|
|
} else {
|
2021-07-02 21:25:50 +02:00
|
|
|
$("#user-profile-streams-tab #clear_stream_search").hide();
|
2022-01-25 11:36:19 +01:00
|
|
|
$input.css("margin-right", "0");
|
2021-06-30 22:17:19 +02:00
|
|
|
}
|
|
|
|
});
|
2021-06-23 20:48:49 +02:00
|
|
|
}
|