Allow sharing conversations

This commit is contained in:
2026-03-02 03:23:52 +00:00
parent b94219fc5b
commit 00588ed1b8
5 changed files with 903 additions and 134 deletions

View File

@@ -440,10 +440,14 @@ def _serialize_message(msg: Message) -> dict:
read_delta = int(read_ts - ts_val) if read_ts and ts_val else None
# Human friendly delta strings
delivered_delta_display = (
_format_gap_duration(delivered_delta) if delivered_delta is not None else ""
_format_gap_duration(delivered_delta)
if delivered_delta is not None and int(delivered_delta) > 0
else ""
)
read_delta_display = (
_format_gap_duration(read_delta) if read_delta is not None else ""
_format_gap_duration(read_delta)
if read_delta is not None and int(read_delta) > 0
else ""
)
# Receipt payload and metadata
receipt_payload = msg.receipt_payload or {}
@@ -850,8 +854,11 @@ def _serialize_messages_with_artifacts(
and current_ts >= prev_ts
):
block_gap_ms = current_ts - prev_ts
serialized[idx]["block_gap_ms"] = int(block_gap_ms)
serialized[idx]["block_gap_display"] = _format_gap_duration(block_gap_ms)
if int(block_gap_ms) > 0:
serialized[idx]["block_gap_ms"] = int(block_gap_ms)
serialized[idx]["block_gap_display"] = _format_gap_duration(
block_gap_ms
)
if (
prev_msg is not None
@@ -937,6 +944,23 @@ def _glance_items_from_state(gap_fragment=None, metric_fragments=None, person_id
"url": _insight_detail_url(person_id, metric.get("slug")),
}
)
if not metric_fragments:
items.extend(
[
{
"label": "Stability Score",
"value": "n/a",
"tooltip": "No stability score available yet for this conversation.",
"url": "",
},
{
"label": "Stability Confidence",
"value": "n/a",
"tooltip": "No stability confidence available yet for this conversation.",
"url": "",
},
]
)
return items[:3]
@@ -1767,7 +1791,11 @@ def _command_options_for_channel(user, service: str, identifier: str) -> list[di
def _compose_urls(service, identifier, person_id):
query = {"service": service, "identifier": identifier}
service_key = _default_service(service)
identifier_value = str(identifier or "").strip()
if service_key == "whatsapp" and "@" in identifier_value:
identifier_value = identifier_value.split("@", 1)[0].strip()
query = {"service": service_key, "identifier": identifier_value}
if person_id:
query["person"] = str(person_id)
payload = urlencode(query)
@@ -1997,14 +2025,26 @@ def _recent_manual_contacts(
if not all_rows:
return []
def _normalize_recent_identifier(service_value: str, identifier_value: str) -> str:
svc = _default_service(service_value)
raw = str(identifier_value or "").strip()
if svc == "whatsapp" and "@" in raw:
return raw.split("@", 1)[0].strip()
return raw
current_service_key = _default_service(current_service)
current_identifier_value = str(current_identifier or "").strip()
current_identifier_value = _normalize_recent_identifier(
current_service_key, str(current_identifier or "").strip()
)
current_person_id = str(current_person.id) if current_person else ""
row_by_key = {
(
str(row.get("service") or "").strip().lower(),
str(row.get("identifier") or "").strip(),
_normalize_recent_identifier(
str(row.get("service") or "").strip().lower(),
str(row.get("identifier") or "").strip(),
),
): row
for row in all_rows
}
@@ -2019,7 +2059,9 @@ def _recent_manual_contacts(
if not person_id:
continue
service_key = _default_service(link.service)
identifier_value = str(link.identifier or "").strip()
identifier_value = _normalize_recent_identifier(
service_key, str(link.identifier or "").strip()
)
if not identifier_value:
continue
by_person_service.setdefault(person_id, {})
@@ -2042,9 +2084,13 @@ def _recent_manual_contacts(
.order_by("-ts", "-id")[:1000]
)
for service_value, identifier_value in recent_values:
service_key = _default_service(service_value)
normalized_identifier = _normalize_recent_identifier(
service_key, str(identifier_value or "").strip()
)
key = (
_default_service(service_value),
str(identifier_value or "").strip(),
service_key,
normalized_identifier,
)
if not key[1] or key in seen_keys:
continue
@@ -2113,6 +2159,9 @@ def _recent_manual_contacts(
).strip()
break
selected_identifier = selected_identifier or identifier_value
selected_identifier = _normalize_recent_identifier(
selected_service, selected_identifier
)
selected_urls = _compose_urls(
selected_service,
selected_identifier,
@@ -2134,6 +2183,7 @@ def _recent_manual_contacts(
svc_identifier = str(
(service_map.get(svc) or {}).get("identifier") or ""
).strip()
svc_identifier = _normalize_recent_identifier(svc, svc_identifier)
row[f"{svc}_identifier"] = svc_identifier
if svc_identifier:
svc_urls = _compose_urls(svc, svc_identifier, person_id)
@@ -2150,7 +2200,9 @@ def _recent_manual_contacts(
row["service_label"] = _service_label(service_key)
for svc in ("signal", "whatsapp", "instagram", "xmpp"):
row[f"{svc}_identifier"] = (
identifier_value if svc == service_key else ""
_normalize_recent_identifier(service_key, identifier_value)
if svc == service_key
else ""
)
row[f"{svc}_compose_url"] = (
row.get("compose_url") if svc == service_key else ""
@@ -2161,7 +2213,11 @@ def _recent_manual_contacts(
row["is_active"] = (
row.get("service") == current_service_key
and str(row.get("identifier") or "").strip() == current_identifier_value
and _normalize_recent_identifier(
str(row.get("service") or "").strip().lower(),
str(row.get("identifier") or "").strip(),
)
== current_identifier_value
)
rows.append(row)
if len(rows) >= limit: