From 998ad006fbee9311c73f7f23d6593246bb375307 Mon Sep 17 00:00:00 2001 From: Tulir Asokan <tulir@maunium.net> Date: Thu, 9 Jul 2020 19:45:40 +0300 Subject: [PATCH] Move enable_dm_encryption helper to Portal --- mautrix_facebook/matrix.py | 12 +----------- mautrix_facebook/portal.py | 11 ++++++++++- requirements.txt | 2 +- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/mautrix_facebook/matrix.py b/mautrix_facebook/matrix.py index 508f535..63e3ccc 100644 --- a/mautrix_facebook/matrix.py +++ b/mautrix_facebook/matrix.py @@ -107,7 +107,7 @@ class MatrixHandler(BaseMatrixHandler): portal.mxid = room_id e2be_ok = None if self.config["bridge.encryption.default"] and self.e2ee: - e2be_ok = await self.enable_dm_encryption(portal, members=members) + e2be_ok = await portal.enable_dm_encryption() portal.save() if e2be_ok is True: evt_type, content = await self.e2ee.encrypt( @@ -122,16 +122,6 @@ class MatrixHandler(BaseMatrixHandler): message += "\n\nWarning: Failed to enable end-to-bridge encryption" await intent.send_notice(room_id, message) - async def enable_dm_encryption(self, portal: po.Portal, members: List[UserID]) -> bool: - ok = await super().enable_dm_encryption(portal, members) - if ok: - try: - puppet = pu.Puppet.get_by_fbid(portal.fbid) - await portal.main_intent.set_room_name(portal.mxid, puppet.name) - except Exception: - self.log.warning(f"Failed to set room name for {portal.mxid}", exc_info=True) - return ok - async def handle_invite(self, room_id: RoomID, user_id: UserID, invited_by: 'u.User', event_id: EventID) -> None: # TODO handle puppet and user invites for group chats diff --git a/mautrix_facebook/portal.py b/mautrix_facebook/portal.py index 3c4ca72..59bfda7 100644 --- a/mautrix_facebook/portal.py +++ b/mautrix_facebook/portal.py @@ -662,7 +662,6 @@ class Portal(BasePortal): if existing and existing.reaction == reaction: return - # TODO normalize reaction emoji bytes and maybe pre-reject invalid emojis await fbchat.Message(thread=self.thread_for(sender), id=message.fbid).react(reaction) await self._upsert_reaction(existing, self.main_intent, event_id, message, sender, reaction) @@ -684,6 +683,16 @@ class Portal(BasePortal): self._typing = users await asyncio.gather(*stopped_typing, *started_typing, loop=self.loop) + async def enable_dm_encryption(self) -> bool: + ok = await super().enable_dm_encryption() + if ok: + try: + puppet = p.Puppet.get_by_fbid(self.fbid) + await self.main_intent.set_room_name(self.mxid, puppet.name) + except Exception: + self.log.warning(f"Failed to set room name", exc_info=True) + return ok + # endregion # region Facebook event handling diff --git a/requirements.txt b/requirements.txt index f05d23a..332dee8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,5 +4,5 @@ alembic>=1,<2 ruamel.yaml>=0.15.94,<0.17 commonmark>=0.8,<0.10 python-magic>=0.4,<0.5 -mautrix==0.6.0.beta6 +mautrix==0.6.0.beta7 fbchat-asyncio>=0.6.10,<0.7 -- GitLab