Fix Signal emoji sync

This commit is contained in:
2026-03-03 17:50:46 +00:00
parent 506ea8a3b8
commit 9646931181
2 changed files with 169 additions and 1 deletions

View File

@@ -1039,6 +1039,23 @@ class SignalClient(ClientBase):
)
if result is False or result is None:
raise RuntimeError("signal_send_failed")
legacy_message_id = str(metadata.get("legacy_message_id") or "").strip()
if legacy_message_id and isinstance(result, int):
message_row = await sync_to_async(
lambda: Message.objects.filter(id=legacy_message_id).first()
)()
if message_row is not None:
update_fields = []
if int(message_row.delivered_ts or 0) <= 0:
message_row.delivered_ts = int(result)
update_fields.append("delivered_ts")
if str(message_row.source_message_id or "").strip() != str(result):
message_row.source_message_id = str(result)
update_fields.append("source_message_id")
if update_fields:
await sync_to_async(message_row.save)(
update_fields=update_fields
)
transport.set_runtime_command_result(
self.service,
command_id,
@@ -1275,6 +1292,45 @@ class SignalClient(ClientBase):
destination_uuid,
destination_number,
)
reaction_payload = _extract_signal_reaction(envelope)
if identifiers and isinstance(reaction_payload, dict):
source_uuid = str(
envelope.get("sourceUuid") or envelope.get("source") or ""
).strip()
source_number = str(envelope.get("sourceNumber") or "").strip()
for identifier in identifiers:
try:
await history.apply_reaction(
identifier.user,
identifier,
target_message_id="",
target_ts=int(reaction_payload.get("target_ts") or 0),
emoji=str(reaction_payload.get("emoji") or ""),
source_service="signal",
actor=(source_uuid or source_number or ""),
remove=bool(reaction_payload.get("remove")),
payload=reaction_payload.get("raw") or {},
)
except Exception as exc:
self.log.warning(
"signal raw sync reaction history apply failed: %s", exc
)
try:
await self.ur.xmpp.client.apply_external_reaction(
identifier.user,
identifier,
source_service="signal",
emoji=str(reaction_payload.get("emoji") or ""),
remove=bool(reaction_payload.get("remove")),
upstream_message_id="",
upstream_ts=int(reaction_payload.get("target_ts") or 0),
actor=(source_uuid or source_number or ""),
payload=reaction_payload.get("raw") or {},
)
except Exception as exc:
self.log.warning(
"signal raw sync reaction relay to XMPP failed: %s", exc
)
if identifiers and text:
ts_raw = (
sync_sent_message.get("timestamp")
@@ -1358,6 +1414,21 @@ class SignalClient(ClientBase):
return
identifiers = await self._resolve_signal_identifiers(source_uuid, source_number)
reaction_payload = _extract_signal_reaction(envelope)
if (not identifiers) and isinstance(reaction_payload, dict):
# Sync reactions from our own linked device can arrive with source=our
# account and destination=<contact>. Resolve by destination as fallback.
destination_uuid = str(
envelope.get("destinationServiceId")
or envelope.get("destinationUuid")
or ""
).strip()
destination_number = str(envelope.get("destinationNumber") or "").strip()
if destination_uuid or destination_number:
identifiers = await self._resolve_signal_identifiers(
destination_uuid,
destination_number,
)
if not identifiers:
identifiers = await self._auto_link_single_user_signal_identifier(
source_uuid, source_number
@@ -1371,7 +1442,6 @@ class SignalClient(ClientBase):
)
return
reaction_payload = _extract_signal_reaction(envelope)
if isinstance(reaction_payload, dict):
for identifier in identifiers:
try: