mirror of
https://github.com/zulip/zulip.git
synced 2025-11-12 18:06:44 +00:00
Fix display of changed avatars in old messages (page_params).
Our client code will now receive avatar_url in page_params.people_list during page load, so it will be able to use more current urls for old messages (the client already had some logic for that and was just missing the data). We also add avatar_url to the realm_user/add event. When we change the avatar, we make sure to always send a realm_user/update event (even for bots). We also needed to add avatar_version and avatar_source to our active users cache.
This commit is contained in:
@@ -356,6 +356,7 @@ def notify_created_user(user_profile):
|
||||
user_id=user_profile.id,
|
||||
is_admin=user_profile.is_realm_admin,
|
||||
full_name=user_profile.full_name,
|
||||
avatar_url=avatar_url(user_profile),
|
||||
is_bot=user_profile.is_bot))
|
||||
send_event(event, active_user_ids(user_profile.realm))
|
||||
|
||||
@@ -1915,17 +1916,17 @@ def do_change_avatar_fields(user_profile, avatar_source, log=True):
|
||||
avatar_url=avatar_url(user_profile),
|
||||
)),
|
||||
bot_owner_userids(user_profile))
|
||||
else:
|
||||
payload = dict(
|
||||
email=user_profile.email,
|
||||
avatar_url=avatar_url(user_profile),
|
||||
user_id=user_profile.id
|
||||
)
|
||||
|
||||
send_event(dict(type='realm_user',
|
||||
op='update',
|
||||
person=payload),
|
||||
active_user_ids(user_profile.realm))
|
||||
payload = dict(
|
||||
email=user_profile.email,
|
||||
avatar_url=avatar_url(user_profile),
|
||||
user_id=user_profile.id
|
||||
)
|
||||
|
||||
send_event(dict(type='realm_user',
|
||||
op='update',
|
||||
person=payload),
|
||||
active_user_ids(user_profile.realm))
|
||||
|
||||
def _default_stream_permision_check(user_profile, stream):
|
||||
# type: (UserProfile, Optional[Stream]) -> None
|
||||
|
||||
@@ -313,7 +313,11 @@ def user_profile_by_id_cache_key(user_profile_id):
|
||||
# TODO: Refactor these cache helpers into another file that can import
|
||||
# models.py so that python v3 style type annotations can also work.
|
||||
|
||||
active_user_dict_fields = ['id', 'full_name', 'short_name', 'email', 'is_realm_admin', 'is_bot'] # type: List[str]
|
||||
active_user_dict_fields = [
|
||||
'id', 'full_name', 'short_name', 'email',
|
||||
'avatar_source', 'avatar_version',
|
||||
'is_realm_admin', 'is_bot'] # type: List[str]
|
||||
|
||||
def active_user_dicts_in_realm_cache_key(realm):
|
||||
# type: (Realm) -> Text
|
||||
return u"active_user_dicts_in_realm:%s" % (realm.id,)
|
||||
|
||||
@@ -19,6 +19,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 get_avatar_url
|
||||
from zerver.lib.narrow import check_supported_events_narrow_filter
|
||||
from zerver.lib.request import JsonableError
|
||||
from zerver.lib.actions import validate_user_access_to_subscribers_helper, \
|
||||
@@ -32,8 +33,16 @@ from zerver.models import Client, Message, UserProfile, \
|
||||
|
||||
def get_realm_user_dicts(user_profile):
|
||||
# type: (UserProfile) -> List[Dict[str, Text]]
|
||||
def avatar_url(userdict):
|
||||
# type: (Dict[str, Any]) -> Text
|
||||
return get_avatar_url(userdict['avatar_source'],
|
||||
userdict['email'],
|
||||
userdict['avatar_version'],
|
||||
)
|
||||
|
||||
return [{'email': userdict['email'],
|
||||
'user_id': userdict['id'],
|
||||
'avatar_url': avatar_url(userdict),
|
||||
'is_admin': userdict['is_realm_admin'],
|
||||
'is_bot': userdict['is_bot'],
|
||||
'full_name': userdict['full_name']}
|
||||
@@ -187,12 +196,6 @@ def apply_event(state, event, user_profile, include_subscribers):
|
||||
if not p['is_admin'] and person['is_admin']:
|
||||
state['realm_bots'] = get_owned_bot_dicts(user_profile)
|
||||
|
||||
# This is temporary code to support tests, but it does avoid polluting
|
||||
# our data with misleading avatar_url data (although we will soon support
|
||||
# that field in realm_users).
|
||||
if 'avatar_url' in person:
|
||||
return
|
||||
|
||||
# Now update the person
|
||||
p.update(person)
|
||||
elif event['type'] == 'realm_bot':
|
||||
|
||||
@@ -495,7 +495,6 @@ class EventsRegisterTest(ZulipTestCase):
|
||||
])
|
||||
events = self.do_test(
|
||||
lambda: do_change_avatar_fields(self.user_profile, UserProfile.AVATAR_FROM_USER),
|
||||
state_change_expected=False,
|
||||
)
|
||||
error = schema_checker('events[0]', events[0])
|
||||
self.assert_on_error(error)
|
||||
|
||||
Reference in New Issue
Block a user