From 912168626ce3ada5a3d5d4c82fee5321bc9d29ce Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sat, 27 Aug 2022 21:50:48 +0200 Subject: [PATCH] Added join_room, leave_room and invite_to_room and extended handling on invitation events --- platypush/plugins/matrix/__init__.py | 34 +++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/platypush/plugins/matrix/__init__.py b/platypush/plugins/matrix/__init__.py index 9483cecd0..aeb77fa4d 100644 --- a/platypush/plugins/matrix/__init__.py +++ b/platypush/plugins/matrix/__init__.py @@ -21,7 +21,7 @@ from nio import ( CallInviteEvent, ErrorResponse, Event, - InviteNameEvent, + InviteEvent, KeyVerificationStart, KeyVerificationAccept, KeyVerificationMac, @@ -359,7 +359,7 @@ class MatrixClient(AsyncClient): def _add_callbacks(self): self.add_event_callback(self._event_catch_all, Event) - self.add_event_callback(self._on_invite, InviteNameEvent) # type: ignore + self.add_event_callback(self._on_invite, InviteEvent) # type: ignore self.add_event_callback(self._on_message, RoomMessageText) # type: ignore self.add_event_callback(self._on_message, RoomMessageMedia) # type: ignore self.add_event_callback(self._on_message, RoomEncryptedMedia) # type: ignore @@ -379,7 +379,7 @@ class MatrixClient(AsyncClient): self.add_to_device_callback(self._on_key_verification_accept, KeyVerificationAccept) # type: ignore if self._autojoin_on_invite: - self.add_event_callback(self._autojoin_room_callback, InviteNameEvent) # type: ignore + self.add_event_callback(self._autojoin_room_callback, InviteEvent) # type: ignore def _sync_store(self): self.logger.info('Synchronizing keystore') @@ -1281,5 +1281,33 @@ class MatrixPlugin(AsyncRunnablePlugin): return rs[0].content_uri + @action + def invite_to_room(self, room_id: str, user_id: str): + """ + Invite a user to a room. + + :param room_id: Room ID. + :param user_id: User ID. + """ + self._loop_execute(self.client.room_invite(room_id, user_id)) + + @action + def join_room(self, room_id: str): + """ + Join a room. + + :param room_id: Room ID. + """ + self._loop_execute(self.client.join(room_id)) + + @action + def leave_room(self, room_id: str): + """ + Leave a joined room. + + :param room_id: Room ID. + """ + self._loop_execute(self.client.room_leave(room_id)) + # vim:sw=4:ts=4:et: