XEP-0461: add get fallback body helper

This commit is contained in:
nicoco 2022-11-22 10:23:52 +01:00
parent 7300f1285e
commit 9b89401b36
2 changed files with 20 additions and 0 deletions

View file

@ -18,6 +18,16 @@ class FeatureFallBack(ElementBase):
plugin_attrib = "feature_fallback"
interfaces = {"for"}
def get_fallback_body(self):
# only works for a single fallback_body attrib
start = self["fallback_body"]["start"]
end = self["fallback_body"]["end"]
body = self.parent()["body"]
if start < end < len(body):
return body[start:end]
else:
return ""
def get_stripped_body(self):
# only works for a single fallback_body attrib
start = self["fallback_body"]["start"]

View file

@ -61,5 +61,15 @@ class TestReply(SlixTest):
"""
)
def testGetFallBackBody(self):
body = "Anna wrote:\nHi, how are you?"
quoted = "> Anna wrote:\n> Hi, how are you?\n"
msg = Message()
msg["body"] = "Great"
msg["feature_fallback"].add_quoted_fallback(body)
body2 = msg["feature_fallback"].get_fallback_body()
self.assertTrue(body2 == quoted, body2)
suite = unittest.TestLoader().loadTestsFromTestCase(TestReply)