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 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
46 changes: 45 additions & 1 deletion synapse/handlers/appservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,18 +273,49 @@ async def _notify_interested_services_ephemeral(
async def _handle_typing(
self, service: ApplicationService, new_token: int
) -> List[JsonDict]:
"""
Given an application service, determine which events it should receive
from the given typing event stream token and now.
clokep marked this conversation as resolved.
Show resolved Hide resolved

Args:
service: The application service to check for which events it should receive.
new_token: The latest typing event stream token.

Returns:
A list of JSON dictionaries containing data derived from the typing events that
should be sent to the given application service.
"""
typing_source = self.event_sources.sources.typing
# Get the typing events from just before current
typing, _ = await typing_source.get_new_events_as(
service=service,
# For performance reasons, we don't persist the previous
# token in the DB and instead fetch the latest typing information
# token in the DB and instead fetch the latest typing event
# for appservices.
# TODO: It'd probably be more efficient to simply fetch the
# typing event with the given 'new_token' stream token and
# checking if the given service was interested, rather than
# iterating over all typing events and only grabbing the
# latest one.
from_key=new_token - 1,
)
return typing

async def _handle_receipts(self, service: ApplicationService) -> List[JsonDict]:
"""
Given an application service, determine which events it should receive
from those between the last-recorded typing event stream token for this
appservice and the latest one.

Args:
service: The application service to check for which events it should receive.
new_token: A typing event stream token. Typing events between this token and
the current event stream token will be checked.

Returns:
A list of JSON dictionaries containing data derived from the typing events that
should be sent to the given application service.
"""
from_key = await self.store.get_type_stream_id_for_appservice(
service, "read_receipt"
)
Expand All @@ -297,6 +328,19 @@ async def _handle_receipts(self, service: ApplicationService) -> List[JsonDict]:
async def _handle_presence(
self, service: ApplicationService, users: Collection[Union[str, UserID]]
) -> List[JsonDict]:
"""
Given an application service and a list of users who should be receiving
presence updates, return a list of presence updates destined for the
application service.

Args:
service: The application service that ephemeral events are being sent to.
users: The users that should receive the presence update.

Returns:
A list of json dictionaries containing data derived from the presence events
that should be sent to the given application service.
"""
events: List[JsonDict] = []
presence_source = self.event_sources.sources.presence
from_key = await self.store.get_type_stream_id_for_appservice(
Expand Down
4 changes: 4 additions & 0 deletions synapse/handlers/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,10 @@ async def notify_device_update(
) -> None:
"""Notify that a user's device(s) has changed. Pokes the notifier, and
remote servers if the user is local.

Args:
user_id: The Matrix ID of the user who's device list has been updated.
device_ids: The device IDs that have changed.
"""
if not device_ids:
# No changes to notify about, so this is a no-op.
Expand Down
8 changes: 7 additions & 1 deletion synapse/handlers/receipts.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,18 @@ async def get_new_events(
async def get_new_events_as(
self, from_key: int, service: ApplicationService
) -> Tuple[List[JsonDict], int]:
"""Returns a set of new receipt events that an appservice
"""Returns a set of new read receipt events that an appservice
may be interested in.

Args:
from_key: the stream position at which events should be fetched from
service: The appservice which may be interested

Returns:
A two-tuple containing the following:
* A list of json dictionaries derived from read receipts that the
appservice may be interested in.
* The current read receipt stream token.
"""
from_key = int(from_key)
to_key = self.get_current_key()
Expand Down
7 changes: 6 additions & 1 deletion synapse/handlers/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,9 +467,14 @@ async def get_new_events_as(
Args:
from_key: the stream position at which events should be fetched from
service: The appservice which may be interested

Returns:
A two-tuple containing the following:
* A list of json dictionaries derived from typing events that the
appservice may be interested in.
* The latest known room serial.
"""
with Measure(self.clock, "typing.get_new_events_as"):
from_key = int(from_key)
handler = self.get_typing_handler()

events = []
Expand Down