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
Show file tree
Hide file tree
Changes from 3 commits
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
18 changes: 16 additions & 2 deletions synapse/notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,14 @@ def _notify_app_services_ephemeral(
stream_key: str,
new_token: Union[int, RoomStreamToken],
users: Optional[Collection[Union[str, UserID]]] = None,
):
) -> None:
"""Notify application services of ephemeral event activity.

Args:
stream_key: The stream the event came from.
new_token: The value of the new stream token.
users: The users that should be informed of the new event, if any.
"""
try:
stream_token = None
if isinstance(new_token, int):
Expand All @@ -402,10 +409,17 @@ def on_new_event(
new_token: Union[int, RoomStreamToken],
users: Optional[Collection[Union[str, UserID]]] = None,
rooms: Optional[Collection[str]] = None,
):
) -> None:
"""Used to inform listeners that something has happened event wise.

Will wake up all listeners for the given users and rooms.

Args:
stream_key: The stream the event came from.
new_token: The value of the new stream token.
users: The users that should be informed of the new event.
rooms: A collection of room IDs for which each joined member will be
informed of the new event.
"""
users = users or []
rooms = rooms or []
Expand Down