From 6bd62f8283c14d456791e2b26fcc5744abaf5e72 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Fri, 3 Sep 2021 01:55:47 +0200 Subject: [PATCH] Make desktop alerting independent from notification support in the homeserver. --- src/ChatPage.cpp | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp index 038c3e3c..80d06ae2 100644 --- a/src/ChatPage.cpp +++ b/src/ChatPage.cpp @@ -189,13 +189,26 @@ ChatPage::ChatPage(QSharedPointer userSettings, QWidget *parent) connect(this, &ChatPage::syncUI, this, [this](const mtx::responses::Rooms &rooms) { view_manager_->sync(rooms); - bool hasNotifications = false; + static unsigned int prevNotificationCount = 0; + unsigned int notificationCount = 0; for (const auto &room : rooms.join) { - if (room.second.unread_notifications.notification_count > 0) - hasNotifications = true; + notificationCount += room.second.unread_notifications.notification_count; } - if (hasNotifications && userSettings_->hasNotifications()) + // HACK: If we had less notifications last time we checked, send an alert if the + // user wanted one. Technically, this may cause an alert to be missed if new ones + // come in while you are reading old ones. Since the window is almost certainly open + // in this edge case, that's probably a non-issue. + // TODO: Replace this once we have proper pushrules support. This is a horrible hack + if (prevNotificationCount < notificationCount) { + if (userSettings_->hasAlertOnNotification()) + QApplication::alert(this); + } + prevNotificationCount = notificationCount; + + // No need to check amounts for this section, as this function internally checks for + // duplicates. + if (notificationCount && userSettings_->hasNotifications()) http::client()->notifications( 5, "", @@ -462,10 +475,6 @@ ChatPage::sendNotifications(const mtx::responses::Notifications &res) if (isRoomActive(room_id)) continue; - if (userSettings_->hasAlertOnNotification()) { - QApplication::alert(this); - } - if (userSettings_->hasDesktopNotifications()) { auto info = cache::singleRoomInfo(item.room_id);