From 25c28ff5d187698cd5f7a2838e78f8fa35f8da36 Mon Sep 17 00:00:00 2001 From: nicoco Date: Sun, 4 Jun 2023 14:17:19 +0200 Subject: [PATCH] xep_0461/add_quoted_fallback: add optional nickname argument + a little docstring that doesn't hurt --- slixmpp/plugins/xep_0461/stanza.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/slixmpp/plugins/xep_0461/stanza.py b/slixmpp/plugins/xep_0461/stanza.py index e6297f75..8e4981f7 100644 --- a/slixmpp/plugins/xep_0461/stanza.py +++ b/slixmpp/plugins/xep_0461/stanza.py @@ -1,3 +1,5 @@ +from typing import Optional + from slixmpp.stanza import Message from slixmpp.xmlstream import ElementBase, register_stanza_plugin @@ -38,9 +40,22 @@ class FeatureFallBack(ElementBase): else: return body - def add_quoted_fallback(self, fallback: str): + def add_quoted_fallback(self, fallback: str, nickname: Optional[str] = None): + """ + Add plain text fallback for clients not implementing XEP-0461. + + ``msg["feature_fallback"].add_quoted_fallback("Some text", "Bob")`` will + prepend "> Bob:\n> Some text\n" to the body of the message, and set the + fallback_body attributes accordingly, so that clients implementing + XEP-0461 can hide the fallback text. + + :param fallback: Body of the quoted message. + :param nickname: Optional, nickname of the quoted participant. + """ msg = self.parent() quoted = "\n".join("> " + x.strip() for x in fallback.split("\n")) + "\n" + if nickname: + quoted = "> " + nickname + ":\n" + quoted msg["body"] = quoted + msg["body"] msg["feature_fallback"]["for"] = NS msg["feature_fallback"]["fallback_body"]["start"] = 0