From 030be64c4514d5bc6ee81bfaae5470855e134630 Mon Sep 17 00:00:00 2001 From: Goffi Date: Fri, 4 Jul 2025 12:30:20 +0200 Subject: [PATCH] plugin XEP-0428: Add missing "for" attribute: The "for" attribute was missing from element. rel 461 --- libervia/backend/plugins/plugin_xep_0424.py | 7 +++++-- libervia/backend/plugins/plugin_xep_0428.py | 18 ++++++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/libervia/backend/plugins/plugin_xep_0424.py b/libervia/backend/plugins/plugin_xep_0424.py index 3ffc270a..6d362fb0 100644 --- a/libervia/backend/plugins/plugin_xep_0424.py +++ b/libervia/backend/plugins/plugin_xep_0424.py @@ -16,7 +16,7 @@ # along with this program. If not, see . import time -from typing import Any, Dict +from typing import Any, Dict, cast from sqlalchemy.orm.attributes import flag_modified from twisted.internet import defer @@ -31,6 +31,7 @@ from libervia.backend.core.core_types import MessageDataLegacy, SatXMPPEntity from libervia.backend.core.i18n import D_, _ from libervia.backend.core.log import getLogger from libervia.backend.memory.sqla_mapping import History +from libervia.backend.plugins.plugin_xep_0428 import XEP_0428 from libervia.backend.tools.common import data_format log = getLogger(__name__) @@ -111,8 +112,10 @@ class XEP_0424: message_elt["type"] = history.type retract_elt = message_elt.addElement((NS_MESSAGE_RETRACT, "retract")) retract_elt["id"] = retract_id - self.host.plugins["XEP-0428"].add_fallback_elt( + fallback = cast(XEP_0428, self.host.plugins["XEP-0428"]) + fallback.add_fallback_elt( message_elt, + NS_MESSAGE_RETRACT, "[A message retraction has been requested, but your client doesn't support " "it]", ) diff --git a/libervia/backend/plugins/plugin_xep_0428.py b/libervia/backend/plugins/plugin_xep_0428.py index 7c1054cc..54352d3c 100644 --- a/libervia/backend/plugins/plugin_xep_0428.py +++ b/libervia/backend/plugins/plugin_xep_0428.py @@ -43,25 +43,35 @@ PLUGIN_INFO = { NS_FALLBACK = "urn:xmpp:fallback:0" -class XEP_0428(object): +class XEP_0428: def __init__(self, host): log.info(_("XEP-0428 (Fallback Indication) plugin initialization")) host.register_namespace("fallback", NS_FALLBACK) def add_fallback_elt( - self, message_elt: domish.Element, msg: Optional[str] = None + self, + message_elt: domish.Element, + for_: str, + msg: str|None = None ) -> None: """Add the fallback indication element @param message_elt: element where the indication must be set + @param for_: Specification namespace that the fallback is meant to replace. + see https://xmpp.org/extensions/xep-0428.html#sect-idm46381699903600 @param msg: message to show as fallback Will be added as """ - message_elt.addElement((NS_FALLBACK, "fallback")) + fallback_elt = message_elt.addElement((NS_FALLBACK, "fallback")) + fallback_elt["for"] = for_ if msg is not None: - message_elt.addElement("body", content=msg) + body_elt = message_elt.body + if body_elt is None: + message_elt.addElement("body", content=msg) + else: + body_elt.addContent(msg) def has_fallback(self, message_elt: domish.Element) -> bool: """Tell if a message has a fallback indication"""