diff options
author | Will Hunt <will@half-shot.uk> | 2020-09-21 16:21:22 +0100 |
---|---|---|
committer | Will Hunt <will@half-shot.uk> | 2020-09-21 16:21:22 +0100 |
commit | 3bf1b79d3c2735cca9c0b38689b1f2701354bd52 (patch) | |
tree | cee02a7ec0a1d42efa7e891bbb5f89e522b0bc6a /synapse | |
parent | Call appservice handler when seeing new events in the notifier (diff) | |
download | synapse-3bf1b79d3c2735cca9c0b38689b1f2701354bd52.tar.xz |
Add is_interested_in_presence func
Diffstat (limited to 'synapse')
-rw-r--r-- | synapse/appservice/__init__.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/synapse/appservice/__init__.py b/synapse/appservice/__init__.py index 8737b34e54..5ed9f54bc7 100644 --- a/synapse/appservice/__init__.py +++ b/synapse/appservice/__init__.py @@ -19,7 +19,7 @@ from typing import TYPE_CHECKING from synapse.api.constants import EventTypes from synapse.appservice.api import ApplicationServiceApi from synapse.types import GroupID, get_domain_from_id -from synapse.util.caches.descriptors import cached +from synapse.util.caches.descriptors import cached, cachedList if TYPE_CHECKING: from synapse.storage.databases.main import DataStore @@ -241,6 +241,19 @@ class ApplicationService: return False + @cached(num_args=1, cache_context=True) + async def is_interested_in_presence(self, user_id, store, cache_context): + # Find all the rooms the sender is in + if self.is_interested_in_user(user_id.to_string()): + return True + room_ids = await store.get_rooms_for_user(user_id.to_string()) + + # Then find out if the appservice is interested in any of those rooms + for room_id in room_ids: + if await self.matches_user_in_member_list(room_id, store, cache_context): + return True + return False + def is_interested_in_user(self, user_id): return ( self._matches_regex(user_id, ApplicationService.NS_USERS) |