From 54234399f58c27c6ee9cfdb3e53ef2a31e1eedda Mon Sep 17 00:00:00 2001 From: miruka Date: Sat, 19 Sep 2020 15:42:25 -0400 Subject: [PATCH] Fix "Mentions & keywords" notification level Make it work in cases where multiple accounts are present in the room and one of them is highlighted. --- src/backend/backend.py | 3 +-- src/backend/matrix_client.py | 7 ++----- src/backend/pyotherside_events.py | 1 + src/gui/PythonBridge/EventHandlers.qml | 9 +++++++-- src/gui/Window.qml | 1 + 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/backend/backend.py b/src/backend/backend.py index 1c92116b..5ec72057 100644 --- a/src/backend/backend.py +++ b/src/backend/backend.py @@ -8,7 +8,7 @@ import sys import time from datetime import datetime from pathlib import Path -from typing import Any, DefaultDict, Dict, List, Optional, Set, Tuple, Union +from typing import Any, DefaultDict, Dict, List, Optional, Tuple, Union from urllib.parse import urlparse import aiohttp @@ -133,7 +133,6 @@ class Backend: self.mxc_events: DefaultDict[str, List[Event]] = DefaultDict(list) - self.notified_events: Set[str] = set() # {event_id} self.notification_avatar_cache: Dict[str, Path] = {} # {mxc: path} diff --git a/src/backend/matrix_client.py b/src/backend/matrix_client.py index 4b6c07f6..2d51fa06 100644 --- a/src/backend/matrix_client.py +++ b/src/backend/matrix_client.py @@ -2181,16 +2181,12 @@ class MatrixClient(nio.AsyncClient): if from_us: return item - already_notified = item.event_id in self.backend.notified_events - - if already_notified or await self.event_is_past(ev): + if await self.event_is_past(ev): await self.update_account_unread_counts() return item # Alerts & notifications - self.backend.notified_events.add(item.event_id) - room_item = self.models[self.user_id, "rooms"][room.room_id] unread = \ @@ -2230,6 +2226,7 @@ class MatrixClient(nio.AsyncClient): body = f"{sender}: {item.inline_content}" NotificationRequested( + id = item.id, high_importance = highlight, title = room_name, diff --git a/src/backend/pyotherside_events.py b/src/backend/pyotherside_events.py index 6ddecf2a..866f0833 100644 --- a/src/backend/pyotherside_events.py +++ b/src/backend/pyotherside_events.py @@ -42,6 +42,7 @@ class NotificationRequested(PyOtherSideEvent): flash the program's taskbar icon on Windows. """ + id: str = field() title: str = field() body: str = "" image: Union[Path, str] = "" diff --git a/src/gui/PythonBridge/EventHandlers.qml b/src/gui/PythonBridge/EventHandlers.qml index f3378670..d5cc5807 100644 --- a/src/gui/PythonBridge/EventHandlers.qml +++ b/src/gui/PythonBridge/EventHandlers.qml @@ -11,12 +11,17 @@ QtObject { Qt.exit(exitCode) } - function onNotificationRequested(title, body, image, highImportance) { + function onNotificationRequested(id, title, body, image, highImportance) { const level = window.notificationLevel - if (Qt.application.state === Qt.ApplicationActive) return if (level === Window.NotificationLevel.None) return if (level === Window.MentionsKeywords && ! highImportance) return + if (window.notifiedIds.has(id)) return + + window.notifiedIds.add(id) + window.notifiedIdsChanged() + + if (Qt.application.state === Qt.ApplicationActive) return py.callCoro("desktop_notify", [title, body, image]) diff --git a/src/gui/Window.qml b/src/gui/Window.qml index a82b5fd8..a6237ae2 100644 --- a/src/gui/Window.qml +++ b/src/gui/Window.qml @@ -20,6 +20,7 @@ ApplicationWindow { window.visibility === window.Hidden property int notificationLevel: Window.NotificationLevel.All + property var notifiedIds: new Set() property var mainUI: null property var settings: ({})