From a90a451865b01f868097b05c456b780f25ca4014 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Mon, 20 Jan 2025 11:46:32 +0100 Subject: [PATCH] Set LXMF renderer field if message has BB-code markup --- sbapp/sideband/core.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/sbapp/sideband/core.py b/sbapp/sideband/core.py index 53fd60d..b68186b 100644 --- a/sbapp/sideband/core.py +++ b/sbapp/sideband/core.py @@ -4396,6 +4396,8 @@ class SidebandCore(): fields[LXMF.FIELD_IMAGE] = image if audio != None: fields[LXMF.FIELD_AUDIO] = audio + if self.has_bb_markup(content): + fields[LXMF.FIELD_RENDERER] = LXMF.RENDERER_BBCODE lxm = LXMF.LXMessage(dest, source, content, title="", desired_method=desired_method, fields = fields, include_ticket=self.is_trusted(destination_hash)) @@ -4534,11 +4536,19 @@ class SidebandCore(): self.setstate("lxm_uri_ingest.result", response) - def strip_markup(self, text): + def strip_bb_markup(self, text): if not hasattr(self, "smr") or self.smr == None: self.smr = re.compile(r'\[\/?(?:b|i|u|url|quote|code|img|color|size)*?.*?\]',re.IGNORECASE | re.MULTILINE ) return self.smr.sub("", text) + def has_bb_markup(self, text): + if not hasattr(self, "smr") or self.smr == None: + self.smr = re.compile(r'\[\/?(?:b|i|u|url|quote|code|img|color|size)*?.*?\]',re.IGNORECASE | re.MULTILINE ) + if self.smr.match(text): + return True + else: + return False + def lxm_ingest(self, message, originator = False): should_notify = False is_trusted = False @@ -4621,7 +4631,7 @@ class SidebandCore(): if should_notify: nlen = 128 text = message.content.decode("utf-8") - notification_content = self.strip_markup(text[:nlen]) + notification_content = self.strip_bb_markup(text[:nlen]) if len(text) > nlen: notification_content += " [...]"