diff options
author | Andrew Morgan <andrew@amorgan.xyz> | 2021-12-09 18:27:59 +0000 |
---|---|---|
committer | Andrew Morgan <andrew@amorgan.xyz> | 2021-12-09 18:27:59 +0000 |
commit | feeecea60371e6adfe354e66dd051c6bbc75e75d (patch) | |
tree | 741cca5583392d544b91099c8b6549a332f316a6 /synapse | |
parent | Switch DeviceLists to containing Sets, as we'll need a type that we can delet... (diff) | |
download | synapse-feeecea60371e6adfe354e66dd051c6bbc75e75d.tar.xz |
Create ApplicationService.is_interested_in_user, and use everywhere
Diffstat (limited to 'synapse')
-rw-r--r-- | synapse/appservice/__init__.py | 25 |
1 files changed, 25 insertions, 0 deletions
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, |