Await invite callback (#32)
Co-authored-by: Kev <> Co-authored-by: Andrew Morgan <andrew@amorgan.xyz>
This commit is contained in:
parent
54c2b88d60
commit
71d520239c
2 changed files with 16 additions and 16 deletions
|
@ -104,6 +104,19 @@ class Callbacks:
|
||||||
# Successfully joined room
|
# Successfully joined room
|
||||||
logger.info(f"Joined {room.room_id}")
|
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(
|
async def _reaction(
|
||||||
self, room: MatrixRoom, event: UnknownEvent, reacted_to_id: str
|
self, room: MatrixRoom, event: UnknownEvent, reacted_to_id: str
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|
|
@ -11,7 +11,6 @@ from nio import (
|
||||||
InviteMemberEvent,
|
InviteMemberEvent,
|
||||||
LocalProtocolError,
|
LocalProtocolError,
|
||||||
LoginError,
|
LoginError,
|
||||||
MatrixRoom,
|
|
||||||
MegolmEvent,
|
MegolmEvent,
|
||||||
RoomMessageText,
|
RoomMessageText,
|
||||||
UnknownEvent,
|
UnknownEvent,
|
||||||
|
@ -64,21 +63,9 @@ async def main():
|
||||||
# Set up event callbacks
|
# Set up event callbacks
|
||||||
callbacks = Callbacks(client, store, config)
|
callbacks = Callbacks(client, store, config)
|
||||||
client.add_event_callback(callbacks.message, (RoomMessageText,))
|
client.add_event_callback(callbacks.message, (RoomMessageText,))
|
||||||
|
client.add_event_callback(
|
||||||
def invite_event_filtered_callback(
|
callbacks.invite_event_filtered_callback, (InviteMemberEvent,)
|
||||||
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.decryption_failure, (MegolmEvent,))
|
client.add_event_callback(callbacks.decryption_failure, (MegolmEvent,))
|
||||||
client.add_event_callback(callbacks.unknown, (UnknownEvent,))
|
client.add_event_callback(callbacks.unknown, (UnknownEvent,))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue