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.
This commit is contained in:
Aman Agrawal 2020-06-10 17:12:13 +05:30 committed by Tim Abbott
parent d97c891afe
commit 21ac1fb32c
3 changed files with 9 additions and 4 deletions

View File

@ -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.

View File

@ -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)

View File

@ -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)