From feeecea60371e6adfe354e66dd051c6bbc75e75d Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Thu, 9 Dec 2021 18:27:59 +0000 Subject: Create ApplicationService.is_interested_in_user, and use everywhere --- synapse/appservice/__init__.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'synapse') diff --git a/synapse/appservice/__init__.py b/synapse/appservice/__init__.py index 36d09cb53e..30a114fcd1 100644 --- a/synapse/appservice/__init__.py +++ b/synapse/appservice/__init__.py @@ -171,6 +171,31 @@ class ApplicationService: return True return False + @cached + async def is_interested_in_user( + self, + user_id: str, + ) -> bool: + """ + Returns whether the application is interested in a given user ID. + + The appservice is considered to be interested in a user if either: the + user ID is in the appservice's user namespace, or if the user is the + appservice's configured sender_localpart. + + Args: + user_id: The ID of the user to check. + + Returns: + True if the application service is interested in the user, False if not. + """ + return ( + # User is the appservice's sender_localpart user + user_id == self.sender + # User is in a defined namespace + or self.is_user_in_namespace(user_id) + ) + @cached(num_args=1, cache_context=True) async def is_interested_in_room( self, -- cgit 1.5.1