4545from twisted .web .resource import Resource
4646
4747from synapse .api import errors
48+ from synapse .api .constants import ProfileFields
4849from synapse .api .errors import SynapseError
4950from synapse .api .presence import UserPresenceState
5051from synapse .config import ConfigError
@@ -1086,7 +1087,10 @@ async def update_room_membership(
10861087 content = {}
10871088
10881089 # Set the profile if not already done by the module.
1089- if "avatar_url" not in content or "displayname" not in content :
1090+ if (
1091+ ProfileFields .AVATAR_URL not in content
1092+ or ProfileFields .DISPLAYNAME not in content
1093+ ):
10901094 try :
10911095 # Try to fetch the user's profile.
10921096 profile = await self ._hs .get_profile_handler ().get_profile (
@@ -1095,8 +1099,8 @@ async def update_room_membership(
10951099 except SynapseError as e :
10961100 # If the profile couldn't be found, use default values.
10971101 profile = {
1098- "displayname" : target_user_id .localpart ,
1099- "avatar_url" : None ,
1102+ ProfileFields . DISPLAYNAME : target_user_id .localpart ,
1103+ ProfileFields . AVATAR_URL : None ,
11001104 }
11011105
11021106 if e .code != 404 :
@@ -1109,11 +1113,9 @@ async def update_room_membership(
11091113 )
11101114
11111115 # Set the profile where it needs to be set.
1112- if "avatar_url" not in content :
1113- content ["avatar_url" ] = profile ["avatar_url" ]
1114-
1115- if "displayname" not in content :
1116- content ["displayname" ] = profile ["displayname" ]
1116+ for field_name in [ProfileFields .AVATAR_URL , ProfileFields .DISPLAYNAME ]:
1117+ if field_name not in content and field_name in profile :
1118+ content [field_name ] = profile [field_name ]
11171119
11181120 event_id , _ = await self ._hs .get_room_member_handler ().update_membership (
11191121 requester = requester ,
0 commit comments