# HG changeset patch # User Goffi # Date 1718638635 -7200 # Node ID c4407befc52a57bf12387c337f8030a599f908cb # Parent ebd538cb26cbf32153985076a5ca397d9cb4a3b9 browser (chat): fix attachments URL for messages. diff -r ebd538cb26cb -r c4407befc52a libervia/web/pages/chat/_browser/__init__.py --- a/libervia/web/pages/chat/_browser/__init__.py Wed Jun 12 23:11:08 2024 +0200 +++ b/libervia/web/pages/chat/_browser/__init__.py Mon Jun 17 17:37:15 2024 +0200 @@ -257,6 +257,17 @@ else: await cache.fill_identities([str(jid.JID(from_jid).bare)]) from_jid = from_jid.bare + attachments = extra.get("attachments", []) + for attachment in attachments: + if "url" not in attachment: + try: + attachment["url"] = next( + s['url'] for s in attachment["sources"] if 'url' in s + ) + except (StopIteration, KeyError): + log.warning( + f"An attachment has no URL: {attachment}" + ) msg_data = { "id": uid, "timestamp": extra.get("updated", timestamp), @@ -268,7 +279,7 @@ "reeceived": extra.get("received_timestamp") or timestamp, "encrypted": extra.get("encrypted", False), "received": extra.get("received", False), - "attachments": extra.get("attachments", []), + "attachments": attachments, "extra": extra } for key in ("thread", "thread_parent", "delay_sender", "info_type"):