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

Improve docstrings for methods related to sending EDUs to application services #11138

Merged
merged 16 commits into from
Oct 21, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 29 additions & 10 deletions synapse/handlers/appservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,19 +185,25 @@ def notify_interested_services_ephemeral(
new_token: Optional[int],
users: Optional[Collection[Union[str, UserID]]] = None,
) -> None:
"""This is called by the notifier in the background
when a ephemeral event handled by the homeserver.

This will determine which appservices
are interested in the event, and submit them.
"""
This is called by the notifier in the background when
an ephemeral event is handled by the homeserver.

Events will only be pushed to appservices
that have opted into ephemeral events
This will determine which appservices are
interested in the event, and submit them.
anoadragon453 marked this conversation as resolved.
Show resolved Hide resolved

Args:
stream_key: The stream the event came from.
new_token: The latest stream token
users: The user(s) involved with the event.

When `stream_key` is "typing_key", "receipt_key" or "presence_key", events
will only be pushed to appservices that have opted into ephemeral events.
anoadragon453 marked this conversation as resolved.
Show resolved Hide resolved
Appservices will only receive ephemeral events that fall within their
registered user and room namespaces.

Any other value for `stream_key` will cause this function to return early.

new_token: The latest stream token.
users: The users that should be informed of the new event, if any.
"""
if not self.notify_appservices:
return
Expand Down Expand Up @@ -232,21 +238,34 @@ async def _notify_interested_services_ephemeral(
for service in services:
# Only handle typing if we have the latest token
if stream_key == "typing_key" and new_token is not None:
# Note that we don't persist the token (via set_type_stream_id_for_appservice)
# for typing_key due to performance reasons and due to their highly
# ephemeral nature.
#
# Instead we simply grab the latest typing update in _handle_typing
# and, if it applies to this application service, send it off.
events = await self._handle_typing(service, new_token)
if events:
self.scheduler.submit_ephemeral_events_for_as(service, events)
# We don't persist the token for typing_key for performance reasons

elif stream_key == "receipt_key":
events = await self._handle_receipts(service)
if events:
self.scheduler.submit_ephemeral_events_for_as(service, events)

# Persist the latest handled stream token for this appservice
# TODO: We seem to update the stream token for each appservice,
# even if sending the ephemeral events to the appservice failed.
anoadragon453 marked this conversation as resolved.
Show resolved Hide resolved
await self.store.set_type_stream_id_for_appservice(
service, "read_receipt", new_token
)

elif stream_key == "presence_key":
events = await self._handle_presence(service, users)
if events:
self.scheduler.submit_ephemeral_events_for_as(service, events)

# Persist the latest handled stream token for this appservice
await self.store.set_type_stream_id_for_appservice(
service, "presence", new_token
)
Expand Down