Mercurial > libervia-backend
comparison 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 |
comparison
equal
deleted
inserted
replaced
4380:2e3ce128973c | 4381:3c97717fd662 |
---|---|
41 } | 41 } |
42 | 42 |
43 NS_FALLBACK = "urn:xmpp:fallback:0" | 43 NS_FALLBACK = "urn:xmpp:fallback:0" |
44 | 44 |
45 | 45 |
46 class XEP_0428(object): | 46 class XEP_0428: |
47 | 47 |
48 def __init__(self, host): | 48 def __init__(self, host): |
49 log.info(_("XEP-0428 (Fallback Indication) plugin initialization")) | 49 log.info(_("XEP-0428 (Fallback Indication) plugin initialization")) |
50 host.register_namespace("fallback", NS_FALLBACK) | 50 host.register_namespace("fallback", NS_FALLBACK) |
51 | 51 |
52 def add_fallback_elt( | 52 def add_fallback_elt( |
53 self, message_elt: domish.Element, msg: Optional[str] = None | 53 self, |
54 message_elt: domish.Element, | |
55 for_: str, | |
56 msg: str|None = None | |
54 ) -> None: | 57 ) -> None: |
55 """Add the fallback indication element | 58 """Add the fallback indication element |
56 | 59 |
57 @param message_elt: <message> element where the indication must be | 60 @param message_elt: <message> element where the indication must be |
58 set | 61 set |
62 @param for_: Specification namespace that the fallback is meant to replace. | |
63 see https://xmpp.org/extensions/xep-0428.html#sect-idm46381699903600 | |
59 @param msg: message to show as fallback | 64 @param msg: message to show as fallback |
60 Will be added as <body> | 65 Will be added as <body> |
61 """ | 66 """ |
62 message_elt.addElement((NS_FALLBACK, "fallback")) | 67 fallback_elt = message_elt.addElement((NS_FALLBACK, "fallback")) |
68 fallback_elt["for"] = for_ | |
63 if msg is not None: | 69 if msg is not None: |
64 message_elt.addElement("body", content=msg) | 70 body_elt = message_elt.body |
71 if body_elt is None: | |
72 message_elt.addElement("body", content=msg) | |
73 else: | |
74 body_elt.addContent(msg) | |
65 | 75 |
66 def has_fallback(self, message_elt: domish.Element) -> bool: | 76 def has_fallback(self, message_elt: domish.Element) -> bool: |
67 """Tell if a message has a fallback indication""" | 77 """Tell if a message has a fallback indication""" |
68 try: | 78 try: |
69 next(message_elt.elements(NS_FALLBACK, "fallback")) | 79 next(message_elt.elements(NS_FALLBACK, "fallback")) |