Fix Signal compose live updates and self-chat direction
This commit is contained in:
@@ -22,6 +22,24 @@ def _safe_int(value, default=0):
|
||||
return default
|
||||
|
||||
|
||||
def _message_fingerprint(message_row):
|
||||
row = dict(message_row or {})
|
||||
fields = {
|
||||
"id": str(row.get("id") or ""),
|
||||
"ts": int(_safe_int(row.get("ts"), 0)),
|
||||
"text": str(row.get("text") or ""),
|
||||
"display_text": str(row.get("display_text") or ""),
|
||||
"outgoing": bool(row.get("outgoing")),
|
||||
"read_ts": int(_safe_int(row.get("read_ts"), 0)),
|
||||
"delivered_ts": int(_safe_int(row.get("delivered_ts"), 0)),
|
||||
"receipt_payload": row.get("receipt_payload") or {},
|
||||
"reactions": row.get("reactions") or [],
|
||||
"source_service": str(row.get("source_service") or ""),
|
||||
"source_label": str(row.get("source_label") or ""),
|
||||
}
|
||||
return json.dumps(fields, sort_keys=True, separators=(",", ":"))
|
||||
|
||||
|
||||
def _load_since(user_id, service, identifier, person_id, after_ts, limit):
|
||||
person = None
|
||||
person_identifier = None
|
||||
@@ -174,7 +192,7 @@ async def compose_ws_application(scope, receive, send):
|
||||
last_ts = 0
|
||||
limit = 100
|
||||
last_typing_key = ""
|
||||
sent_message_ids = set()
|
||||
sent_message_state = {}
|
||||
|
||||
while True:
|
||||
event = None
|
||||
@@ -205,10 +223,11 @@ async def compose_ws_application(scope, receive, send):
|
||||
messages = []
|
||||
for msg in raw_messages:
|
||||
message_id = str((msg or {}).get("id") or "").strip()
|
||||
if message_id and message_id in sent_message_ids:
|
||||
continue
|
||||
if message_id:
|
||||
sent_message_ids.add(message_id)
|
||||
fingerprint = _message_fingerprint(msg)
|
||||
if sent_message_state.get(message_id) == fingerprint:
|
||||
continue
|
||||
sent_message_state[message_id] = fingerprint
|
||||
messages.append(msg)
|
||||
latest = _safe_int(payload.get("last_ts"), last_ts)
|
||||
if resolved_person_id <= 0:
|
||||
|
||||
Reference in New Issue
Block a user