diff --git a/slixmpp/plugins/xep_0461/stanza.py b/slixmpp/plugins/xep_0461/stanza.py index 1035fd83..37021c00 100644 --- a/slixmpp/plugins/xep_0461/stanza.py +++ b/slixmpp/plugins/xep_0461/stanza.py @@ -28,6 +28,14 @@ class FeatureFallBack(ElementBase): else: return body + def add_quoted_fallback(self, fallback: str): + msg = self.parent() + quoted = "\n".join("> " + x.strip() for x in fallback.split("\n")) + "\n" + msg["body"] = quoted + msg["body"] + msg["feature_fallback"]["for"] = NS + msg["feature_fallback"]["fallback_body"]["start"] = 0 + msg["feature_fallback"]["fallback_body"]["end"] = len(quoted) + class FallBackBody(ElementBase): # According to https://xmpp.org/extensions/inbox/compatibility-fallback.html diff --git a/tests/test_stanza_xep_0461.py b/tests/test_stanza_xep_0461.py index 90aa751b..3eb6a3ac 100644 --- a/tests/test_stanza_xep_0461.py +++ b/tests/test_stanza_xep_0461.py @@ -44,5 +44,22 @@ class TestReply(SlixTest): assert message["feature_fallback"].get_stripped_body() == "realbody" + def testAddFallBackHelper(self): + msg = Message() + msg["body"] = "Great" + msg["feature_fallback"].add_quoted_fallback("Anna wrote:\nHi, how are you?") + # ugly dedent but the test does not pass without it + self.check( + msg, + """ + + > Anna wrote:\n> Hi, how are you?\nGreat + + + + + """ + ) + suite = unittest.TestLoader().loadTestsFromTestCase(TestReply)