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
|
- Change docs linking to dev branch back to master
|
||||||
|
|
||||||
- Implement fallback QML notifications, usable if dbus isn't available
|
- Implement fallback QML notifications, usable if dbus isn't available
|
||||||
- Option to use plaintext notifications
|
|
||||||
|
|
||||||
- add http_proxy support
|
- add http_proxy support
|
||||||
- image viewer: can't expand image in reduced window layout
|
- image viewer: can't expand image in reduced window layout
|
||||||
|
|
|
@ -2438,19 +2438,24 @@ class MatrixClient(nio.AsyncClient):
|
||||||
)
|
)
|
||||||
|
|
||||||
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):
|
if isinstance(ev, nio.RoomMessageEmote) and use_html:
|
||||||
body = f"<i>{sender} {item.inline_content}</i>"
|
body = f"<i>{sender} {content}</i>"
|
||||||
|
elif isinstance(ev, nio.RoomMessageEmote):
|
||||||
|
body = f"{sender} {content}"
|
||||||
elif not isinstance(ev, nio.RoomMessage):
|
elif not isinstance(ev, nio.RoomMessage):
|
||||||
body = item.inline_content.replace(
|
body = content.replace(
|
||||||
"%1", item.sender_name or item.sender_id,
|
"%1", item.sender_name or item.sender_id,
|
||||||
).replace(
|
).replace(
|
||||||
"%2", item.target_name or item.target_id,
|
"%2", item.target_name or item.target_id,
|
||||||
)
|
)
|
||||||
elif room.member_count == 2 and room.display_name == sender:
|
elif room.member_count == 2 and room.display_name == sender:
|
||||||
body = item.inline_content
|
body = content
|
||||||
else:
|
else:
|
||||||
body = f"{sender}: {item.inline_content}"
|
body = f"{sender}: {content}"
|
||||||
|
|
||||||
NotificationRequested(
|
NotificationRequested(
|
||||||
id = item.id,
|
id = item.id,
|
||||||
|
|
|
@ -14,7 +14,7 @@ import lxml # nosec
|
||||||
import nio
|
import nio
|
||||||
|
|
||||||
from ..presence import Presence
|
from ..presence import Presence
|
||||||
from ..utils import AutoStrEnum, auto
|
from ..utils import AutoStrEnum, auto, strip_html_tags
|
||||||
from .model_item import ModelItem
|
from .model_item import ModelItem
|
||||||
|
|
||||||
OptionalExceptionType = Union[Type[None], Type[Exception]]
|
OptionalExceptionType = Union[Type[None], Type[Exception]]
|
||||||
|
@ -432,6 +432,15 @@ class Event(ModelItem):
|
||||||
|
|
||||||
return (self.date, self.id) > (other.date, other.id)
|
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
|
@staticmethod
|
||||||
def parse_links(text: str) -> List[str]:
|
def parse_links(text: str) -> List[str]:
|
||||||
"""Return list of URLs (`<a href=...>` tags) present in the text."""
|
"""Return list of URLs (`<a href=...>` tags) present in the text."""
|
||||||
|
|
|
@ -197,6 +197,11 @@ def plain2html(text: str) -> str:
|
||||||
.replace("\t", " " * 4)
|
.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(
|
def serialize_value_for_qml(
|
||||||
value: Any, json_list_dicts: bool = False, reject_unknown: bool = False,
|
value: Any, json_list_dicts: bool = False, reject_unknown: bool = False,
|
||||||
) -> Any:
|
) -> Any:
|
||||||
|
|
|
@ -49,6 +49,13 @@ class Notifications:
|
||||||
# - "mute" (don't notify for anything)
|
# - "mute" (don't notify for anything)
|
||||||
start_level: str = "enable"
|
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
|
# 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
|
# a new message, which matches a notification push rule with a
|
||||||
# flash (lightbulb) action, is posted in a room.
|
# flash (lightbulb) action, is posted in a room.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user