Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Fix module api
Browse files Browse the repository at this point in the history
  • Loading branch information
erikjohnston committed Apr 15, 2021
1 parent 40bc877 commit 7575a68
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions synapse/module_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from twisted.internet import defer

from synapse.events import EventBase
from synapse.handlers.presence import get_interested_remotes
from synapse.http.client import SimpleHttpClient
from synapse.http.site import SynapseRequest
from synapse.logging.context import make_deferred_yieldable, run_in_background
Expand Down Expand Up @@ -50,6 +51,12 @@ def __init__(self, hs, auth_handler):
self._auth_handler = 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():
self._federation = self._hs.get_federation_sender()

# We expose these as properties below in order to attach a helpful docstring.
self._http_client = hs.get_simple_http_client() # type: SimpleHttpClient
Expand Down Expand Up @@ -423,19 +430,26 @@ async def send_local_online_presence_to(self, users: Iterable[str]) -> None:
# Force a presence initial_sync for this user next time
self._send_full_presence_to_local_users.add(user)
else:
if not self._federation:
continue

# Retrieve presence state for currently online users that this user
# is considered interested in
presence_events, _ = await self._presence_stream.get_new_events(
UserID.from_string(user), from_key=None, include_offline=False
)

# Send to remote destinations
await make_deferred_yieldable(
# We pull the federation sender here as we can only do so on workers
# that support sending presence
self._hs.get_federation_sender().send_presence(presence_events)
hosts_and_states = await get_interested_remotes(
self._store,
self._presence_router,
presence_events,
self._state,
)

for destinations, states in hosts_and_states:
self._federation.send_presence_to_destinations(states, destinations)


class PublicRoomListManager:
"""Contains methods for adding to, removing from and querying whether a room
Expand Down

0 comments on commit 7575a68

Please sign in to comment.