소스 검색

Add blank quoted attachment to trick Signal iOS into rendering replies properly

Tulir Asokan 3 년 전
부모
커밋
498e0f2bab
2개의 변경된 파일19개의 추가작업 그리고 8개의 파일을 삭제
  1. 15 8
      mausignald/types.py
  2. 4 0
      mautrix_signal/portal.py

+ 15 - 8
mausignald/types.py

@@ -234,12 +234,26 @@ class Attachment(SerializableAttrs):
     outgoing_filename: Optional[str] = field(default=None, json="filename")
 
 
+@dataclass
+class Mention(SerializableAttrs):
+    uuid: UUID
+    length: int
+    start: int = 0
+
+
+@dataclass
+class QuotedAttachment(SerializableAttrs):
+    content_type: Optional[str] = field(default=None, json="contentType")
+    filename: Optional[str] = field(default=None, json="fileName")
+
+
 @dataclass
 class Quote(SerializableAttrs):
     id: int
     author: Address
     text: Optional[str] = None
-    # TODO: attachments, mentions
+    attachments: Optional[List[QuotedAttachment]] = None
+    mentions: Optional[List[Mention]] = None
 
 
 @dataclass(kw_only=True)
@@ -263,13 +277,6 @@ class RemoteDelete(SerializableAttrs):
     target_sent_timestamp: int = field(json="targetSentTimestamp")
 
 
-@dataclass
-class Mention(SerializableAttrs):
-    uuid: UUID
-    length: int
-    start: int = 0
-
-
 @dataclass
 class MessageData(SerializableAttrs):
     timestamp: int

+ 4 - 0
mautrix_signal/portal.py

@@ -42,6 +42,7 @@ from mausignald.types import (
     MessageData,
     Profile,
     Quote,
+    QuotedAttachment,
     Reaction,
     Sticker,
 )
@@ -346,6 +347,9 @@ class Portal(DBPortal, BasePortal):
             # TODO include actual text? either store in db or fetch event from homeserver
             if reply is not None:
                 quote = Quote(id=reply.timestamp, author=reply.sender, text="")
+                # TODO only send this when it's actually a reply to an attachment?
+                #      Neither Signal Android nor iOS seem to care though, so this works too
+                quote.attachments = [QuotedAttachment("", "")]
 
         attachments: list[Attachment] | None = None
         attachment_path: str | None = None