@@ -74,6 +74,17 @@ def __init__(self, hs: "HomeServer"):
74
74
self ._third_party_rules = hs .get_module_api_callbacks ().third_party_event_rules
75
75
76
76
async def get_profile (self , user_id : str , ignore_backoff : bool = True ) -> JsonDict :
77
+ """
78
+ Get a user's profile as a JSON dictionary.
79
+
80
+ Args:
81
+ user_id: The user to fetch the profile of.
82
+ ignore_backoff: True to ignore backoff when fetching over federation.
83
+
84
+ Returns:
85
+ A JSON dictionary. For local queries this will include the displayname and avatar_url
86
+ fields. For remote queries it may contain arbitrary information.
87
+ """
77
88
target_user = UserID .from_string (user_id )
78
89
79
90
if self .hs .is_mine (target_user ):
@@ -107,6 +118,15 @@ async def get_profile(self, user_id: str, ignore_backoff: bool = True) -> JsonDi
107
118
raise e .to_synapse_error ()
108
119
109
120
async def get_displayname (self , target_user : UserID ) -> Optional [str ]:
121
+ """
122
+ Fetch a user's display name from their profile.
123
+
124
+ Args:
125
+ target_user: The user to fetch the display name of.
126
+
127
+ Returns:
128
+ The user's display name or None if unset.
129
+ """
110
130
if self .hs .is_mine (target_user ):
111
131
try :
112
132
displayname = await self .store .get_profile_displayname (target_user )
@@ -203,6 +223,15 @@ async def set_displayname(
203
223
await self ._update_join_states (requester , target_user )
204
224
205
225
async def get_avatar_url (self , target_user : UserID ) -> Optional [str ]:
226
+ """
227
+ Fetch a user's avatar URL from their profile.
228
+
229
+ Args:
230
+ target_user: The user to fetch the avatar URL of.
231
+
232
+ Returns:
233
+ The user's avatar URL or None if unset.
234
+ """
206
235
if self .hs .is_mine (target_user ):
207
236
try :
208
237
avatar_url = await self .store .get_profile_avatar_url (target_user )
@@ -403,6 +432,12 @@ async def on_profile_query(self, args: JsonDict) -> JsonDict:
403
432
async def _update_join_states (
404
433
self , requester : Requester , target_user : UserID
405
434
) -> None :
435
+ """
436
+ Update the membership events of each room the user is joined to with the
437
+ new profile information.
438
+
439
+ Note that this stomps over any custom display name or avatar URL in member events.
440
+ """
406
441
if not self .hs .is_mine (target_user ):
407
442
return
408
443
0 commit comments