Files
zulip/static/js/user_events.js
Anders Kaseorg 28f3dfa284 js: Automatically convert var to let and const in most files.
This commit was originally automatically generated using `tools/lint
--only=eslint --fix`.  It was then modified by tabbott to contain only
changes to a set of files that are unlikely to result in significant
merge conflicts with any open pull request, excluding about 20 files.
His plan is to merge the remaining changes with more precise care,
potentially involving merging parts of conflicting pull requests
before running the `eslint --fix` operation.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2019-11-03 12:42:39 -08:00

97 lines
3.2 KiB
JavaScript

// 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.)
exports.update_person = function update(person) {
const person_obj = people.get_person_from_user_id(person.user_id);
if (!person_obj) {
blueslip.error("Got update_person event for unexpected user " + person.user_id);
return;
}
if (_.has(person, 'new_email')) {
const user_id = person.user_id;
const new_email = person.new_email;
narrow_state.update_email(user_id, new_email);
compose.update_email(user_id, new_email);
if (people.is_my_user_id(person.user_id)) {
page_params.email = new_email;
}
people.update_email(user_id, new_email);
}
if (_.has(person, 'delivery_email')) {
const delivery_email = person.delivery_email;
if (people.is_my_user_id(person.user_id)) {
settings_account.update_email(delivery_email);
page_params.delivery_email = delivery_email;
}
}
if (_.has(person, 'full_name')) {
people.set_full_name(person_obj, person.full_name);
settings_users.update_user_data(person.user_id, person);
activity.redraw();
message_live_update.update_user_full_name(person.user_id, person.full_name);
pm_list.update_private_messages();
if (people.is_my_user_id(person.user_id)) {
page_params.full_name = person.full_name;
settings_account.update_full_name(person.full_name);
}
}
if (_.has(person, 'is_admin')) {
person_obj.is_admin = person.is_admin;
settings_users.update_user_data(person.user_id, person);
if (people.is_my_user_id(person.user_id)) {
page_params.is_admin = person.is_admin;
gear_menu.update_org_settings_menu_item();
settings_linkifiers.maybe_disable_widgets();
settings_org.maybe_disable_widgets();
settings_profile_fields.maybe_disable_widgets();
settings_streams.maybe_disable_widgets();
}
}
if (_.has(person, 'is_guest')) {
person_obj.is_guest = person.is_guest;
settings_users.update_user_data(person.user_id, person);
}
if (_.has(person, 'avatar_url')) {
const url = person.avatar_url;
person_obj.avatar_url = url;
if (people.is_my_user_id(person.user_id)) {
page_params.avatar_source = person.avatar_source;
page_params.avatar_url = url;
page_params.avatar_url_medium = person.avatar_url_medium;
$("#user-avatar-block").attr("style", "background-image:url(" + person.avatar_url_medium + ")");
}
message_live_update.update_avatar(person_obj.user_id, person.avatar_url);
}
if (_.has(person, 'custom_profile_field')) {
people.set_custom_profile_field_data(person.user_id, person.custom_profile_field);
}
if (_.has(person, 'timezone')) {
person_obj.timezone = person.timezone;
}
if (_.has(person, 'bot_owner_id')) {
person_obj.bot_owner_id = person.bot_owner_id;
}
};
window.user_events = exports;