From 3bf1b79d3c2735cca9c0b38689b1f2701354bd52 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Mon, 21 Sep 2020 16:21:22 +0100 Subject: Add is_interested_in_presence func --- synapse/appservice/__init__.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'synapse') 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) -- cgit 1.4.1