diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp index c7f5164a..0ca20c52 100644 --- a/src/ChatPage.cpp +++ b/src/ChatPage.cpp @@ -450,7 +450,7 @@ ChatPage::ChatPage(QSharedPointer userSettings, QWidget *parent) this, &ChatPage::updateGroupsInfo, communitiesList_, &CommunitiesList::setCommunities); connect(this, &ChatPage::leftRoom, this, &ChatPage::removeRoom); - connect(this, &ChatPage::notificationsRetrieved, this, &ChatPage::sendDesktopNotifications); + connect(this, &ChatPage::notificationsRetrieved, this, &ChatPage::sendNotifications); connect(this, &ChatPage::highlightedNotifsRetrieved, this, @@ -525,7 +525,7 @@ ChatPage::ChatPage(QSharedPointer userSettings, QWidget *parent) hasNotifications = true; } - if (hasNotifications && userSettings_->hasDesktopNotifications()) + if (hasNotifications && userSettings_->hasNotifications()) http::client()->notifications( 5, "", @@ -883,7 +883,7 @@ ChatPage::updateRoomNotificationCount(const QString &room_id, } void -ChatPage::sendDesktopNotifications(const mtx::responses::Notifications &res) +ChatPage::sendNotifications(const mtx::responses::Notifications &res) { for (const auto &item : res.notifications) { const auto event_id = mtx::accessors::event_id(item.event); @@ -906,16 +906,23 @@ ChatPage::sendDesktopNotifications(const mtx::responses::Notifications &res) if (isRoomActive(room_id)) continue; - notificationsManager.postNotification( - room_id, - QString::fromStdString(event_id), - QString::fromStdString(cache::singleRoomInfo(item.room_id).name), - cache::displayName(room_id, user_id), - utils::event_body(item.event), - cache::getRoomAvatar(room_id)); + if (userSettings_->hasAlertOnNotification()) { + QApplication::alert(this); + } + + if (userSettings_->hasDesktopNotifications()) { + notificationsManager.postNotification( + room_id, + QString::fromStdString(event_id), + QString::fromStdString( + cache::singleRoomInfo(item.room_id).name), + cache::displayName(room_id, user_id), + utils::event_body(item.event), + cache::getRoomAvatar(room_id)); + } } } catch (const lmdb::error &e) { - nhlog::db()->warn("error while sending desktop notification: {}", e.what()); + nhlog::db()->warn("error while sending notification: {}", e.what()); } } } diff --git a/src/ChatPage.h b/src/ChatPage.h index 83b4e76d..8c33a63e 100644 --- a/src/ChatPage.h +++ b/src/ChatPage.h @@ -206,7 +206,7 @@ private: uint16_t notification_count, uint16_t highlight_count); //! Send desktop notification for the received messages. - void sendDesktopNotifications(const mtx::responses::Notifications &); + void sendNotifications(const mtx::responses::Notifications &); void showNotificationsDialog(const QPoint &point); diff --git a/src/UserSettingsPage.cpp b/src/UserSettingsPage.cpp index dfd99069..4e9e0cb0 100644 --- a/src/UserSettingsPage.cpp +++ b/src/UserSettingsPage.cpp @@ -54,6 +54,7 @@ UserSettings::load() QSettings settings; tray_ = settings.value("user/window/tray", false).toBool(); hasDesktopNotifications_ = settings.value("user/desktop_notifications", true).toBool(); + hasAlertOnNotification_ = settings.value("user/alert_on_notification", false).toBool(); startInTray_ = settings.value("user/window/start_in_tray", false).toBool(); groupView_ = settings.value("user/group_view", true).toBool(); buttonsInTimeline_ = settings.value("user/timeline/buttons", true).toBool(); @@ -193,6 +194,16 @@ UserSettings::setDesktopNotifications(bool state) save(); } +void +UserSettings::setAlertOnNotification(bool state) +{ + if (state == hasAlertOnNotification_) + return; + hasAlertOnNotification_ = state; + emit alertOnNotificationChanged(state); + save(); +} + void UserSettings::setAvatarCircles(bool state) { @@ -334,6 +345,7 @@ UserSettings::save() settings.setValue("group_view", groupView_); settings.setValue("markdown_enabled", markdown_); settings.setValue("desktop_notifications", hasDesktopNotifications_); + settings.setValue("alert_on_notification", hasAlertOnNotification_); settings.setValue("theme", theme()); settings.setValue("font_family", font_); settings.setValue("emoji_font_family", emojiFont_); @@ -401,6 +413,7 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge readReceipts_ = new Toggle{this}; markdown_ = new Toggle{this}; desktopNotifications_ = new Toggle{this}; + alertOnNotification_ = new Toggle{this}; scaleFactorCombo_ = new QComboBox{this}; fontSizeCombo_ = new QComboBox{this}; fontSelectionCombo_ = new QComboBox{this}; @@ -554,6 +567,10 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge boxWrap(tr("Desktop notifications"), desktopNotifications_, tr("Notify about received message when the client is not currently focused.")); + boxWrap(tr("Alert on notification"), + alertOnNotification_, + tr("Show an alert when a message is received.\nThis usually causes the application " + "icon in the task bar to animate in some fashion.")); boxWrap(tr("Highlight message on hover"), messageHoverHighlight_, tr("Change the background color of messages when you hover over them.")); @@ -680,6 +697,10 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge settings_->setDesktopNotifications(!disabled); }); + connect(alertOnNotification_, &Toggle::toggled, this, [this](bool disabled) { + settings_->setAlertOnNotification(!disabled); + }); + connect(messageHoverHighlight_, &Toggle::toggled, this, [this](bool disabled) { settings_->setMessageHoverHighlight(!disabled); }); @@ -725,6 +746,7 @@ UserSettingsPage::showEvent(QShowEvent *) readReceipts_->setState(!settings_->readReceipts()); markdown_->setState(!settings_->markdown()); desktopNotifications_->setState(!settings_->hasDesktopNotifications()); + alertOnNotification_->setState(!settings_->hasAlertOnNotification()); messageHoverHighlight_->setState(!settings_->messageHoverHighlight()); enlargeEmojiOnlyMessages_->setState(!settings_->enlargeEmojiOnlyMessages()); deviceIdValue_->setText(QString::fromStdString(http::client()->device_id())); diff --git a/src/UserSettingsPage.h b/src/UserSettingsPage.h index fb807067..c90dc759 100644 --- a/src/UserSettingsPage.h +++ b/src/UserSettingsPage.h @@ -58,6 +58,8 @@ class UserSettings : public QObject bool readReceipts READ readReceipts WRITE setReadReceipts NOTIFY readReceiptsChanged) Q_PROPERTY(bool desktopNotifications READ hasDesktopNotifications WRITE setDesktopNotifications NOTIFY desktopNotificationsChanged) + Q_PROPERTY(bool alertOnNotification READ hasAlertOnNotification WRITE setAlertOnNotification + NOTIFY alertOnNotificationChanged) Q_PROPERTY( bool avatarCircles READ avatarCircles WRITE setAvatarCircles NOTIFY avatarCirclesChanged) Q_PROPERTY(bool decryptSidebar READ decryptSidebar WRITE setDecryptSidebar NOTIFY @@ -91,6 +93,7 @@ public: void setButtonsInTimeline(bool state); void setTimelineMaxWidth(int state); void setDesktopNotifications(bool state); + void setAlertOnNotification(bool state); void setAvatarCircles(bool state); void setDecryptSidebar(bool state); @@ -108,6 +111,11 @@ public: bool buttonsInTimeline() const { return buttonsInTimeline_; } bool readReceipts() const { return readReceipts_; } bool hasDesktopNotifications() const { return hasDesktopNotifications_; } + bool hasAlertOnNotification() const { return hasAlertOnNotification_; } + bool hasNotifications() const + { + return hasDesktopNotifications() || hasAlertOnNotification(); + } int timelineMaxWidth() const { return timelineMaxWidth_; } double fontSize() const { return baseFontSize_; } QString font() const { return font_; } @@ -126,6 +134,7 @@ signals: void buttonInTimelineChanged(bool state); void readReceiptsChanged(bool state); void desktopNotificationsChanged(bool state); + void alertOnNotificationChanged(bool state); void avatarCirclesChanged(bool state); void decryptSidebarChanged(bool state); void timelineMaxWidthChanged(int state); @@ -151,6 +160,7 @@ private: bool buttonsInTimeline_; bool readReceipts_; bool hasDesktopNotifications_; + bool hasAlertOnNotification_; bool avatarCircles_; bool decryptSidebar_; int timelineMaxWidth_; @@ -208,6 +218,7 @@ private: Toggle *readReceipts_; Toggle *markdown_; Toggle *desktopNotifications_; + Toggle *alertOnNotification_; Toggle *avatarCircles_; Toggle *decryptSidebar_; QLabel *deviceFingerprintValue_;