comparison libervia/web/pages/chat/_browser/__init__.py @ 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 52098b5bab8d
children c4407befc52a
comparison
equal deleted inserted replaced
1609:f3305832f3f6 1610:19c83dd943df
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 msg_data = {
261 "id": uid,
262 "timestamp": extra.get("updated", timestamp),
263 "type": mess_type,
264 "from_": str(from_jid),
265 "text": message_data.get("") or next(iter(message_data.values()), ""),
266 "subject": subject_data.get("") or next(iter(subject_data.values()), ""),
267 "type": mess_type,
268 "reeceived": extra.get("received_timestamp") or timestamp,
269 "encrypted": extra.get("encrypted", False),
270 "received": extra.get("received", False),
271 "attachments": extra.get("attachments", []),
272 "extra": extra
273 }
274 for key in ("thread", "thread_parent", "delay_sender", "info_type"):
275 value = extra.get(key)
276 if value is not None:
277 msg_data[key] = value
278
279 if xhtml:
280 msg_data["html"] = safe(xhtml)
260 281
261 return { 282 return {
262 "own_local_jid": str(own_local_jid), 283 "own_local_jid": str(own_local_jid),
263 "chat_type": chat_type, 284 "chat_type": chat_type,
264 "msg": { 285 "msg": msg_data,
265 "id": uid,
266 "timestamp": extra.get("updated", timestamp),
267 "type": mess_type,
268 "from_": str(from_jid),
269 "text": message_data.get("") or next(iter(message_data.values()), ""),
270 "subject": subject_data.get("") or next(iter(subject_data.values()), ""),
271 "type": mess_type,
272 "thread": extra.get("thread"),
273 "thread_parent": extra.get("thread_parent"),
274 "reeceived": extra.get("received_timestamp") or timestamp,
275 "delay_sender": extra.get("delay_sender"),
276 "info_type": extra.get("info_type"),
277 "html": safe(xhtml) if xhtml else None,
278 "encrypted": extra.get("encrypted", False),
279 "received": extra.get("received", False),
280 "attachments": extra.get("attachments", []),
281 "extra": extra
282 },
283 "identities": identities, 286 "identities": identities,
284 } 287 }
285 288
286 async def on_message_new( 289 async def on_message_new(
287 self, 290 self,