Move enable_dm_encryption helper to Portal

This commit is contained in:
Tulir Asokan
2020-07-09 19:45:28 +03:00
parent 64c9759de8
commit 689d84fa78
3 changed files with 11 additions and 12 deletions
+1 -11
View File
@@ -115,7 +115,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()
inviter.register_portal(portal)
if e2be_ok is True:
@@ -135,16 +135,6 @@ class MatrixHandler(BaseMatrixHandler):
await intent.send_notice(room_id, "This puppet will remain inactive until a "
"Telegram chat is created for this room.")
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(portal.tgid)
await portal.main_intent.set_room_name(portal.mxid, puppet.displayname)
except Exception:
self.log.warning(f"Failed to set room name for {portal.mxid}", exc_info=True)
return ok
async def send_welcome_message(self, room_id: RoomID, inviter: 'u.User') -> None:
try:
is_management = len(await self.az.intent.get_room_members(room_id)) == 2
+9
View File
@@ -574,6 +574,15 @@ class PortalMatrix(BasePortal, MautrixBasePortal, ABC):
self.db_instance.edit(mxid=self.mxid)
self.by_mxid[self.mxid] = self
async def enable_dm_encryption(self) -> bool:
ok = await super().enable_dm_encryption()
if ok:
try:
puppet = p.Puppet.get(self.tgid)
await self.main_intent.set_room_name(self.mxid, puppet.displayname)
except Exception:
self.log.warning(f"Failed to set room name", exc_info=True)
return ok
def init(context: Context) -> None:
global config
+1 -1
View File
@@ -4,6 +4,6 @@ ruamel.yaml>=0.15.35,<0.17
python-magic>=0.4,<0.5
commonmark>=0.8,<0.10
aiohttp>=3,<4
mautrix==0.6.0.beta6
mautrix==0.6.0.beta7
telethon>=1.13,<1.16
telethon-session-sqlalchemy>=0.2.14,<0.3