mirror of
https://github.com/zulip/zulip.git
synced 2025-11-01 12:33:40 +00:00
Use client_gratavar=True for users on in page_params.
This change affects realm_users and realm_non_active_users. Note that we still send full avatar urls in realm_user/add events, so apply_events has to do something mildly hacky to turn the avatar_url to None in that case. Fixing the event is probably not worth the trouble, as single urls are not bandwidth hogs; we only need this optimization for bulk data.
This commit is contained in:
@@ -15,7 +15,7 @@ session_engine = import_module(settings.SESSION_ENGINE)
|
||||
|
||||
from zerver.lib.alert_words import user_alert_words
|
||||
from zerver.lib.attachments import user_attachments
|
||||
from zerver.lib.avatar import avatar_url, avatar_url_from_dict
|
||||
from zerver.lib.avatar import avatar_url, get_avatar_field
|
||||
from zerver.lib.hotspots import get_next_hotspots
|
||||
from zerver.lib.integrations import EMBEDDED_BOTS
|
||||
from zerver.lib.message import (
|
||||
@@ -44,13 +44,22 @@ from zproject.backends import email_auth_enabled, password_auth_enabled
|
||||
from version import ZULIP_VERSION
|
||||
|
||||
|
||||
def get_raw_user_data(realm_id):
|
||||
# type: (int) -> Dict[int, Dict[str, Text]]
|
||||
def get_raw_user_data(realm_id, client_gravatar):
|
||||
# type: (int, bool) -> Dict[int, Dict[str, Text]]
|
||||
user_dicts = get_realm_user_dicts(realm_id)
|
||||
|
||||
def user_data(row):
|
||||
# type: (Dict[str, Any]) -> Dict[str, Any]
|
||||
avatar_url = avatar_url_from_dict(row)
|
||||
avatar_url = get_avatar_field(
|
||||
user_id=row['id'],
|
||||
realm_id= realm_id,
|
||||
email=row['email'],
|
||||
avatar_source=row['avatar_source'],
|
||||
avatar_version=row['avatar_version'],
|
||||
medium=False,
|
||||
client_gravatar=client_gravatar,
|
||||
)
|
||||
|
||||
is_admin = row['is_realm_admin']
|
||||
|
||||
return dict(
|
||||
@@ -169,7 +178,10 @@ def fetch_initial_state_data(user_profile, event_types, queue_id, client_gravata
|
||||
state['realm_filters'] = realm_filters_for_realm(user_profile.realm_id)
|
||||
|
||||
if want('realm_user'):
|
||||
state['raw_users'] = get_raw_user_data(user_profile.realm_id)
|
||||
state['raw_users'] = get_raw_user_data(
|
||||
realm_id=user_profile.realm_id,
|
||||
client_gravatar=client_gravatar,
|
||||
)
|
||||
state['avatar_source'] = user_profile.avatar_source
|
||||
state['avatar_url_medium'] = avatar_url(
|
||||
user_profile,
|
||||
@@ -243,9 +255,9 @@ def remove_message_id_from_unread_mgs(state, message_id):
|
||||
raw_unread['unmuted_stream_msgs'].discard(message_id)
|
||||
raw_unread['mentions'].discard(message_id)
|
||||
|
||||
def apply_events(state, events, user_profile, include_subscribers=True,
|
||||
def apply_events(state, events, user_profile, client_gravatar, include_subscribers=True,
|
||||
fetch_event_types=None):
|
||||
# type: (Dict[str, Any], Iterable[Dict[str, Any]], UserProfile, bool, Optional[Iterable[str]]) -> None
|
||||
# type: (Dict[str, Any], Iterable[Dict[str, Any]], UserProfile, bool, bool, Optional[Iterable[str]]) -> None
|
||||
for event in events:
|
||||
if fetch_event_types is not None and event['type'] not in fetch_event_types:
|
||||
# TODO: continuing here is not, most precisely, correct.
|
||||
@@ -257,10 +269,10 @@ def apply_events(state, events, user_profile, include_subscribers=True,
|
||||
# `apply_event`. For now, be careful in your choice of
|
||||
# `fetch_event_types`.
|
||||
continue
|
||||
apply_event(state, event, user_profile, include_subscribers)
|
||||
apply_event(state, event, user_profile, client_gravatar, include_subscribers)
|
||||
|
||||
def apply_event(state, event, user_profile, include_subscribers):
|
||||
# type: (Dict[str, Any], Dict[str, Any], UserProfile, bool) -> None
|
||||
def apply_event(state, event, user_profile, client_gravatar, include_subscribers):
|
||||
# type: (Dict[str, Any], Dict[str, Any], UserProfile, bool, bool) -> None
|
||||
if event['type'] == "message":
|
||||
state['max_message_id'] = max(state['max_message_id'], event['message']['id'])
|
||||
if 'raw_unread_msgs' in state:
|
||||
@@ -283,6 +295,9 @@ def apply_event(state, event, user_profile, include_subscribers):
|
||||
|
||||
if event['op'] == "add":
|
||||
person = copy.deepcopy(person)
|
||||
if client_gravatar:
|
||||
if 'gravatar.com' in person['avatar_url']:
|
||||
person['avatar_url'] = None
|
||||
person['is_active'] = True
|
||||
state['raw_users'][person_user_id] = person
|
||||
elif event['op'] == "remove":
|
||||
@@ -563,6 +578,7 @@ def do_events_register(user_profile, user_client, apply_markdown=True, client_gr
|
||||
# Apply events that came in while we were fetching initial data
|
||||
events = get_user_events(user_profile, queue_id, -1)
|
||||
apply_events(ret, events, user_profile, include_subscribers=include_subscribers,
|
||||
client_gravatar=client_gravatar,
|
||||
fetch_event_types=fetch_event_types)
|
||||
|
||||
'''
|
||||
|
||||
@@ -491,7 +491,8 @@ class EventsRegisterTest(ZulipTestCase):
|
||||
self.assertTrue(len(events) == num_events)
|
||||
|
||||
before = ujson.dumps(hybrid_state)
|
||||
apply_events(hybrid_state, events, self.user_profile, include_subscribers=include_subscribers)
|
||||
apply_events(hybrid_state, events, self.user_profile,
|
||||
client_gravatar=True, include_subscribers=include_subscribers)
|
||||
after = ujson.dumps(hybrid_state)
|
||||
|
||||
if state_change_expected:
|
||||
@@ -949,7 +950,7 @@ class EventsRegisterTest(ZulipTestCase):
|
||||
('person', check_dict_only([
|
||||
('user_id', check_int),
|
||||
('email', check_string),
|
||||
('avatar_url', check_string),
|
||||
('avatar_url', check_none_or(check_string)),
|
||||
('full_name', check_string),
|
||||
('is_admin', check_bool),
|
||||
('is_bot', check_bool),
|
||||
|
||||
Reference in New Issue
Block a user