comparison libervia/web/pages/chat/_browser/__init__.py @ 1613:c4407befc52a

browser (chat): fix attachments URL for messages.
author Goffi <goffi@goffi.org>
date Mon, 17 Jun 2024 17:37:15 +0200
parents 19c83dd943df
children
comparison
equal deleted inserted replaced
1612:ebd538cb26cb 1613:c4407befc52a
255 if chat_type == "group": 255 if chat_type == "group":
256 await cache.fill_identities([str(from_jid)]) 256 await cache.fill_identities([str(from_jid)])
257 else: 257 else:
258 await cache.fill_identities([str(jid.JID(from_jid).bare)]) 258 await cache.fill_identities([str(jid.JID(from_jid).bare)])
259 from_jid = from_jid.bare 259 from_jid = from_jid.bare
260 attachments = extra.get("attachments", [])
261 for attachment in attachments:
262 if "url" not in attachment:
263 try:
264 attachment["url"] = next(
265 s['url'] for s in attachment["sources"] if 'url' in s
266 )
267 except (StopIteration, KeyError):
268 log.warning(
269 f"An attachment has no URL: {attachment}"
270 )
260 msg_data = { 271 msg_data = {
261 "id": uid, 272 "id": uid,
262 "timestamp": extra.get("updated", timestamp), 273 "timestamp": extra.get("updated", timestamp),
263 "type": mess_type, 274 "type": mess_type,
264 "from_": str(from_jid), 275 "from_": str(from_jid),
266 "subject": subject_data.get("") or next(iter(subject_data.values()), ""), 277 "subject": subject_data.get("") or next(iter(subject_data.values()), ""),
267 "type": mess_type, 278 "type": mess_type,
268 "reeceived": extra.get("received_timestamp") or timestamp, 279 "reeceived": extra.get("received_timestamp") or timestamp,
269 "encrypted": extra.get("encrypted", False), 280 "encrypted": extra.get("encrypted", False),
270 "received": extra.get("received", False), 281 "received": extra.get("received", False),
271 "attachments": extra.get("attachments", []), 282 "attachments": attachments,
272 "extra": extra 283 "extra": extra
273 } 284 }
274 for key in ("thread", "thread_parent", "delay_sender", "info_type"): 285 for key in ("thread", "thread_parent", "delay_sender", "info_type"):
275 value = extra.get(key) 286 value = extra.get(key)
276 if value is not None: 287 if value is not None: