Add options to disable HTML in notifications
This commit is contained in:
parent
fe92ce6730
commit
1b0bec3470
|
@ -17,7 +17,6 @@
|
|||
- Change docs linking to dev branch back to master
|
||||
|
||||
- Implement fallback QML notifications, usable if dbus isn't available
|
||||
- Option to use plaintext notifications
|
||||
|
||||
- add http_proxy support
|
||||
- image viewer: can't expand image in reduced window layout
|
||||
|
|
|
@ -2437,20 +2437,25 @@ class MatrixClient(nio.AsyncClient):
|
|||
sender_name=sender_name, sender_avatar=sender_avatar,
|
||||
)
|
||||
|
||||
sender = item.sender_name or item.sender_id
|
||||
sender = item.sender_name or item.sender_id
|
||||
is_linux = platform.system() == "Linux"
|
||||
use_html = is_linux and self.backend.settings.Notifications.use_html
|
||||
content = item.inline_content if use_html else item.plain_content
|
||||
|
||||
if isinstance(ev, nio.RoomMessageEmote):
|
||||
body = f"<i>{sender} {item.inline_content}</i>"
|
||||
if isinstance(ev, nio.RoomMessageEmote) and use_html:
|
||||
body = f"<i>{sender} {content}</i>"
|
||||
elif isinstance(ev, nio.RoomMessageEmote):
|
||||
body = f"{sender} {content}"
|
||||
elif not isinstance(ev, nio.RoomMessage):
|
||||
body = item.inline_content.replace(
|
||||
body = content.replace(
|
||||
"%1", item.sender_name or item.sender_id,
|
||||
).replace(
|
||||
"%2", item.target_name or item.target_id,
|
||||
)
|
||||
elif room.member_count == 2 and room.display_name == sender:
|
||||
body = item.inline_content
|
||||
body = content
|
||||
else:
|
||||
body = f"{sender}: {item.inline_content}"
|
||||
body = f"{sender}: {content}"
|
||||
|
||||
NotificationRequested(
|
||||
id = item.id,
|
||||
|
|
|
@ -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."""
|
||||
|
|
|
@ -197,6 +197,11 @@ def plain2html(text: str) -> str:
|
|||
.replace("\t", " " * 4)
|
||||
|
||||
|
||||
def strip_html_tags(text: str) -> str:
|
||||
"""Remove HTML tags from text."""
|
||||
return re.sub(r"<\/?[^>]+(>|$)", "", text)
|
||||
|
||||
|
||||
def serialize_value_for_qml(
|
||||
value: Any, json_list_dicts: bool = False, reject_unknown: bool = False,
|
||||
) -> Any:
|
||||
|
|
|
@ -49,6 +49,13 @@ class Notifications:
|
|||
# - "mute" (don't notify for anything)
|
||||
start_level: str = "enable"
|
||||
|
||||
# Use HTML formatting in notification bubbles.
|
||||
# This option has no effect on Windows and OSX.
|
||||
# Rendering is only supported by notification servers which follow the
|
||||
# GNOME Desktop Notification Specification, set this to `False` if you
|
||||
# keep seeing raw <tags> in notifications.
|
||||
use_html: bool = True
|
||||
|
||||
# How long in seconds the window will flash in your dock or taskbar when
|
||||
# a new message, which matches a notification push rule with a
|
||||
# flash (lightbulb) action, is posted in a room.
|
||||
|
|
Loading…
Reference in New Issue
Block a user