diff --git a/synapse/appservice/__init__.py b/synapse/appservice/__init__.py index 6ee5240c4e..a0971e3c48 100644 --- a/synapse/appservice/__init__.py +++ b/synapse/appservice/__init__.py @@ -88,6 +88,7 @@ class ApplicationService: supports_ephemeral: bool = False, msc3202_transaction_extensions: bool = False, msc4190_device_management: bool = False, + supports_profile_lookup: bool = False, ): self.token = token self.url = ( @@ -100,6 +101,7 @@ class ApplicationService: self.id = id self.ip_range_whitelist = ip_range_whitelist self.supports_ephemeral = supports_ephemeral + self.supports_profile_lookup = supports_profile_lookup self.msc3202_transaction_extensions = msc3202_transaction_extensions self.msc4190_device_management = msc4190_device_management diff --git a/synapse/appservice/api.py b/synapse/appservice/api.py index 2c24db0822..fc9cb06c0e 100644 --- a/synapse/appservice/api.py +++ b/synapse/appservice/api.py @@ -278,7 +278,7 @@ class ApplicationServiceApi(SimpleHttpClient): url = f"{service.url}{APP_SERVICE_PREFIX}/profile/{urllib.parse.quote(user_id)}" if key: - url += f"/{key}" + url += f"/{urllib.parse.quote(key)}" response = await self.get_json( url, diff --git a/synapse/config/appservice.py b/synapse/config/appservice.py index dda6bcd1b7..68816cd85e 100644 --- a/synapse/config/appservice.py +++ b/synapse/config/appservice.py @@ -171,6 +171,7 @@ def _load_appservice( ip_range_whitelist = IPSet(as_info.get("ip_range_whitelist")) supports_ephemeral = as_info.get("de.sorunome.msc2409.push_ephemeral", False) + lookup_profiles = as_info.get("uk.half-shot.lookup_profile", False) # Opt-in flag for the MSC3202-specific transactional behaviour. # When enabled, appservice transactions contain the following information: @@ -206,6 +207,7 @@ def _load_appservice( rate_limited=rate_limited, ip_range_whitelist=ip_range_whitelist, supports_ephemeral=supports_ephemeral, + supports_profile_lookup=lookup_profiles, msc3202_transaction_extensions=msc3202_transaction_extensions, msc4190_device_management=msc4190_enabled, ) diff --git a/synapse/handlers/appservice.py b/synapse/handlers/appservice.py index d2a39ba151..f101c671f0 100644 --- a/synapse/handlers/appservice.py +++ b/synapse/handlers/appservice.py @@ -724,11 +724,12 @@ class ApplicationServicesHandler: user_query_services = self._get_services_for_user(user_id=user_id) accumulated_profile = {} for user_service in user_query_services: - profile = await self.appservice_api.query_profile( - user_service, user_id, from_user_id, key - ) - if profile: - accumulated_profile.update(profile) + if user_service.supports_profile_lookup: + profile = await self.appservice_api.query_profile( + user_service, user_id, from_user_id, key + ) + if profile: + accumulated_profile.update(profile) return accumulated_profile async def query_room_alias_exists(