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.
This commit is contained in:
@@ -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()
|
||||
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user