Strip markup from notifications

This commit is contained in:
Mark Qvist 2025-01-18 23:48:35 +01:00
parent dd1399d7ce
commit 56add0bc50

View File

@ -7,6 +7,7 @@ import struct
import sqlite3
import random
import shlex
import re
import RNS.vendor.umsgpack as msgpack
import RNS.Interfaces.Interface as Interface
@ -127,6 +128,7 @@ class SidebandCore():
# Add the announce to the directory announce
# stream logger
if self.reticulum != None:
link_stats = {"rssi": self.reticulum.get_packet_rssi(announce_packet_hash),
"snr": self.reticulum.get_packet_snr(announce_packet_hash),
"q": self.reticulum.get_packet_q(announce_packet_hash)}
@ -4532,6 +4534,11 @@ class SidebandCore():
self.setstate("lxm_uri_ingest.result", response)
def strip_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 lxm_ingest(self, message, originator = False):
should_notify = False
is_trusted = False
@ -4614,7 +4621,7 @@ class SidebandCore():
if should_notify:
nlen = 128
text = message.content.decode("utf-8")
notification_content = text[:nlen]
notification_content = self.strip_markup(text[:nlen])
if len(text) > nlen:
notification_content += " [...]"