Bläddra i källkod

Add flag to invite events that will be auto-accepted

Tulir Asokan 3 år sedan
förälder
incheckning
02cf61ace1
2 ändrade filer med 27 tillägg och 16 borttagningar
  1. 26 15
      mautrix_signal/portal.py
  2. 1 1
      requirements.txt

+ 26 - 15
mautrix_signal/portal.py

@@ -962,12 +962,21 @@ class Portal(DBPortal, BasePortal):
         async with self._create_room_lock:
             return await self._create_matrix_room(source, info)
 
-    async def _update_matrix_room(self, source: 'u.User', info: ChatInfo) -> None:
+    def _get_invite_content(self, double_puppet: Optional['p.Puppet']) -> Dict[str, Any]:
+        invite_content = {}
+        if double_puppet:
+            invite_content["fi.mau.will_auto_accept"] = True
         if self.is_direct:
-            puppet = await p.Puppet.get_by_custom_mxid(source.mxid)
-            if puppet:
-                await self.main_intent.invite_user(self.mxid, source.mxid, check_cache=True)
-                await puppet.intent.ensure_joined(self.mxid)
+            invite_content["is_direct"] = True
+        return invite_content
+
+    async def _update_matrix_room(self, source: 'u.User', info: ChatInfo) -> None:
+        puppet = await p.Puppet.get_by_custom_mxid(source.mxid)
+        await self.main_intent.invite_user(self.mxid, source.mxid, check_cache=True,
+                                           extra_content=self._get_invite_content(puppet))
+        if puppet:
+            did_join = await puppet.intent.ensure_joined(self.mxid)
+            if did_join and self.is_direct:
                 await source.update_direct_chats({self.main_intent.mxid: [self.mxid]})
 
         await self.update_info(source, info)
@@ -1030,7 +1039,7 @@ class Portal(DBPortal, BasePortal):
             "type": str(EventType.ROOM_POWER_LEVELS),
             "content": power_levels.serialize(),
         }]
-        invites = [source.mxid]
+        invites = []
         if self.config["bridge.encryption.default"] and self.matrix.e2ee:
             self.encrypted = True
             initial_state.append({
@@ -1069,20 +1078,22 @@ class Portal(DBPortal, BasePortal):
                 self.log.warning("Failed to add bridge bot "
                                  f"to new private chat {self.mxid}")
 
+        puppet = await p.Puppet.get_by_custom_mxid(source.mxid)
+        await self.main_intent.invite_user(self.mxid, source.mxid,
+                                           extra_content=self._get_invite_content(puppet))
+        if puppet:
+            try:
+                await source.update_direct_chats({self.main_intent.mxid: [self.mxid]})
+                await puppet.intent.join_room_by_id(self.mxid)
+            except MatrixError:
+                self.log.debug("Failed to join custom puppet into newly created portal",
+                               exc_info=True)
+
         await self.update()
         self.log.debug(f"Matrix room created: {self.mxid}")
         self.by_mxid[self.mxid] = self
         if not self.is_direct:
             await self._update_participants(source, info)
-        else:
-            puppet = await p.Puppet.get_by_custom_mxid(source.mxid)
-            if puppet:
-                try:
-                    await puppet.intent.join_room_by_id(self.mxid)
-                    await source.update_direct_chats({self.main_intent.mxid: [self.mxid]})
-                except MatrixError:
-                    self.log.debug("Failed to join custom puppet into newly created portal",
-                                   exc_info=True)
 
         # TODO
         # in_community = await source._community_helper.add_room(source._community_id, self.mxid)

+ 1 - 1
requirements.txt

@@ -4,5 +4,5 @@ commonmark>=0.8,<0.10
 aiohttp>=3,<4
 yarl>=1,<2
 attrs>=19.1
-mautrix>=0.10.3,<0.11
+mautrix>=0.10.4,<0.11
 asyncpg>=0.20,<0.25