Fix Signal messages and replies

This commit is contained in:
2026-03-03 15:51:58 +00:00
parent 56c620473f
commit d6bd56dace
31 changed files with 3317 additions and 668 deletions

View File

@@ -56,18 +56,83 @@ def _find_origin_tag(value: Any, depth: int = 0) -> str:
def _extract_signal_reply(raw_payload: dict[str, Any]) -> dict[str, str]:
envelope = _as_dict((raw_payload or {}).get("envelope"))
data_message = _as_dict(
envelope.get("dataMessage")
or envelope.get("syncMessage", {}).get("sentMessage", {}).get("message")
sync_message = _as_dict(envelope.get("syncMessage"))
sent_message = _as_dict(sync_message.get("sentMessage"))
data_candidates = [
_as_dict(envelope.get("dataMessage")),
_as_dict(sent_message.get("message")),
_as_dict(sent_message),
_as_dict((raw_payload or {}).get("dataMessage")),
_as_dict(raw_payload),
]
quote_key_candidates = (
"id",
"targetSentTimestamp",
"targetTimestamp",
"quotedMessageId",
"quoted_message_id",
"quotedMessageID",
"messageId",
"message_id",
"timestamp",
)
quote = _as_dict(data_message.get("quote"))
quote_id = _clean(quote.get("id"))
if quote_id:
return {
"reply_source_message_id": quote_id,
"reply_source_service": "signal",
"reply_source_chat_id": "",
}
quote_author_candidates = (
"author",
"authorUuid",
"authorAci",
"authorNumber",
"source",
"sourceNumber",
"sourceUuid",
)
quote_candidates: list[dict[str, Any]] = []
for data_message in data_candidates:
if not data_message:
continue
direct_quote = _as_dict(data_message.get("quote") or data_message.get("Quote"))
if direct_quote:
quote_candidates.append(direct_quote)
stack = [data_message]
while stack:
current = stack.pop()
if not isinstance(current, dict):
continue
for key, value in current.items():
if isinstance(value, dict):
key_text = str(key or "").strip().lower()
if "quote" in key_text or "reply" in key_text:
quote_candidates.append(_as_dict(value))
stack.append(value)
elif isinstance(value, list):
for item in value:
if isinstance(item, dict):
stack.append(item)
for quote in quote_candidates:
quote_id = ""
for key in quote_key_candidates:
quote_id = _clean(quote.get(key))
if quote_id:
break
if not quote_id:
nested = _as_dict(quote.get("id"))
if nested:
for key in quote_key_candidates:
quote_id = _clean(nested.get(key))
if quote_id:
break
if quote_id:
reply_chat_id = ""
for key in quote_author_candidates:
reply_chat_id = _clean(quote.get(key))
if reply_chat_id:
break
return {
"reply_source_message_id": quote_id,
"reply_source_service": "signal",
"reply_source_chat_id": reply_chat_id,
}
return {}