Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2430 from matrix-org/erikj/groups_profile_cache
Browse files Browse the repository at this point in the history
Add user profiles to summary from group server
  • Loading branch information
erikjohnston authored Aug 25, 2017
2 parents 6d8799a + 4a9b1cf commit 7f0d0ba
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
7 changes: 6 additions & 1 deletion synapse/groups/groups_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def __init__(self, hs):
self.server_name = hs.hostname
self.attestations = hs.get_groups_attestation_signing()
self.transport_client = hs.get_federation_transport_client()
self.profile_handler = hs.get_profile_handler()

# Ensure attestations get renewed
hs.get_groups_attestation_renewer()
Expand Down Expand Up @@ -128,6 +129,9 @@ def get_group_summary(self, group_id, requester_user_id):
group_id, user_id,
)

user_profile = yield self.profile_handler.get_profile_from_cache(user_id)
entry.update(user_profile)

users.sort(key=lambda e: e.get("order", 0))

membership_info = yield self.store.get_users_membership_info_in_group(
Expand Down Expand Up @@ -387,7 +391,8 @@ def get_users_in_group(self, group_id, requester_user_id):

entry = {"user_id": g_user_id}

# TODO: Get profile information
profile = yield self.profile_handler.get_profile_from_cache(g_user_id)
entry.update(profile)

if not is_public:
entry["is_public"] = False
Expand Down
23 changes: 23 additions & 0 deletions synapse/handlers/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,29 @@ def get_profile(self, user_id):

raise

@defer.inlineCallbacks
def get_profile_from_cache(self, user_id):
"""Get the profile information from our local cache. If the user is
ours then the profile information will always be corect. Otherwise,
it may be out of date/missing.
"""
target_user = UserID.from_string(user_id)
if self.hs.is_mine(target_user):
displayname = yield self.store.get_profile_displayname(
target_user.localpart
)
avatar_url = yield self.store.get_profile_avatar_url(
target_user.localpart
)

defer.returnValue({
"displayname": displayname,
"avatar_url": avatar_url,
})
else:
profile = yield self.store.get_from_remote_profile_cache(user_id)
defer.returnValue(profile or {})

@defer.inlineCallbacks
def get_displayname(self, target_user):
if self.hs.is_mine(target_user):
Expand Down
2 changes: 1 addition & 1 deletion synapse/storage/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def get_from_remote_profile_cache(self, user_id):
return self._simple_select_one(
table="remote_profile_cache",
keyvalues={"user_id": user_id},
retcols=("displayname", "avatar_url", "last_check"),
retcols=("displayname", "avatar_url",),
allow_none=True,
desc="get_from_remote_profile_cache",
)
Expand Down

0 comments on commit 7f0d0ba

Please sign in to comment.