changeset 1610:19c83dd943df

browser (chat): don't set `None` value in message data used in template: `None` can behave unexpectedly with template, unsetting the value is safer.
author Goffi <goffi@goffi.org>
date Wed, 12 Jun 2024 23:09:12 +0200
parents f3305832f3f6
children b695b98851fc
files libervia/web/pages/chat/_browser/__init__.py
diffstat 1 files changed, 22 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/libervia/web/pages/chat/_browser/__init__.py	Fri May 31 11:10:04 2024 +0200
+++ b/libervia/web/pages/chat/_browser/__init__.py	Wed Jun 12 23:09:12 2024 +0200
@@ -257,29 +257,32 @@
         else:
             await cache.fill_identities([str(jid.JID(from_jid).bare)])
             from_jid = from_jid.bare
+        msg_data = {
+            "id": uid,
+            "timestamp": extra.get("updated", timestamp),
+            "type": mess_type,
+            "from_": str(from_jid),
+            "text": message_data.get("") or next(iter(message_data.values()), ""),
+            "subject": subject_data.get("") or next(iter(subject_data.values()), ""),
+            "type": mess_type,
+            "reeceived": extra.get("received_timestamp") or timestamp,
+            "encrypted": extra.get("encrypted", False),
+            "received": extra.get("received", False),
+            "attachments": extra.get("attachments", []),
+            "extra": extra
+        }
+        for key in ("thread", "thread_parent", "delay_sender", "info_type"):
+            value = extra.get(key)
+            if value is not None:
+                msg_data[key] = value
+
+        if xhtml:
+            msg_data["html"] = safe(xhtml)
 
         return {
             "own_local_jid": str(own_local_jid),
             "chat_type": chat_type,
-            "msg": {
-                "id": uid,
-                "timestamp": extra.get("updated", timestamp),
-                "type": mess_type,
-                "from_": str(from_jid),
-                "text": message_data.get("") or next(iter(message_data.values()), ""),
-                "subject": subject_data.get("") or next(iter(subject_data.values()), ""),
-                "type": mess_type,
-                "thread": extra.get("thread"),
-                "thread_parent": extra.get("thread_parent"),
-                "reeceived": extra.get("received_timestamp") or timestamp,
-                "delay_sender": extra.get("delay_sender"),
-                "info_type": extra.get("info_type"),
-                "html": safe(xhtml) if xhtml else None,
-                "encrypted": extra.get("encrypted", False),
-                "received": extra.get("received", False),
-                "attachments": extra.get("attachments", []),
-                "extra": extra
-            },
+            "msg": msg_data,
             "identities": identities,
         }