From 21ac1fb32c356e7645c201b5a71e7354a53f9f2f Mon Sep 17 00:00:00 2001 From: Aman Agrawal Date: Wed, 10 Jun 2020 17:12:13 +0530 Subject: [PATCH] register: Refactor to pass client_capabilities directly. We extract values from client_capabilities directly in do_events_register where we decide how to process the extracted variables. --- zerver/lib/events.py | 4 +++- zerver/views/events_register.py | 3 +-- zerver/views/home.py | 6 +++++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/zerver/lib/events.py b/zerver/lib/events.py index 018b18f55d..17642e1e0d 100644 --- a/zerver/lib/events.py +++ b/zerver/lib/events.py @@ -830,7 +830,7 @@ def do_events_register(user_profile: UserProfile, user_client: Client, queue_lifespan_secs: int = 0, all_public_streams: bool = False, include_subscribers: bool = True, - notification_settings_null: bool = False, + client_capabilities: Dict[str, bool] = {}, narrow: Iterable[Sequence[str]] = [], fetch_event_types: Optional[Iterable[str]] = None) -> Dict[str, Any]: # Technically we don't need to check this here because @@ -838,6 +838,8 @@ def do_events_register(user_profile: UserProfile, user_client: Client, # handling perspective to do it before contacting Tornado check_supported_events_narrow_filter(narrow) + notification_settings_null = client_capabilities.get('notification_settings_null', False) + if user_profile.realm.email_address_visibility != Realm.EMAIL_ADDRESS_VISIBILITY_EVERYONE: # If real email addresses are not available to the user, their # clients cannot compute gravatars, so we force-set it to false. diff --git a/zerver/views/events_register.py b/zerver/views/events_register.py index 32b3277877..cba94e6e9c 100644 --- a/zerver/views/events_register.py +++ b/zerver/views/events_register.py @@ -50,12 +50,11 @@ def events_register_backend( if client_capabilities is None: client_capabilities = {} - notification_settings_null = client_capabilities.get("notification_settings_null", False) ret = do_events_register(user_profile, request.client, apply_markdown, client_gravatar, slim_presence, event_types, queue_lifespan_secs, all_public_streams, narrow=narrow, include_subscribers=include_subscribers, - notification_settings_null=notification_settings_null, + client_capabilities=client_capabilities, fetch_event_types=fetch_event_types) return json_success(ret) diff --git a/zerver/views/home.py b/zerver/views/home.py index ff1c47f522..a4765165c5 100644 --- a/zerver/views/home.py +++ b/zerver/views/home.py @@ -189,10 +189,14 @@ def home_real(request: HttpRequest) -> HttpResponse: narrow, narrow_stream, narrow_topic = detect_narrowed_window(request, user_profile) + client_capabilities = { + 'notification_settings_null': True, + } + register_ret = do_events_register(user_profile, request.client, apply_markdown=True, client_gravatar=True, slim_presence=True, - notification_settings_null=True, + client_capabilities=client_capabilities, narrow=narrow) update_last_reminder(user_profile)