Skip InviteMemberEvents that are not our invites (#30)
Co-authored-by: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com>
This commit is contained in:
parent
c7752db54c
commit
54c2b88d60
1 changed files with 16 additions and 1 deletions
|
@ -11,6 +11,7 @@ from nio import (
|
|||
InviteMemberEvent,
|
||||
LocalProtocolError,
|
||||
LoginError,
|
||||
MatrixRoom,
|
||||
MegolmEvent,
|
||||
RoomMessageText,
|
||||
UnknownEvent,
|
||||
|
@ -63,7 +64,21 @@ async def main():
|
|||
# Set up event callbacks
|
||||
callbacks = Callbacks(client, store, config)
|
||||
client.add_event_callback(callbacks.message, (RoomMessageText,))
|
||||
client.add_event_callback(callbacks.invite, (InviteMemberEvent,))
|
||||
|
||||
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.decryption_failure, (MegolmEvent,))
|
||||
client.add_event_callback(callbacks.unknown, (UnknownEvent,))
|
||||
|
||||
|
|
Loading…
Reference in a new issue