diff --git a/synapse/handlers/presence.py b/synapse/handlers/presence.py index 1255ceca5529..810a0882c7a4 100644 --- a/synapse/handlers/presence.py +++ b/synapse/handlers/presence.py @@ -1947,7 +1947,10 @@ def send_presence_to_destinations( """ if self._federation: - self._federation.send_presence_to_destinations(states, destinations) + self._federation.send_presence_to_destinations( + states=states, + destinations=destinations, + ) if not self._queue_presence_updates: return @@ -2038,4 +2041,7 @@ async def process_replication_rows( for host, user_ids in hosts_to_users.items(): states = await self._presence_handler.current_state_for_users(user_ids) - self._federation.send_presence_to_destinations(states.values(), [host]) + self._federation.send_presence_to_destinations( + states=states.values(), + destinations=[host], + ) diff --git a/synapse/module_api/__init__.py b/synapse/module_api/__init__.py index 90a40cd16b2c..9b1030e26f7f 100644 --- a/synapse/module_api/__init__.py +++ b/synapse/module_api/__init__.py @@ -52,7 +52,6 @@ def __init__(self, hs, auth_handler): self._server_name = hs.hostname self._presence_stream = hs.get_event_sources().sources["presence"] self._state = hs.get_state_handler() - self._presence_router = hs.get_presence_router() self._federation = None if hs.should_send_federation(): @@ -442,7 +441,7 @@ async def send_local_online_presence_to(self, users: Iterable[str]) -> None: # Send to remote destinations hosts_and_states = await get_interested_remotes( self._store, - self._presence_router, + self._hs.get_presence_router(), presence_events, self._state, ) diff --git a/tests/handlers/test_presence.py b/tests/handlers/test_presence.py index 6cda602fce72..5744105bfb52 100644 --- a/tests/handlers/test_presence.py +++ b/tests/handlers/test_presence.py @@ -21,6 +21,7 @@ from synapse.api.presence import UserPresenceState from synapse.api.room_versions import KNOWN_ROOM_VERSIONS from synapse.events.builder import EventBuilder +from synapse.federation.sender import FederationSender from synapse.handlers.presence import ( EXTERNAL_PROCESS_EXPIRY, FEDERATION_PING_INTERVAL, @@ -644,10 +645,17 @@ class PresenceJoinTestCase(unittest.HomeserverTestCase): def make_homeserver(self, reactor, clock): hs = self.setup_test_homeserver( - "server", federation_http_client=None, federation_sender=Mock() + "server", + federation_http_client=None, + federation_sender=Mock(spec=FederationSender), ) return hs + def default_config(self): + config = unittest.default_config("test") + config["send_federation"] = True + return config + def prepare(self, reactor, clock, hs): self.federation_sender = hs.get_federation_sender() self.event_builder_factory = hs.get_event_builder_factory() @@ -691,9 +699,6 @@ def test_remote_joins(self): # Add a new remote server to the room self._add_new_user(room_id, "@alice:server2") - # We shouldn't have sent out any local presence *updates* - self.federation_sender.send_presence.assert_not_called() - # When new server is joined we send it the local users presence states. # We expect to only see user @test2:server, as @test:server is offline # and has a zero last_active_ts @@ -712,7 +717,6 @@ def test_remote_joins(self): self.federation_sender.reset_mock() self._add_new_user(room_id, "@bob:server3") - self.federation_sender.send_presence.assert_not_called() self.federation_sender.send_presence_to_destinations.assert_called_once_with( destinations=["server3"], states={expected_state} ) @@ -757,9 +761,6 @@ def test_remote_gets_presence_when_local_user_joins(self): self.reactor.pump([0]) # Wait for presence updates to be handled - # We shouldn't have sent out any local presence *updates* - self.federation_sender.send_presence.assert_not_called() - # We expect to only send test2 presence to server2 and server3 expected_state = self.get_success( self.presence_handler.current_state_for_user("@test2:server")