Fix issues with multiplatform conversation displays

This commit is contained in:
2026-02-16 11:42:53 +00:00
parent cf651a3bd4
commit a70faa3576
10 changed files with 489 additions and 78 deletions

View File

@@ -1,6 +1,5 @@
import asyncio
import json
import os
from urllib.parse import quote_plus, urlparse
import aiohttp
@@ -25,10 +24,7 @@ if _signal_http_url:
SIGNAL_HOST = parsed.hostname or "signal"
SIGNAL_PORT = parsed.port or 8080
else:
if settings.DEBUG:
SIGNAL_HOST = "127.0.0.1"
else:
SIGNAL_HOST = "signal"
SIGNAL_HOST = "signal"
SIGNAL_PORT = 8080
SIGNAL_URL = f"{SIGNAL_HOST}:{SIGNAL_PORT}"
@@ -241,12 +237,10 @@ class HandleMessage(Command):
"raw_message": c.message.raw_message,
}
raw = json.loads(c.message.raw_message)
dest = (
raw.get("envelope", {})
.get("syncMessage", {})
.get("sentMessage", {})
.get("destinationUuid")
sent_message = (
raw.get("envelope", {}).get("syncMessage", {}).get("sentMessage", {}) or {}
)
dest = sent_message.get("destinationUuid")
account = raw.get("account", "")
source_name = raw.get("envelope", {}).get("sourceName", "")
@@ -271,25 +265,22 @@ class HandleMessage(Command):
envelope_source_uuid = envelope.get("sourceUuid")
envelope_source_number = envelope.get("sourceNumber")
envelope_source = envelope.get("source")
destination_number = (
raw.get("envelope", {})
.get("syncMessage", {})
.get("sentMessage", {})
.get("destination")
)
destination_number = sent_message.get("destination")
primary_identifier = dest if is_from_bot else source_uuid
if is_from_bot:
# Outbound events must route only by destination identity.
# Including the bot's own UUID/number leaks messages across people
# if "self" identifiers are linked anywhere.
identifier_candidates = _identifier_candidates(
dest,
destination_number,
primary_identifier,
)
if dest or destination_number:
# Sync "sentMessage" events are outbound; route by destination only.
# This prevents copying one outbound message into multiple people
# when source fields include the bot's own identifier.
identifier_candidates = _identifier_candidates(dest, destination_number)
elif is_from_bot:
identifier_candidates = _identifier_candidates(primary_identifier)
else:
identifier_candidates = _identifier_candidates(
bot_identifiers = {
str(c.bot.bot_uuid or "").strip(),
str(getattr(c.bot, "phone_number", "") or "").strip(),
}
incoming_candidates = _identifier_candidates(
primary_identifier,
source_uuid,
source_number,
@@ -297,8 +288,12 @@ class HandleMessage(Command):
envelope_source_uuid,
envelope_source_number,
envelope_source,
dest,
)
identifier_candidates = [
value
for value in incoming_candidates
if value and value not in bot_identifiers
]
if not identifier_candidates:
log.warning("No Signal identifier available for message routing.")
return
@@ -598,12 +593,13 @@ class HandleMessage(Command):
class SignalClient(ClientBase):
def __init__(self, ur, *args, **kwargs):
super().__init__(ur, *args, **kwargs)
signal_number = str(getattr(settings, "SIGNAL_NUMBER", "")).strip()
self.client = NewSignalBot(
ur,
self.service,
{
"signal_service": SIGNAL_URL,
"phone_number": "+447700900000",
"phone_number": signal_number,
},
)