Skip to content

Commit 8fea190

Browse files
authored
Add missing docstrings related to profile methods. (#17559)
1 parent 81c19c4 commit 8fea190

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

changelog.d/17559.doc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improve docstrings for profile methods.

synapse/handlers/profile.py

+35
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,17 @@ def __init__(self, hs: "HomeServer"):
7474
self._third_party_rules = hs.get_module_api_callbacks().third_party_event_rules
7575

7676
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+
"""
7788
target_user = UserID.from_string(user_id)
7889

7990
if self.hs.is_mine(target_user):
@@ -107,6 +118,15 @@ async def get_profile(self, user_id: str, ignore_backoff: bool = True) -> JsonDi
107118
raise e.to_synapse_error()
108119

109120
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+
"""
110130
if self.hs.is_mine(target_user):
111131
try:
112132
displayname = await self.store.get_profile_displayname(target_user)
@@ -203,6 +223,15 @@ async def set_displayname(
203223
await self._update_join_states(requester, target_user)
204224

205225
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+
"""
206235
if self.hs.is_mine(target_user):
207236
try:
208237
avatar_url = await self.store.get_profile_avatar_url(target_user)
@@ -403,6 +432,12 @@ async def on_profile_query(self, args: JsonDict) -> JsonDict:
403432
async def _update_join_states(
404433
self, requester: Requester, target_user: UserID
405434
) -> 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+
"""
406441
if not self.hs.is_mine(target_user):
407442
return
408443

synapse/storage/databases/main/profile.py

+34
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,16 @@ def _final_batch(txn: LoggingTransaction, lower_bound_id: str) -> None:
144144
return 50
145145

146146
async def get_profileinfo(self, user_id: UserID) -> ProfileInfo:
147+
"""
148+
Fetch the display name and avatar URL of a user.
149+
150+
Args:
151+
user_id: The user ID to fetch the profile for.
152+
153+
Returns:
154+
The user's display name and avatar URL. Values may be null if unset
155+
or if the user doesn't exist.
156+
"""
147157
profile = await self.db_pool.simple_select_one(
148158
table="profiles",
149159
keyvalues={"full_user_id": user_id.to_string()},
@@ -158,6 +168,15 @@ async def get_profileinfo(self, user_id: UserID) -> ProfileInfo:
158168
return ProfileInfo(avatar_url=profile[1], display_name=profile[0])
159169

160170
async def get_profile_displayname(self, user_id: UserID) -> Optional[str]:
171+
"""
172+
Fetch the display name of a user.
173+
174+
Args:
175+
user_id: The user to get the display name for.
176+
177+
Raises:
178+
404 if the user does not exist.
179+
"""
161180
return await self.db_pool.simple_select_one_onecol(
162181
table="profiles",
163182
keyvalues={"full_user_id": user_id.to_string()},
@@ -166,6 +185,15 @@ async def get_profile_displayname(self, user_id: UserID) -> Optional[str]:
166185
)
167186

168187
async def get_profile_avatar_url(self, user_id: UserID) -> Optional[str]:
188+
"""
189+
Fetch the avatar URL of a user.
190+
191+
Args:
192+
user_id: The user to get the avatar URL for.
193+
194+
Raises:
195+
404 if the user does not exist.
196+
"""
169197
return await self.db_pool.simple_select_one_onecol(
170198
table="profiles",
171199
keyvalues={"full_user_id": user_id.to_string()},
@@ -174,6 +202,12 @@ async def get_profile_avatar_url(self, user_id: UserID) -> Optional[str]:
174202
)
175203

176204
async def create_profile(self, user_id: UserID) -> None:
205+
"""
206+
Create a blank profile for a user.
207+
208+
Args:
209+
user_id: The user to create the profile for.
210+
"""
177211
user_localpart = user_id.localpart
178212
await self.db_pool.simple_insert(
179213
table="profiles",

0 commit comments

Comments
 (0)