Mercurial > libervia-backend
diff libervia/backend/plugins/plugin_xep_0428.py @ 4381:3c97717fd662
plugin XEP-0428: Add missing "for" attribute:
The "for" attribute was missing from <fallback> element.
rel 461
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 04 Jul 2025 12:30:20 +0200 |
parents | 0d7bb4df2343 |
children |
line wrap: on
line diff
--- a/libervia/backend/plugins/plugin_xep_0428.py Fri Jul 04 12:28:40 2025 +0200 +++ b/libervia/backend/plugins/plugin_xep_0428.py Fri Jul 04 12:30:20 2025 +0200 @@ -43,25 +43,35 @@ 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: <message> 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 <body> """ - 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"""