summary refs log tree commit diff
diff options
context:
space:
mode:
authorAndrew Morgan <andrew@amorgan.xyz>2022-02-03 15:31:59 +0000
committerAndrew Morgan <andrew@amorgan.xyz>2022-02-03 15:35:37 +0000
commitd33ab609bcd817ed09336185df0318352149ce6e (patch)
treecd2d1f6266c6a7d5b1b4b13c7ad324542dec4c57
parentDerive users to notify from user streams in on_new_event (diff)
downloadsynapse-d33ab609bcd817ed09336185df0318352149ce6e.tar.xz
Remove handling of str-type user IDs down the call stack
I broke off this refactoring at _get_to_device_messages, as this PR would start to become
much bigger otherwise.
-rw-r--r--synapse/handlers/appservice.py11
-rw-r--r--tests/handlers/test_appservice.py6
2 files changed, 6 insertions, 11 deletions
diff --git a/synapse/handlers/appservice.py b/synapse/handlers/appservice.py
index 0fb919acf6..fa0db46444 100644
--- a/synapse/handlers/appservice.py
+++ b/synapse/handlers/appservice.py
@@ -193,7 +193,7 @@ class ApplicationServicesHandler:
         self,
         stream_key: str,
         new_token: Union[int, RoomStreamToken],
-        users: Collection[Union[str, UserID]],
+        users: Collection[UserID],
     ) -> None:
         """
         This is called by the notifier in the background when an ephemeral event is handled
@@ -280,7 +280,7 @@ class ApplicationServicesHandler:
         services: List[ApplicationService],
         stream_key: str,
         new_token: int,
-        users: Collection[Union[str, UserID]],
+        users: Collection[UserID],
     ) -> None:
         logger.debug("Checking interested services for %s", stream_key)
         with Measure(self.clock, "notify_interested_services_ephemeral"):
@@ -410,7 +410,7 @@ class ApplicationServicesHandler:
     async def _handle_presence(
         self,
         service: ApplicationService,
-        users: Collection[Union[str, UserID]],
+        users: Collection[UserID],
         new_token: Optional[int],
     ) -> List[JsonDict]:
         """
@@ -444,9 +444,6 @@ class ApplicationServicesHandler:
             return []
 
         for user in users:
-            if isinstance(user, str):
-                user = UserID.from_string(user)
-
             interested = await service.is_interested_in_presence(user, self.store)
             if not interested:
                 continue
@@ -498,8 +495,6 @@ class ApplicationServicesHandler:
         # Filter out users that this appservice is not interested in
         users_appservice_is_interested_in: List[str] = []
         for user in users:
-            # FIXME: We should do this farther up the call stack. We currently repeat
-            #  this operation in _handle_presence.
             if isinstance(user, UserID):
                 user = user.to_string()
 
diff --git a/tests/handlers/test_appservice.py b/tests/handlers/test_appservice.py
index fe57ff2671..d0283e4969 100644
--- a/tests/handlers/test_appservice.py
+++ b/tests/handlers/test_appservice.py
@@ -22,7 +22,7 @@ import synapse.storage
 from synapse.appservice import ApplicationService
 from synapse.handlers.appservice import ApplicationServicesHandler
 from synapse.rest.client import login, receipts, room, sendtodevice
-from synapse.types import RoomStreamToken
+from synapse.types import RoomStreamToken, UserID
 from synapse.util.stringutils import random_string
 
 from tests import unittest
@@ -280,7 +280,7 @@ class AppServiceHandlerTestCase(unittest.TestCase):
         )
 
         self.handler.notify_interested_services_ephemeral(
-            "receipt_key", 580, ["@fakerecipient:example.com"]
+            "receipt_key", 580, [UserID.from_string("@fakerecipient:example.com")]
         )
         self.mock_scheduler.enqueue_for_appservice.assert_called_once_with(
             interested_service, ephemeral=[event]
@@ -310,7 +310,7 @@ class AppServiceHandlerTestCase(unittest.TestCase):
         )
 
         self.handler.notify_interested_services_ephemeral(
-            "receipt_key", 580, ["@fakerecipient:example.com"]
+            "receipt_key", 580, [UserID.from_string("@fakerecipient:example.com")]
         )
         # This method will be called, but with an empty list of events
         self.mock_scheduler.enqueue_for_appservice.assert_called_once_with(