Compare commits

...

3 Commits

Author SHA1 Message Date
Andrew Morgan
29f2b64188 changelog 2022-02-03 15:40:41 +00:00
Andrew Morgan
d33ab609bc 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.
2022-02-03 15:35:37 +00:00
Andrew Morgan
c26f7f7cae Derive users to notify from user streams in on_new_event
Otherwise we were completely ignoring all users discovered from rooms being passed
to this function.
2022-02-03 15:35:37 +00:00
4 changed files with 11 additions and 12 deletions

1
changelog.d/11903.misc Normal file
View File

@@ -0,0 +1 @@
Ensure application service users receive EDUs generated by another user that they share a room with.

View File

@@ -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()

View File

@@ -458,7 +458,10 @@ class Notifier:
self.appservice_handler.notify_interested_services_ephemeral(
stream_key,
new_token,
users,
[
UserID.from_string(user_stream.user_id)
for user_stream in user_streams
],
)
except Exception:
logger.exception(

View File

@@ -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(