2017-01-21 16:49:27 +01:00
|
|
|
var user_events = (function () {
|
|
|
|
|
|
|
|
var exports = {};
|
|
|
|
|
|
|
|
// 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) {
|
|
|
|
var person_obj = people.get_person_from_user_id(person.user_id);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-02-04 17:51:05 +01:00
|
|
|
if (_.has(person, 'new_email')) {
|
|
|
|
var user_id = person.user_id;
|
|
|
|
var new_email = person.new_email;
|
|
|
|
|
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)) {
|
2017-04-06 02:28:57 +02:00
|
|
|
settings_account.update_email(new_email);
|
2017-02-04 17:51:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
people.update_email(user_id, new_email);
|
|
|
|
}
|
|
|
|
|
2017-01-21 16:49:27 +01:00
|
|
|
if (_.has(person, 'full_name')) {
|
|
|
|
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)) {
|
|
|
|
settings_account.update_full_name(person.full_name);
|
|
|
|
}
|
2017-01-21 16:49:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (_.has(person, 'is_admin')) {
|
|
|
|
person_obj.is_admin = person.is_admin;
|
|
|
|
|
|
|
|
if (people.is_my_user_id(person.user_id)) {
|
|
|
|
page_params.is_admin = person.is_admin;
|
|
|
|
admin.show_or_hide_menu_item();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_.has(person, 'avatar_url')) {
|
2017-02-17 00:44:21 +01:00
|
|
|
var url = person.avatar_url;
|
2017-01-21 16:49:27 +01:00
|
|
|
person_obj.avatar_url = url;
|
|
|
|
|
|
|
|
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;
|
2018-03-13 18:24:14 +01:00
|
|
|
$("#user-avatar-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
|
|
|
|
2018-03-10 14:41:44 +01:00
|
|
|
if (_.has(person, 'custom_profile_field')) {
|
|
|
|
people.set_custom_profile_field_data(person.user_id, person.custom_profile_field);
|
|
|
|
}
|
|
|
|
|
2018-05-06 21:43:17 +02:00
|
|
|
if (_.has(person, 'timezone')) {
|
|
|
|
person_obj.timezone = person.timezone;
|
2017-04-02 20:57:27 +02:00
|
|
|
}
|
2017-01-21 16:49:27 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
return exports;
|
|
|
|
|
|
|
|
}());
|
|
|
|
if (typeof module !== 'undefined') {
|
|
|
|
module.exports = user_events;
|
|
|
|
}
|