Add options to disable HTML in notifications

This commit is contained in:
miruka
2021-02-28 12:40:24 -04:00
parent fe92ce6730
commit 1b0bec3470
5 changed files with 38 additions and 13 deletions

View File

@@ -14,7 +14,7 @@ import lxml # nosec
import nio
from ..presence import Presence
from ..utils import AutoStrEnum, auto
from ..utils import AutoStrEnum, auto, strip_html_tags
from .model_item import ModelItem
OptionalExceptionType = Union[Type[None], Type[Exception]]
@@ -389,11 +389,11 @@ class Event(ModelItem):
sender_avatar: str = field()
fetch_profile: bool = False
content: str = ""
inline_content: str = ""
reason: str = ""
links: List[str] = field(default_factory=list)
mentions: List[Tuple[str, str]] = field(default_factory=list)
content: str = ""
inline_content: str = ""
reason: str = ""
links: List[str] = field(default_factory=list)
mentions: List[Tuple[str, str]] = field(default_factory=list)
type_specifier: TypeSpecifier = TypeSpecifier.Unset
@@ -432,6 +432,15 @@ class Event(ModelItem):
return (self.date, self.id) > (other.date, other.id)
@property
def plain_content(self) -> str:
"""Plaintext version of the event's content."""
if isinstance(self.source, nio.RoomMessageText):
return self.source.body
return strip_html_tags(self.content)
@staticmethod
def parse_links(text: str) -> List[str]:
"""Return list of URLs (`<a href=...>` tags) present in the text."""