mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	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:
		@@ -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'],))
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user