Support changing one's name without a reload.

(imported from commit 4e7aea017f016494e2674f11b96681e098816f2d)
This commit is contained in:
Tim Abbott
2013-07-16 15:32:33 -04:00
parent fd0d8799ca
commit 907bb154b1
2 changed files with 38 additions and 3 deletions

View File

@@ -729,6 +729,15 @@ def do_change_full_name(user_profile, full_name, log=True):
'user': user_profile.email, 'user': user_profile.email,
'full_name': full_name}) 'full_name': full_name})
notice = dict(event=dict(type="realm_user", op="update",
person=dict(email=user_profile.email,
full_name=user_profile.full_name)),
users=[up.id for up in
UserProfile.objects.select_related().filter(realm=user_profile.realm,
is_active=True)])
tornado_callbacks.send_notification(notice)
def do_create_realm(domain, restricted_to_domain=True): def do_create_realm(domain, restricted_to_domain=True):
realm = get_realm(domain) realm = get_realm(domain)
created = not realm created = not realm
@@ -1101,12 +1110,14 @@ def do_events_register(user_profile, user_client, apply_markdown=True,
elif event['type'] == "onboarding_steps": elif event['type'] == "onboarding_steps":
ret['onboarding_steps'] = event['steps'] ret['onboarding_steps'] = event['steps']
elif event['type'] == "realm_user": elif event['type'] == "realm_user":
if event['op'] == "add": # We handle update by just removing the old value and
ret['realm_users'].append(event['person']) # adding the new one.
elif event['op'] == "remove": if event['op'] == "remove" or event['op'] == "update":
person = event['person'] person = event['person']
ret['realm_users'] = filter(lambda p: p['email'] != person['email'], ret['realm_users'] = filter(lambda p: p['email'] != person['email'],
ret['realm_users']) ret['realm_users'])
if event['op'] == "add" or event['op'] == "update":
ret['realm_users'].append(event['person'])
elif event['type'] == "subscriptions": elif event['type'] == "subscriptions":
subscriptions_to_filter = set(sub.name.lower() for sub in event["subscriptions"]) subscriptions_to_filter = set(sub.name.lower() for sub in event["subscriptions"])
# We add the new subscriptions to the list of streams the # We add the new subscriptions to the list of streams the

View File

@@ -54,6 +54,28 @@ function remove_person(person) {
delete people_dict[person.email]; delete people_dict[person.email];
} }
function update_person(person) {
// Currently the only attribute that can change is full_name, so
// we just push out changes to that field. As we add more things
// that can change, this will need to either get complicated or be
// replaced by MVC
var i;
people_dict[person.email].full_name = person.full_name;
for (i = 0; i < page_params.people_list.length; i++) {
if (page_params.people_list[i].email === person.email) {
page_params.people_list[i].full_name = person.full_name;
break;
}
}
if (person.email === page_params.email) {
page_params.fullname = person.full_name;
$("#my_information .my_fullname").text(person.full_name);
}
activity.set_user_statuses([]);
// TODO: update sender names on messages
}
$(function () { $(function () {
$.each(page_params.people_list, function (idx, person) { $.each(page_params.people_list, function (idx, person) {
people_dict[person.email] = person; people_dict[person.email] = person;
@@ -793,6 +815,8 @@ function get_updates_success(data) {
add_person(event.person); add_person(event.person);
} else if (event.op === 'remove') { } else if (event.op === 'remove') {
remove_person(event.person); remove_person(event.person);
} else if (event.op === 'update') {
update_person(event.person);
} }
break; break;
case 'subscriptions': case 'subscriptions':