diff --git a/zephyr/lib/actions.py b/zephyr/lib/actions.py index f32fd1fd00..f15d36565a 100644 --- a/zephyr/lib/actions.py +++ b/zephyr/lib/actions.py @@ -59,7 +59,17 @@ def do_create_user(email, password, realm, full_name, short_name, 'short_name': short_name, 'user': email, 'domain': realm.domain}) - return create_user(email, password, realm, full_name, short_name, active) + user_profile = create_user(email, password, realm, full_name, short_name, active) + + notice = dict(event=dict(type="realm_user", op="add", + person=dict(email=user_profile.user.email, + full_name=user_profile.full_name)), + users=[up.id for up in + UserProfile.objects.select_related().filter(realm=user_profile.realm, + user__is_active=True)]) + tornado_callbacks.send_notification(notice) + return user_profile + def user_sessions(user): return [s for s in Session.objects.all() if s.get_decoded().get('_auth_user_id') == user.id] @@ -77,6 +87,15 @@ def do_deactivate(user_profile): 'user': user_profile.user.email, 'domain': user_profile.realm.domain}) + notice = dict(event=dict(type="realm_user", op="remove", + person=dict(email=user_profile.user.email, + full_name=user_profile.full_name)), + users=[up.id for up in + UserProfile.objects.select_related().filter(realm=user_profile.realm, + user__is_active=True)]) + tornado_callbacks.send_notification(notice) + + def do_change_user_email(user_profile, new_email): old_email = user_profile.user.email user_profile.user.email = new_email @@ -706,6 +725,12 @@ def do_events_register(user_profile, apply_markdown=True, event_types=None): ret['max_message_id'] = -1 if event_types is None or "pointer" in event_types: ret['pointer'] = user_profile.pointer + if event_types is None or "realm_user" in event_types: + ret['realm_users'] = [{'email' : profile.user.email, + 'full_name' : profile.full_name} + for profile in + UserProfile.objects.select_related().filter(realm=user_profile.realm, + user__is_active=True)] # Apply events that came in while we were fetching initial data events = get_user_events(user_profile, queue_id, -1) @@ -714,6 +739,13 @@ def do_events_register(user_profile, apply_markdown=True, event_types=None): ret['max_message_id'] = max(ret['max_message_id'], event['message']['id']) elif event['type'] == "pointer": ret['pointer'] = max(ret['pointer'], event['pointer']) + elif event['type'] == "realm_user": + if event['op'] == "add": + ret['realm_users'].append(simplejson.loads(event['person'])) + elif event['op'] == "remove": + person = simplejson.loads(event['person']) + ret['realm_users'] = filter(lambda p: p['email'] != person['email'], + ret['realm_users']) if events: ret['last_event_id'] = events[-1:]['id'] diff --git a/zephyr/tornado_callbacks.py b/zephyr/tornado_callbacks.py index a0f9f8f4cb..d1f9272bb3 100644 --- a/zephyr/tornado_callbacks.py +++ b/zephyr/tornado_callbacks.py @@ -259,8 +259,18 @@ def process_new_message(data): if 'stream_name' in data: stream_receive_message(data['realm_id'], data['stream_name'], message) +def process_event(data): + event = data['event'] + for user_profile_id in data['users']: + for client in get_client_descriptors_for_user(user_profile_id): + if client.accepts_event_type(event['type']): + client.add_event(event.copy()) + def process_notification(data): - if data['type'] == 'new_message': + if 'type' not in data: + # Generic event that doesn't need special handling + process_event(data) + elif data['type'] == 'new_message': process_new_message(data) elif data['type'] == 'pointer_update': update_pointer(data['user'], data['new_pointer']) diff --git a/zephyr/views.py b/zephyr/views.py index 2d22f179fa..c6a88de63f 100644 --- a/zephyr/views.py +++ b/zephyr/views.py @@ -417,16 +417,6 @@ def home(request): user_profile.pointer = register_ret['max_message_id'] user_profile.last_pointer_updater = request.session.session_key - # Populate personals autocomplete list based on everyone in your - # realm. Later we might want a 2-layer autocomplete, where we - # consider specially some sort of "buddy list" who e.g. you've - # talked to before, but for small organizations, the right list is - # everyone in your realm. - people = [{'email' : profile.user.email, - 'full_name' : profile.full_name} - for profile in - UserProfile.objects.select_related().filter(realm=user_profile.realm)] - # Pass parameters to the client-side JavaScript code. # These end up in a global JavaScript Object named 'page_params'. page_params = simplejson.encoder.JSONEncoderForHTML().encode(dict( @@ -434,7 +424,7 @@ def home(request): poll_timeout = settings.POLL_TIMEOUT, have_initial_messages = user_has_messages, stream_list = gather_subscriptions(user_profile), - people_list = people, + people_list = register_ret['realm_users'], initial_pointer = register_ret['pointer'], fullname = user_profile.full_name, email = user_profile.user.email,