custom profile data: Send event to active user on update.

On update of custom profile fields, send an event to all
active users of realm.
This commit is contained in:
YJDave
2018-03-10 19:11:44 +05:30
committed by Tim Abbott
parent 82c8d43209
commit 11c995b70f
5 changed files with 30 additions and 0 deletions

View File

@@ -191,6 +191,16 @@ initialize();
initialize(); initialize();
(function test_set_custom_profile_field_data() {
var person = people.get_by_email(me.email);
me.profile_data = {};
var field = {id: 3, name: 'Custom long field', type: 'text', value: 'Field value'};
people.set_custom_profile_field_data(person.user_id, {});
assert.deepEqual(person.profile_data, {});
people.set_custom_profile_field_data(person.user_id, field);
assert.equal(person.profile_data[field.id], 'Field value');
}());
(function test_get_rest_of_realm() { (function test_get_rest_of_realm() {
var alice1 = { var alice1 = {
email: 'alice1@example.com', email: 'alice1@example.com',

View File

@@ -137,4 +137,8 @@ initialize();
assert(!user_events.update_person({user_id: 29, full_name: 'Sir Isaac Newton'})); assert(!user_events.update_person({user_id: 29, full_name: 'Sir Isaac Newton'}));
assert.equal(error_msg, "Got update_person event for unexpected user 29"); assert.equal(error_msg, "Got update_person event for unexpected user 29");
me.profile_data = {};
user_events.update_person({user_id: me.user_id, custom_profile_field: {id: 3, value: 'Value'}});
person = people.get_by_email(me.email);
assert.equal(person.profile_data[3], 'Value');
}()); }());

View File

@@ -819,6 +819,14 @@ exports.set_full_name = function (person_obj, new_full_name) {
person_obj.full_name = new_full_name; person_obj.full_name = new_full_name;
}; };
exports.set_custom_profile_field_data = function (user_id, field) {
if (field.id === undefined) {
blueslip.error("Unknown field id " + field.id);
return;
}
people_by_user_id_dict.get(user_id).profile_data[field.id] = field.value;
};
exports.is_current_user = function (email) { exports.is_current_user = function (email) {
if (email === null || email === undefined) { if (email === null || email === undefined) {
return false; return false;

View File

@@ -64,6 +64,10 @@ exports.update_person = function update(person) {
message_live_update.update_avatar(person_obj.user_id, person.avatar_url); 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')) { if (_.has(person, 'timezone')) {
person_obj.timezone = person.timezone; person_obj.timezone = person.timezone;
} }

View File

@@ -4529,6 +4529,10 @@ def do_update_user_custom_profile_data(user_profile: UserProfile,
update_or_create(user_profile=user_profile, update_or_create(user_profile=user_profile,
field_id=field['id'], field_id=field['id'],
defaults={'value': field['value']}) defaults={'value': field['value']})
payload = dict(user_id=user_profile.id, custom_profile_field=dict(id=field['id'],
value=field['value']))
event = dict(type="realm_user", op="update", person=payload)
send_event(event, active_user_ids(user_profile.realm.id))
def do_send_create_user_group_event(user_group: UserGroup, members: List[UserProfile]) -> None: def do_send_create_user_group_event(user_group: UserGroup, members: List[UserProfile]) -> None:
event = dict(type="user_group", event = dict(type="user_group",