summary refs log tree commit diff
diff options
context:
space:
mode:
authorAndrew Morgan <andrew@amorgan.xyz>2022-02-11 16:32:10 +0000
committerAndrew Morgan <andrew@amorgan.xyz>2022-02-11 16:32:10 +0000
commit610578e27177136b6a4b187783c490d35c688272 (patch)
treee55970a34ef45ae37ff9ce23169e23bd85781937
parentFetch thread summaries for multiple events in a single query (#11752) (diff)
downloadsynapse-anoa/rooms_for_as_edu_handler.tar.xz
Use room IDs to calculate users to additionally send EDUs to github/anoa/rooms_for_as_edu_handler anoa/rooms_for_as_edu_handler
-rw-r--r--synapse/handlers/appservice.py18
-rw-r--r--synapse/notifier.py1
2 files changed, 17 insertions, 2 deletions
diff --git a/synapse/handlers/appservice.py b/synapse/handlers/appservice.py
index a42c3558e4..117248545f 100644
--- a/synapse/handlers/appservice.py
+++ b/synapse/handlers/appservice.py
@@ -12,7 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 import logging
-from typing import TYPE_CHECKING, Collection, Dict, Iterable, List, Optional, Union
+from typing import TYPE_CHECKING, Collection, Dict, Iterable, List, Optional, Union, Set
 
 from prometheus_client import Counter
 
@@ -194,6 +194,7 @@ class ApplicationServicesHandler:
         stream_key: str,
         new_token: Union[int, RoomStreamToken],
         users: Collection[Union[str, UserID]],
+        room_ids: Optional[Collection[str]] = None,
     ) -> None:
         """
         This is called by the notifier in the background when an ephemeral event is handled
@@ -218,6 +219,9 @@ class ApplicationServicesHandler:
 
             new_token: The stream token of the event.
             users: The users that should be informed of the new event, if any.
+            room_ids: The room IDs whose joined members should be notified of
+                the new event. Application services that register explicit interest
+                in a room ID in this list are also be notified.
         """
         if not self.notify_appservices:
             return
@@ -271,7 +275,7 @@ class ApplicationServicesHandler:
         # We only start a new background process if necessary rather than
         # optimistically (to cut down on overhead).
         self._notify_interested_services_ephemeral(
-            services, stream_key, new_token, users
+            services, stream_key, new_token, users, room_ids
         )
 
     @wrap_as_background_process("notify_interested_services_ephemeral")
@@ -281,7 +285,17 @@ class ApplicationServicesHandler:
         stream_key: str,
         new_token: int,
         users: Collection[Union[str, UserID]],
+        room_ids: Optional[Collection[str]] = None,
     ) -> None:
+        # Calculate potential users to notify from the joined members of the given rooms
+        if room_ids:
+            joined_members: Set[Union[str, UserID]] = set()
+            for room_id in room_ids:
+                room_members = await self.store.get_users_in_room(room_id)
+                joined_members.update(room_members)
+
+            users = joined_members.union(users)
+
         logger.debug("Checking interested services for %s", stream_key)
         with Measure(self.clock, "notify_interested_services_ephemeral"):
             for service in services:
diff --git a/synapse/notifier.py b/synapse/notifier.py
index e0fad2da66..d9f517bdaf 100644
--- a/synapse/notifier.py
+++ b/synapse/notifier.py
@@ -464,6 +464,7 @@ class Notifier:
                     stream_key,
                     new_token,
                     users,
+                    rooms,
                 )
             except Exception:
                 logger.exception(