Add origin server

This commit is contained in:
Half-Shot
2025-09-02 06:25:21 +01:00
parent 13ffee45ce
commit 7aaa267b54
4 changed files with 15 additions and 9 deletions

View File

@@ -268,6 +268,7 @@ class ApplicationServiceApi(SimpleHttpClient):
user_id: str,
from_user_id: Optional[UserID] = None,
key: Optional[str] = None,
origin_server: Optional[str] = None,
) -> Optional[JsonDict]:
if service.url is None:
return None
@@ -281,6 +282,8 @@ class ApplicationServiceApi(SimpleHttpClient):
args["access_token"] = service.hs_token
if from_user_id:
args["from_user_id"] = from_user_id.to_string()
if origin_server:
args["origin_server"] = origin_server
url = f"{service.url}{APP_SERVICE_PREFIX}/profile/{urllib.parse.quote(user_id)}"

View File

@@ -737,7 +737,7 @@ class ApplicationServicesHandler:
return False
async def query_profile(
self, user_id: str, from_user_id: Optional[UserID] = None, key: Optional[str] = None
self, user_id: str, from_user_id: Optional[UserID] = None, key: Optional[str] = None, origin_server: Optional[str] = None
) -> Optional[JsonDict]:
"""Check if any application service knows this user_id exists.
@@ -751,7 +751,7 @@ class ApplicationServicesHandler:
for user_service in user_query_services:
if user_service.supports_profile_lookup:
profile = await self.appservice_api.query_profile(
user_service, user_id, from_user_id, key
user_service, user_id, from_user_id, key, origin_server
)
if profile:
accumulated_profile.update(profile)

View File

@@ -139,6 +139,8 @@ class ProfileHandler:
raise e.to_synapse_error()
# Check whether the appservice has any information about the user.
logger.info(f"query_profile {user_id} {from_user_id}")
as_profile = await self._as.query_profile(user_id, from_user_id)
ret.update(as_profile)
@@ -464,6 +466,7 @@ class ProfileHandler:
The value for the profile field or None if the field does not exist.
"""
logger.info(f"get_profile_field {field_name} {from_user_id}")
# Check whether the appservice has any information about the user.
as_profile = await self._as.query_profile(
target_user.to_string(), from_user_id, field_name
@@ -576,9 +579,12 @@ class ProfileHandler:
raise SynapseError(400, "User is not hosted on this homeserver")
just_field = args.get("field")
origin_server = args.get("origin")
assert origin_server
# Check whether the appservice has any information about the user.
as_profile = await self._as.query_profile(user.to_string(), key=just_field)
as_profile = await self._as.query_profile(user.to_string(), key=just_field, origin_server=origin_server)
if just_field and just_field in as_profile:
return as_profile[just_field]

View File

@@ -113,11 +113,8 @@ class ProfileFieldRestServlet(RestServlet):
async def on_GET(
self, request: SynapseRequest, user_id: str, field_name: str
) -> Tuple[int, JsonDict]:
requester_user = None
if self.hs.config.server.require_auth_for_profile_requests:
requester = await self.auth.get_user_by_req(request)
requester_user = requester.user
requester = await self.auth.get_user_by_req(request)
requester_user = requester.user
if not UserID.is_valid(user_id):
raise SynapseError(
@@ -137,7 +134,7 @@ class ProfileFieldRestServlet(RestServlet):
)
user = UserID.from_string(user_id)
await self.profile_handler.check_profile_query_allowed(user, requester_user)
await self.profile_handler.check_profile_query_allowed(user, requester_user if self.hs.config.server.require_auth_for_profile_requests else None)
if field_name == ProfileFields.DISPLAYNAME:
field_value: JsonValue = await self.profile_handler.get_displayname(