2017-01-21 16:49:27 +01:00
|
|
|
// This module is kind of small, but it will help us keep
|
|
|
|
// server_events.js simple while breaking some circular
|
|
|
|
// dependencies that existed when this code was in people.js.
|
|
|
|
// (We should do bot updates here too.)
|
2021-03-11 05:43:45 +01:00
|
|
|
import $ from "jquery";
|
|
|
|
|
2021-02-28 01:14:05 +01:00
|
|
|
import * as activity from "./activity";
|
2021-03-16 23:38:59 +01:00
|
|
|
import * as blueslip from "./blueslip";
|
2021-02-28 01:14:05 +01:00
|
|
|
import * as compose from "./compose";
|
|
|
|
import * as gear_menu from "./gear_menu";
|
|
|
|
import * as message_live_update from "./message_live_update";
|
|
|
|
import * as narrow_state from "./narrow_state";
|
2021-03-25 22:35:45 +01:00
|
|
|
import {page_params} from "./page_params";
|
2021-02-28 01:14:05 +01:00
|
|
|
import * as people from "./people";
|
|
|
|
import * as pm_list from "./pm_list";
|
2021-02-28 01:18:00 +01:00
|
|
|
import * as settings_account from "./settings_account";
|
2021-02-28 01:14:05 +01:00
|
|
|
import * as settings_config from "./settings_config";
|
2021-02-28 01:21:57 +01:00
|
|
|
import * as settings_linkifiers from "./settings_linkifiers";
|
2021-02-28 01:20:46 +01:00
|
|
|
import * as settings_org from "./settings_org";
|
2021-02-28 21:34:05 +01:00
|
|
|
import * as settings_profile_fields from "./settings_profile_fields";
|
2021-09-16 19:18:39 +02:00
|
|
|
import * as settings_realm_user_settings_defaults from "./settings_realm_user_settings_defaults";
|
2021-02-28 01:21:35 +01:00
|
|
|
import * as settings_streams from "./settings_streams";
|
2021-02-28 01:21:11 +01:00
|
|
|
import * as settings_users from "./settings_users";
|
2021-02-28 01:14:05 +01:00
|
|
|
|
|
|
|
export const update_person = function update(person) {
|
2020-02-05 14:30:59 +01:00
|
|
|
const person_obj = people.get_by_user_id(person.user_id);
|
2017-01-21 16:49:27 +01:00
|
|
|
|
|
|
|
if (!person_obj) {
|
2017-08-17 01:17:17 +02:00
|
|
|
blueslip.error("Got update_person event for unexpected user " + person.user_id);
|
2017-01-21 16:49:27 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-24 08:23:22 +01:00
|
|
|
if (Object.hasOwn(person, "new_email")) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const user_id = person.user_id;
|
|
|
|
const new_email = person.new_email;
|
2017-02-04 17:51:05 +01:00
|
|
|
|
2017-04-25 15:25:31 +02:00
|
|
|
narrow_state.update_email(user_id, new_email);
|
2017-02-04 17:51:05 +01:00
|
|
|
compose.update_email(user_id, new_email);
|
|
|
|
|
|
|
|
if (people.is_my_user_id(person.user_id)) {
|
2018-08-02 08:54:28 +02:00
|
|
|
page_params.email = new_email;
|
2017-02-04 17:51:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
people.update_email(user_id, new_email);
|
|
|
|
}
|
|
|
|
|
2022-01-24 08:23:22 +01:00
|
|
|
if (Object.hasOwn(person, "delivery_email")) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const delivery_email = person.delivery_email;
|
2018-08-02 08:54:28 +02:00
|
|
|
|
|
|
|
if (people.is_my_user_id(person.user_id)) {
|
|
|
|
settings_account.update_email(delivery_email);
|
|
|
|
page_params.delivery_email = delivery_email;
|
2022-01-05 18:08:47 +01:00
|
|
|
settings_account.hide_confirm_email_banner();
|
2018-08-02 08:54:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-24 08:23:22 +01:00
|
|
|
if (Object.hasOwn(person, "full_name")) {
|
2017-01-21 16:49:27 +01:00
|
|
|
people.set_full_name(person_obj, person.full_name);
|
|
|
|
|
2017-04-08 20:08:35 +02:00
|
|
|
settings_users.update_user_data(person.user_id, person);
|
2017-01-21 16:49:27 +01:00
|
|
|
activity.redraw();
|
2017-01-24 19:12:21 +01:00
|
|
|
message_live_update.update_user_full_name(person.user_id, person.full_name);
|
2017-01-25 16:23:22 +01:00
|
|
|
pm_list.update_private_messages();
|
2018-02-02 01:24:26 +01:00
|
|
|
if (people.is_my_user_id(person.user_id)) {
|
2018-09-25 22:34:22 +02:00
|
|
|
page_params.full_name = person.full_name;
|
2018-02-02 01:24:26 +01:00
|
|
|
settings_account.update_full_name(person.full_name);
|
|
|
|
}
|
2017-01-21 16:49:27 +01:00
|
|
|
}
|
|
|
|
|
2022-01-24 08:23:22 +01:00
|
|
|
if (Object.hasOwn(person, "role")) {
|
2021-04-29 18:42:49 +02:00
|
|
|
person_obj.role = person.role;
|
2020-06-03 23:30:34 +02:00
|
|
|
person_obj.is_owner = person.role === settings_config.user_role_values.owner.code;
|
2020-07-15 00:34:28 +02:00
|
|
|
person_obj.is_admin =
|
|
|
|
person.role === settings_config.user_role_values.admin.code || person_obj.is_owner;
|
2020-05-30 21:43:19 +02:00
|
|
|
person_obj.is_guest = person.role === settings_config.user_role_values.guest.code;
|
2021-04-22 21:37:04 +02:00
|
|
|
person_obj.is_moderator = person.role === settings_config.user_role_values.moderator.code;
|
2018-08-02 16:09:12 +02:00
|
|
|
settings_users.update_user_data(person.user_id, person);
|
2017-01-21 16:49:27 +01:00
|
|
|
|
2020-06-03 23:30:34 +02:00
|
|
|
if (people.is_my_user_id(person.user_id) && page_params.is_owner !== person_obj.is_owner) {
|
|
|
|
page_params.is_owner = person_obj.is_owner;
|
2020-06-11 13:26:27 +02:00
|
|
|
settings_org.maybe_disable_widgets();
|
2020-06-03 23:30:34 +02:00
|
|
|
}
|
|
|
|
|
2020-05-30 21:43:19 +02:00
|
|
|
if (people.is_my_user_id(person.user_id) && page_params.is_admin !== person_obj.is_admin) {
|
|
|
|
page_params.is_admin = person_obj.is_admin;
|
2018-12-06 18:41:56 +01:00
|
|
|
gear_menu.update_org_settings_menu_item();
|
2018-12-17 21:28:25 +01:00
|
|
|
settings_linkifiers.maybe_disable_widgets();
|
2018-12-08 18:16:37 +01:00
|
|
|
settings_org.maybe_disable_widgets();
|
|
|
|
settings_profile_fields.maybe_disable_widgets();
|
|
|
|
settings_streams.maybe_disable_widgets();
|
2021-09-16 19:18:39 +02:00
|
|
|
settings_realm_user_settings_defaults.maybe_disable_widgets();
|
2017-01-21 16:49:27 +01:00
|
|
|
}
|
2021-04-22 21:37:04 +02:00
|
|
|
|
|
|
|
if (
|
|
|
|
people.is_my_user_id(person.user_id) &&
|
|
|
|
page_params.is_moderator !== person_obj.is_moderator
|
|
|
|
) {
|
|
|
|
page_params.is_moderator = person_obj.is_moderator;
|
|
|
|
}
|
2017-01-21 16:49:27 +01:00
|
|
|
}
|
|
|
|
|
2022-01-24 08:23:22 +01:00
|
|
|
if (Object.hasOwn(person, "is_billing_admin")) {
|
2021-05-28 12:51:50 +02:00
|
|
|
person_obj.is_billing_admin = person.is_billing_admin;
|
|
|
|
if (people.is_my_user_id(person.user_id)) {
|
|
|
|
page_params.is_billing_admin = person_obj.is_billing_admin;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-24 08:23:22 +01:00
|
|
|
if (Object.hasOwn(person, "avatar_url")) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const url = person.avatar_url;
|
2017-01-21 16:49:27 +01:00
|
|
|
person_obj.avatar_url = url;
|
2020-04-07 20:09:30 +02:00
|
|
|
person_obj.avatar_version = person.avatar_version;
|
2017-01-21 16:49:27 +01:00
|
|
|
|
|
|
|
if (people.is_my_user_id(person.user_id)) {
|
2017-04-27 00:04:11 +02:00
|
|
|
page_params.avatar_source = person.avatar_source;
|
|
|
|
page_params.avatar_url = url;
|
|
|
|
page_params.avatar_url_medium = person.avatar_url_medium;
|
2020-06-15 07:38:56 +02:00
|
|
|
$("#user-avatar-upload-widget .image-block").attr("src", person.avatar_url_medium);
|
2017-01-21 16:49:27 +01:00
|
|
|
}
|
|
|
|
|
2017-02-23 00:31:34 +01:00
|
|
|
message_live_update.update_avatar(person_obj.user_id, person.avatar_url);
|
2017-01-21 16:49:27 +01:00
|
|
|
}
|
2017-04-02 20:57:27 +02:00
|
|
|
|
2022-01-24 08:23:22 +01:00
|
|
|
if (Object.hasOwn(person, "custom_profile_field")) {
|
2018-03-10 14:41:44 +01:00
|
|
|
people.set_custom_profile_field_data(person.user_id, person.custom_profile_field);
|
|
|
|
}
|
|
|
|
|
2022-01-24 08:23:22 +01:00
|
|
|
if (Object.hasOwn(person, "timezone")) {
|
2018-05-06 21:43:17 +02:00
|
|
|
person_obj.timezone = person.timezone;
|
2017-04-02 20:57:27 +02:00
|
|
|
}
|
2019-05-21 18:47:30 +02:00
|
|
|
|
2022-01-24 08:23:22 +01:00
|
|
|
if (Object.hasOwn(person, "bot_owner_id")) {
|
2019-05-21 18:47:30 +02:00
|
|
|
person_obj.bot_owner_id = person.bot_owner_id;
|
|
|
|
}
|
2017-01-21 16:49:27 +01:00
|
|
|
};
|