Merge pull request #707 from Thulinma/alerts_working_without_homeserver_support

Make desktop alerting independent from notification support in the homeserver
This commit is contained in:
DeepBlueV7.X 2021-09-03 09:17:05 +00:00 committed by GitHub
commit 43703c95d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 8 deletions

View File

@ -189,13 +189,26 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> 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);