Merge PR #871: fix(signal): use media_urls/media_types in MessageEvent construction

This commit is contained in:
teknium1 2026-03-10 15:00:08 -07:00
commit 53be6afe92

View file

@ -104,6 +104,20 @@ def _is_audio_ext(ext: str) -> bool:
return ext.lower() in (".mp3", ".wav", ".ogg", ".m4a", ".aac") return ext.lower() in (".mp3", ".wav", ".ogg", ".m4a", ".aac")
_EXT_TO_MIME = {
".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".png": "image/png",
".gif": "image/gif", ".webp": "image/webp",
".ogg": "audio/ogg", ".mp3": "audio/mpeg", ".wav": "audio/wav",
".m4a": "audio/mp4", ".aac": "audio/aac",
".mp4": "video/mp4", ".pdf": "application/pdf", ".zip": "application/zip",
}
def _ext_to_mime(ext: str) -> str:
"""Map file extension to MIME type."""
return _EXT_TO_MIME.get(ext.lower(), "application/octet-stream")
def _render_mentions(text: str, mentions: list) -> str: def _render_mentions(text: str, mentions: list) -> str:
"""Replace Signal mention placeholders (\\uFFFC) with readable @identifiers. """Replace Signal mention placeholders (\\uFFFC) with readable @identifiers.
@ -404,9 +418,8 @@ class SignalAdapter(BasePlatformAdapter):
# Process attachments # Process attachments
attachments_data = data_message.get("attachments", []) attachments_data = data_message.get("attachments", [])
image_paths = [] media_urls = []
audio_path = None media_types = []
document_paths = []
if attachments_data and not getattr(self, "ignore_attachments", False): if attachments_data and not getattr(self, "ignore_attachments", False):
for att in attachments_data: for att in attachments_data:
@ -420,12 +433,10 @@ class SignalAdapter(BasePlatformAdapter):
try: try:
cached_path, ext = await self._fetch_attachment(att_id) cached_path, ext = await self._fetch_attachment(att_id)
if cached_path: if cached_path:
if _is_image_ext(ext): # Use contentType from Signal if available, else map from extension
image_paths.append(cached_path) content_type = att.get("contentType") or _ext_to_mime(ext)
elif _is_audio_ext(ext): media_urls.append(cached_path)
audio_path = cached_path media_types.append(content_type)
else:
document_paths.append(cached_path)
except Exception: except Exception:
logger.exception("Signal: failed to fetch attachment %s", att_id) logger.exception("Signal: failed to fetch attachment %s", att_id)
@ -440,11 +451,12 @@ class SignalAdapter(BasePlatformAdapter):
chat_id_alt=group_id if is_group else None, chat_id_alt=group_id if is_group else None,
) )
# Determine message type # Determine message type from media
msg_type = MessageType.TEXT msg_type = MessageType.TEXT
if audio_path: if media_types:
if any(mt.startswith("audio/") for mt in media_types):
msg_type = MessageType.VOICE msg_type = MessageType.VOICE
elif image_paths: elif any(mt.startswith("image/") for mt in media_types):
msg_type = MessageType.IMAGE msg_type = MessageType.IMAGE
# Parse timestamp from envelope data (milliseconds since epoch) # Parse timestamp from envelope data (milliseconds since epoch)
@ -462,9 +474,8 @@ class SignalAdapter(BasePlatformAdapter):
source=source, source=source,
text=text or "", text=text or "",
message_type=msg_type, message_type=msg_type,
image_paths=image_paths, media_urls=media_urls,
audio_path=audio_path, media_types=media_types,
document_paths=document_paths,
timestamp=timestamp, timestamp=timestamp,
) )