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

Port much of synapse.federation.federation_client to async/await #6840

Merged
merged 19 commits into from
Feb 5, 2020
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
Prev Previous commit
Next Next commit
make FederationClient.make_membership_event async
richvdh committed Feb 3, 2020
commit 3f11cbb40494f0ac9622a5b686d3cf8379a44b5d
21 changes: 11 additions & 10 deletions synapse/federation/federation_client.py
Original file line number Diff line number Diff line change
@@ -35,6 +35,7 @@
from synapse.api.room_versions import (
KNOWN_ROOM_VERSIONS,
EventFormatVersions,
RoomVersion,
RoomVersions,
)
from synapse.events import EventBase, builder, room_version_to_event_format
@@ -404,15 +405,15 @@ def _try_destination_list(self, description, destinations, callback):

raise SynapseError(502, "Failed to %s via any server" % (description,))

def make_membership_event(
async def make_membership_event(
self,
destinations: Iterable[str],
room_id: str,
user_id: str,
membership: str,
content: dict,
params: Dict[str, str],
):
) -> Tuple[str, EventBase, RoomVersion]:
"""
Creates an m.room.member event, with context, without participating in the room.

@@ -433,19 +434,19 @@ def make_membership_event(
content: Any additional data to put into the content field of the
event.
params: Query parameters to include in the request.
Return:
Deferred[Tuple[str, FrozenEvent, RoomVersion]]: resolves to a tuple of

Returns:
`(origin, event, room_version)` where origin is the remote
homeserver which generated the event, and room_version is the
version of the room.

Fails with a `UnsupportedRoomVersionError` if remote responds with
a room version we don't understand.
Raises:
UnsupportedRoomVersionError: if remote responds with
a room version we don't understand.

Fails with a ``SynapseError`` if the chosen remote server
returns a 300/400 code.
SynapseError: if the chosen remote server returns a 300/400 code.

Fails with a ``RuntimeError`` if no servers were reachable.
RuntimeError: if no servers were reachable.
"""
valid_memberships = {Membership.JOIN, Membership.LEAVE}
if membership not in valid_memberships:
@@ -491,7 +492,7 @@ def send_request(destination):

return (destination, ev, room_version)

return self._try_destination_list(
return await self._try_destination_list(
"make_" + membership, destinations, send_request
)