Await invite callback (#32)

Co-authored-by: Kev <>
Co-authored-by: Andrew Morgan <andrew@amorgan.xyz>
This commit is contained in:
Kevin Li 2021-10-25 15:28:38 -04:00 committed by GitHub
parent 54c2b88d60
commit 71d520239c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 16 deletions

View file

@ -104,6 +104,19 @@ class Callbacks:
# Successfully joined room
logger.info(f"Joined {room.room_id}")
async def invite_event_filtered_callback(
self, room: MatrixRoom, event: InviteMemberEvent
) -> None:
"""
Since the InviteMemberEvent is fired for every m.room.member state received
in a sync response's `rooms.invite` section, we will receive some that are
not actually our own invite event (such as the inviter's membership).
This makes sure we only call `callbacks.invite` with our own invite events.
"""
if event.state_key == self.client.user_id:
# This is our own membership (invite) event
await self.invite(room, event)
async def _reaction(
self, room: MatrixRoom, event: UnknownEvent, reacted_to_id: str
) -> None:

View file

@ -11,7 +11,6 @@ from nio import (
InviteMemberEvent,
LocalProtocolError,
LoginError,
MatrixRoom,
MegolmEvent,
RoomMessageText,
UnknownEvent,
@ -64,21 +63,9 @@ async def main():
# Set up event callbacks
callbacks = Callbacks(client, store, config)
client.add_event_callback(callbacks.message, (RoomMessageText,))
def invite_event_filtered_callback(
room: MatrixRoom, event: InviteMemberEvent
) -> None:
"""
Since the InviteMemberEvent is fired for every m.room.member state received
in a sync response's `rooms.invite` section, we will receive some that are
not actually our own invite event (such as the inviter's membership).
This makes sure we only call `callbacks.invite` with our own invite events.
"""
if event.state_key == client.user_id:
# This is our own membership (invite) event
callbacks.invite(room, event)
client.add_event_callback(invite_event_filtered_callback, (InviteMemberEvent,))
client.add_event_callback(
callbacks.invite_event_filtered_callback, (InviteMemberEvent,)
)
client.add_event_callback(callbacks.decryption_failure, (MegolmEvent,))
client.add_event_callback(callbacks.unknown, (UnknownEvent,))