瀏覽代碼

Bridge group name changes

Tulir Asokan 4 年之前
父節點
當前提交
6677e5f682
共有 5 個文件被更改,包括 29 次插入17 次删除
  1. 15 3
      ROADMAP.md
  2. 3 4
      mausignald/signald.py
  3. 3 3
      mausignald/types.py
  4. 6 7
      mautrix_signal/portal.py
  5. 2 0
      mautrix_signal/signal.py

+ 15 - 3
ROADMAP.md

@@ -12,12 +12,15 @@
       * [ ] Locations
       * [ ] Locations
       * [ ] Stickers
       * [ ] Stickers
   * [x] Message reactions
   * [x] Message reactions
+  * [ ] Group info changes
+    * [ ] Name
+    * [ ] Avatar
   * [ ] Typing notifications
   * [ ] Typing notifications
   * [ ] Read receipts
   * [ ] Read receipts
 * Signal → Matrix
 * Signal → Matrix
   * [ ] Message content
   * [ ] Message content
     * [x] Text
     * [x] Text
-    * [x] Media
+    * [ ] Media
       * [x] Images
       * [x] Images
       * [x] Voice notes
       * [x] Voice notes
       * [x] Files
       * [x] Files
@@ -26,14 +29,23 @@
       * [x] Locations
       * [x] Locations
       * [x] Stickers
       * [x] Stickers
   * [x] Message reactions
   * [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
   * [ ] Typing notifications
   * [x] Read receipts
   * [x] Read receipts
   * [ ] Disappearing messages
   * [ ] Disappearing messages
 * Misc
 * Misc
   * [x] Automatic portal creation
   * [x] Automatic portal creation
     * [x] At startup
     * [x] At startup
-    * [ ] When receiving message
+    * [x] When receiving message
   * [ ] Provisioning API for logging in
   * [ ] Provisioning API for logging in
   * [ ] Private chat creation by inviting Matrix puppet of Signal user to new room
   * [ ] 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
   * [ ] 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 .rpc import SignaldRPCClient
 from .errors import UnexpectedError, UnexpectedResponse, make_linking_error
 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')
 T = TypeVar('T')
 EventHandler = Callable[[T], Awaitable[None]]
 EventHandler = Callable[[T], Awaitable[None]]
@@ -118,9 +117,9 @@ class SignaldClient(SignaldRPCClient):
         contacts = await self.request("list_contacts", "contact_list", username=username)
         contacts = await self.request("list_contacts", "contact_list", username=username)
         return [Contact.deserialize(contact) for contact in contacts]
         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)
         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]:
     async def get_profile(self, username: str, address: Address) -> Optional[Profile]:
         try:
         try:

+ 3 - 3
mausignald/types.py

@@ -55,11 +55,11 @@ class Profile(SerializableAttrs['Profile']):
 class Group(SerializableAttrs['Group']):
 class Group(SerializableAttrs['Group']):
     group_id: str = attr.ib(metadata={"json": "groupId"})
     group_id: str = attr.ib(metadata={"json": "groupId"})
     name: str
     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: [])
     members: List[Address] = attr.ib(factory=lambda: [])
     avatar_id: int = attr.ib(default=0, metadata={"json": "avatarId"})
     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 time
 import os
 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.appservice import AppService, IntentAPI
 from mautrix.bridge import BasePortal
 from mautrix.bridge import BasePortal
 from mautrix.types import (EventID, MessageEventContent, RoomID, EventType, MessageType,
 from mautrix.types import (EventID, MessageEventContent, RoomID, EventType, MessageType,
@@ -51,7 +51,7 @@ except ImportError:
 
 
 StateBridge = EventType.find("m.bridge", EventType.Class.STATE)
 StateBridge = EventType.find("m.bridge", EventType.Class.STATE)
 StateHalfShotBridge = EventType.find("uk.half-shot.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):
 class Portal(DBPortal, BasePortal):
@@ -434,8 +434,7 @@ class Portal(DBPortal, BasePortal):
         if not isinstance(info, Group):
         if not isinstance(info, Group):
             raise ValueError(f"Unexpected type for group update_info: {type(info)}")
             raise ValueError(f"Unexpected type for group update_info: {type(info)}")
         changed = await self._update_name(info.name)
         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:
         if changed:
             await self.update_bridge_info()
             await self.update_bridge_info()
             await self.update()
             await self.update()
@@ -459,7 +458,7 @@ class Portal(DBPortal, BasePortal):
         return False
         return False
 
 
     async def _update_participants(self, participants: List[Address]) -> None:
     async def _update_participants(self, participants: List[Address]) -> None:
-        if not self.mxid:
+        if not self.mxid or not participants:
             return
             return
 
 
         for address in participants:
         for address in participants:
@@ -602,7 +601,7 @@ class Portal(DBPortal, BasePortal):
         await self.update()
         await self.update()
         self.log.debug(f"Matrix room created: {self.mxid}")
         self.log.debug(f"Matrix room created: {self.mxid}")
         self.by_mxid[self.mxid] = self
         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)
             await self._update_participants(info.members)
         else:
         else:
             puppet = await p.Puppet.get_by_custom_mxid(source.mxid)
             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)
             await portal.handle_signal_reaction(sender, msg.reaction)
         if msg.body or msg.attachments or msg.sticker:
         if msg.body or msg.attachments or msg.sticker:
             await portal.handle_signal_message(sender, msg)
             await portal.handle_signal_message(sender, msg)
+        if msg.group and msg.group.type == "UPDATE":
+            await portal.update_info(msg.group)
 
 
     @staticmethod
     @staticmethod
     async def handle_own_receipts(sender: 'pu.Puppet', receipts: List[OwnReadReceipt]) -> None:
     async def handle_own_receipts(sender: 'pu.Puppet', receipts: List[OwnReadReceipt]) -> None: