status: Add away_user_ids to page_params.

(Also, any client that registers for 'user_status'
will see `away_user_ids`.)
This commit is contained in:
Steve Howell
2018-12-18 16:17:08 +00:00
committed by Tim Abbott
parent 423db23c36
commit a2614956d5
3 changed files with 39 additions and 4 deletions

View File

@@ -44,6 +44,7 @@ from zerver.lib.actions import (
get_available_notification_sounds,
)
from zerver.lib.user_groups import user_groups_in_realm_serialized
from zerver.lib.user_status import get_away_user_ids
from zerver.tornado.event_queue import request_event_queue, get_user_events
from zerver.models import Client, Message, Realm, UserPresence, UserProfile, CustomProfileFieldValue, \
get_user_profile_by_id, \
@@ -301,6 +302,9 @@ def fetch_initial_state_data(user_profile: UserProfile,
state[notification] = getattr(user_profile, notification)
state['available_notification_sounds'] = get_available_notification_sounds()
if want('user_status'):
state['away_user_ids'] = sorted(list(get_away_user_ids(realm_id=realm.id)))
if want('zulip_version'):
state['zulip_version'] = ZULIP_VERSION
@@ -670,6 +674,16 @@ def apply_event(state: Dict[str, Any],
elif event['op'] == 'remove':
state['realm_user_groups'] = [ug for ug in state['realm_user_groups']
if ug['id'] != event['group_id']]
elif event['type'] == 'user_status':
away_user_ids = set(state['away_user_ids'])
user_id = event['user_id']
if event['away']:
away_user_ids.add(user_id)
else:
away_user_ids.discard(user_id)
state['away_user_ids'] = sorted(list(away_user_ids))
else:
raise AssertionError("Unexpected event type %s" % (event['type'],))