Kaynağa Gözat

Bridge group name changes

Tulir Asokan 4 yıl önce
ebeveyn
işleme
6677e5f682

+ 15 - 3
ROADMAP.md

@@ -12,12 +12,15 @@
       * [ ] Locations
       * [ ] Stickers
   * [x] Message reactions
+  * [ ] Group info changes
+    * [ ] Name
+    * [ ] Avatar
   * [ ] Typing notifications
   * [ ] Read receipts
 * Signal → Matrix
   * [ ] Message content
     * [x] Text
-    * [x] Media
+    * [ ] Media
       * [x] Images
       * [x] Voice notes
       * [x] Files
@@ -26,14 +29,23 @@
       * [x] Locations
       * [x] Stickers
   * [x] Message reactions
-  * [ ] User and group avatars
+  * [ ] Initial profile info
+    * [x] User displayname
+    * [ ] User avatar
+    * [x] Group name
+    * [ ] Group avatar
+  * [ ] Profile info changes
+    * [ ] User displayname
+    * [ ] User avatar
+    * [x] Group name
+    * [ ] Group avatar
   * [ ] Typing notifications
   * [x] Read receipts
   * [ ] Disappearing messages
 * Misc
   * [x] Automatic portal creation
     * [x] At startup
-    * [ ] When receiving message
+    * [x] When receiving message
   * [ ] Provisioning API for logging in
   * [ ] Private chat creation by inviting Matrix puppet of Signal user to new room
   * [ ] Option to use own Matrix account for messages sent from other Signal clients

+ 3 - 4
mausignald/signald.py

@@ -11,8 +11,7 @@ from mautrix.util.logging import TraceLogger
 
 from .rpc import SignaldRPCClient
 from .errors import UnexpectedError, UnexpectedResponse, make_linking_error
-from .types import (Address, Quote, Attachment, Reaction, Account, Message, Contact, FullGroup,
-                    Profile)
+from .types import Address, Quote, Attachment, Reaction, Account, Message, Contact, Group, Profile
 
 T = TypeVar('T')
 EventHandler = Callable[[T], Awaitable[None]]
@@ -118,9 +117,9 @@ class SignaldClient(SignaldRPCClient):
         contacts = await self.request("list_contacts", "contact_list", username=username)
         return [Contact.deserialize(contact) for contact in contacts]
 
-    async def list_groups(self, username: str) -> List[FullGroup]:
+    async def list_groups(self, username: str) -> List[Group]:
         resp = await self.request("list_groups", "group_list", username=username)
-        return [FullGroup.deserialize(group) for group in resp["groups"]]
+        return [Group.deserialize(group) for group in resp["groups"]]
 
     async def get_profile(self, username: str, address: Address) -> Optional[Profile]:
         try:

+ 3 - 3
mausignald/types.py

@@ -55,11 +55,11 @@ class Profile(SerializableAttrs['Profile']):
 class Group(SerializableAttrs['Group']):
     group_id: str = attr.ib(metadata={"json": "groupId"})
     name: str
-    type: Optional[str] = None
 
+    # Sometimes "UPDATE"
+    type: Optional[str] = None
 
-@dataclass
-class FullGroup(Group, SerializableAttrs['FullGroup']):
+    # Not always present
     members: List[Address] = attr.ib(factory=lambda: [])
     avatar_id: int = attr.ib(default=0, metadata={"json": "avatarId"})
 

+ 6 - 7
mautrix_signal/portal.py

@@ -23,8 +23,8 @@ import os.path
 import time
 import os
 
-from mausignald.types import (Address, MessageData, Reaction, Quote, FullGroup, Group, Contact,
-                              Profile, Attachment)
+from mausignald.types import (Address, MessageData, Reaction, Quote, Group, Contact, Profile,
+                              Attachment)
 from mautrix.appservice import AppService, IntentAPI
 from mautrix.bridge import BasePortal
 from mautrix.types import (EventID, MessageEventContent, RoomID, EventType, MessageType,
@@ -51,7 +51,7 @@ except ImportError:
 
 StateBridge = EventType.find("m.bridge", EventType.Class.STATE)
 StateHalfShotBridge = EventType.find("uk.half-shot.bridge", EventType.Class.STATE)
-ChatInfo = Union[FullGroup, Group, Contact, Profile, Address]
+ChatInfo = Union[Group, Contact, Profile, Address]
 
 
 class Portal(DBPortal, BasePortal):
@@ -434,8 +434,7 @@ class Portal(DBPortal, BasePortal):
         if not isinstance(info, Group):
             raise ValueError(f"Unexpected type for group update_info: {type(info)}")
         changed = await self._update_name(info.name)
-        if isinstance(info, FullGroup):
-            await self._update_participants(info.members)
+        await self._update_participants(info.members)
         if changed:
             await self.update_bridge_info()
             await self.update()
@@ -459,7 +458,7 @@ class Portal(DBPortal, BasePortal):
         return False
 
     async def _update_participants(self, participants: List[Address]) -> None:
-        if not self.mxid:
+        if not self.mxid or not participants:
             return
 
         for address in participants:
@@ -602,7 +601,7 @@ class Portal(DBPortal, BasePortal):
         await self.update()
         self.log.debug(f"Matrix room created: {self.mxid}")
         self.by_mxid[self.mxid] = self
-        if not self.is_direct and isinstance(info, FullGroup):
+        if not self.is_direct:
             await self._update_participants(info.members)
         else:
             puppet = await p.Puppet.get_by_custom_mxid(source.mxid)

+ 2 - 0
mautrix_signal/signal.py

@@ -82,6 +82,8 @@ class SignalHandler(SignaldClient):
             await portal.handle_signal_reaction(sender, msg.reaction)
         if msg.body or msg.attachments or msg.sticker:
             await portal.handle_signal_message(sender, msg)
+        if msg.group and msg.group.type == "UPDATE":
+            await portal.update_info(msg.group)
 
     @staticmethod
     async def handle_own_receipts(sender: 'pu.Puppet', receipts: List[OwnReadReceipt]) -> None: