Merge remote-tracking branch 'origin/master' into reactions

This commit is contained in:
Joseph Donofry 2020-06-11 21:59:34 -04:00
commit b90b718961
No known key found for this signature in database
GPG Key ID: E8A1D78EF044B0CB
4 changed files with 52 additions and 12 deletions

View File

@ -450,7 +450,7 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
this, &ChatPage::updateGroupsInfo, communitiesList_, &CommunitiesList::setCommunities); this, &ChatPage::updateGroupsInfo, communitiesList_, &CommunitiesList::setCommunities);
connect(this, &ChatPage::leftRoom, this, &ChatPage::removeRoom); connect(this, &ChatPage::leftRoom, this, &ChatPage::removeRoom);
connect(this, &ChatPage::notificationsRetrieved, this, &ChatPage::sendDesktopNotifications); connect(this, &ChatPage::notificationsRetrieved, this, &ChatPage::sendNotifications);
connect(this, connect(this,
&ChatPage::highlightedNotifsRetrieved, &ChatPage::highlightedNotifsRetrieved,
this, this,
@ -525,7 +525,7 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
hasNotifications = true; hasNotifications = true;
} }
if (hasNotifications && userSettings_->hasDesktopNotifications()) if (hasNotifications && userSettings_->hasNotifications())
http::client()->notifications( http::client()->notifications(
5, 5,
"", "",
@ -883,7 +883,7 @@ ChatPage::updateRoomNotificationCount(const QString &room_id,
} }
void void
ChatPage::sendDesktopNotifications(const mtx::responses::Notifications &res) ChatPage::sendNotifications(const mtx::responses::Notifications &res)
{ {
for (const auto &item : res.notifications) { for (const auto &item : res.notifications) {
const auto event_id = mtx::accessors::event_id(item.event); 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)) if (isRoomActive(room_id))
continue; continue;
notificationsManager.postNotification( if (userSettings_->hasAlertOnNotification()) {
room_id, QApplication::alert(this);
QString::fromStdString(event_id), }
QString::fromStdString(cache::singleRoomInfo(item.room_id).name),
cache::displayName(room_id, user_id), if (userSettings_->hasDesktopNotifications()) {
utils::event_body(item.event), notificationsManager.postNotification(
cache::getRoomAvatar(room_id)); 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) { } catch (const lmdb::error &e) {
nhlog::db()->warn("error while sending desktop notification: {}", e.what()); nhlog::db()->warn("error while sending notification: {}", e.what());
} }
} }
} }

View File

@ -206,7 +206,7 @@ private:
uint16_t notification_count, uint16_t notification_count,
uint16_t highlight_count); uint16_t highlight_count);
//! Send desktop notification for the received messages. //! Send desktop notification for the received messages.
void sendDesktopNotifications(const mtx::responses::Notifications &); void sendNotifications(const mtx::responses::Notifications &);
void showNotificationsDialog(const QPoint &point); void showNotificationsDialog(const QPoint &point);

View File

@ -54,6 +54,7 @@ UserSettings::load()
QSettings settings; QSettings settings;
tray_ = settings.value("user/window/tray", false).toBool(); tray_ = settings.value("user/window/tray", false).toBool();
hasDesktopNotifications_ = settings.value("user/desktop_notifications", true).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(); startInTray_ = settings.value("user/window/start_in_tray", false).toBool();
groupView_ = settings.value("user/group_view", true).toBool(); groupView_ = settings.value("user/group_view", true).toBool();
buttonsInTimeline_ = settings.value("user/timeline/buttons", true).toBool(); buttonsInTimeline_ = settings.value("user/timeline/buttons", true).toBool();
@ -193,6 +194,16 @@ UserSettings::setDesktopNotifications(bool state)
save(); save();
} }
void
UserSettings::setAlertOnNotification(bool state)
{
if (state == hasAlertOnNotification_)
return;
hasAlertOnNotification_ = state;
emit alertOnNotificationChanged(state);
save();
}
void void
UserSettings::setAvatarCircles(bool state) UserSettings::setAvatarCircles(bool state)
{ {
@ -334,6 +345,7 @@ UserSettings::save()
settings.setValue("group_view", groupView_); settings.setValue("group_view", groupView_);
settings.setValue("markdown_enabled", markdown_); settings.setValue("markdown_enabled", markdown_);
settings.setValue("desktop_notifications", hasDesktopNotifications_); settings.setValue("desktop_notifications", hasDesktopNotifications_);
settings.setValue("alert_on_notification", hasAlertOnNotification_);
settings.setValue("theme", theme()); settings.setValue("theme", theme());
settings.setValue("font_family", font_); settings.setValue("font_family", font_);
settings.setValue("emoji_font_family", emojiFont_); settings.setValue("emoji_font_family", emojiFont_);
@ -401,6 +413,7 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
readReceipts_ = new Toggle{this}; readReceipts_ = new Toggle{this};
markdown_ = new Toggle{this}; markdown_ = new Toggle{this};
desktopNotifications_ = new Toggle{this}; desktopNotifications_ = new Toggle{this};
alertOnNotification_ = new Toggle{this};
scaleFactorCombo_ = new QComboBox{this}; scaleFactorCombo_ = new QComboBox{this};
fontSizeCombo_ = new QComboBox{this}; fontSizeCombo_ = new QComboBox{this};
fontSelectionCombo_ = new QComboBox{this}; fontSelectionCombo_ = new QComboBox{this};
@ -554,6 +567,10 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
boxWrap(tr("Desktop notifications"), boxWrap(tr("Desktop notifications"),
desktopNotifications_, desktopNotifications_,
tr("Notify about received message when the client is not currently focused.")); 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"), boxWrap(tr("Highlight message on hover"),
messageHoverHighlight_, messageHoverHighlight_,
tr("Change the background color of messages when you hover over them.")); tr("Change the background color of messages when you hover over them."));
@ -680,6 +697,10 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
settings_->setDesktopNotifications(!disabled); settings_->setDesktopNotifications(!disabled);
}); });
connect(alertOnNotification_, &Toggle::toggled, this, [this](bool disabled) {
settings_->setAlertOnNotification(!disabled);
});
connect(messageHoverHighlight_, &Toggle::toggled, this, [this](bool disabled) { connect(messageHoverHighlight_, &Toggle::toggled, this, [this](bool disabled) {
settings_->setMessageHoverHighlight(!disabled); settings_->setMessageHoverHighlight(!disabled);
}); });
@ -725,6 +746,7 @@ UserSettingsPage::showEvent(QShowEvent *)
readReceipts_->setState(!settings_->readReceipts()); readReceipts_->setState(!settings_->readReceipts());
markdown_->setState(!settings_->markdown()); markdown_->setState(!settings_->markdown());
desktopNotifications_->setState(!settings_->hasDesktopNotifications()); desktopNotifications_->setState(!settings_->hasDesktopNotifications());
alertOnNotification_->setState(!settings_->hasAlertOnNotification());
messageHoverHighlight_->setState(!settings_->messageHoverHighlight()); messageHoverHighlight_->setState(!settings_->messageHoverHighlight());
enlargeEmojiOnlyMessages_->setState(!settings_->enlargeEmojiOnlyMessages()); enlargeEmojiOnlyMessages_->setState(!settings_->enlargeEmojiOnlyMessages());
deviceIdValue_->setText(QString::fromStdString(http::client()->device_id())); deviceIdValue_->setText(QString::fromStdString(http::client()->device_id()));

View File

@ -58,6 +58,8 @@ class UserSettings : public QObject
bool readReceipts READ readReceipts WRITE setReadReceipts NOTIFY readReceiptsChanged) bool readReceipts READ readReceipts WRITE setReadReceipts NOTIFY readReceiptsChanged)
Q_PROPERTY(bool desktopNotifications READ hasDesktopNotifications WRITE Q_PROPERTY(bool desktopNotifications READ hasDesktopNotifications WRITE
setDesktopNotifications NOTIFY desktopNotificationsChanged) setDesktopNotifications NOTIFY desktopNotificationsChanged)
Q_PROPERTY(bool alertOnNotification READ hasAlertOnNotification WRITE setAlertOnNotification
NOTIFY alertOnNotificationChanged)
Q_PROPERTY( Q_PROPERTY(
bool avatarCircles READ avatarCircles WRITE setAvatarCircles NOTIFY avatarCirclesChanged) bool avatarCircles READ avatarCircles WRITE setAvatarCircles NOTIFY avatarCirclesChanged)
Q_PROPERTY(bool decryptSidebar READ decryptSidebar WRITE setDecryptSidebar NOTIFY Q_PROPERTY(bool decryptSidebar READ decryptSidebar WRITE setDecryptSidebar NOTIFY
@ -91,6 +93,7 @@ public:
void setButtonsInTimeline(bool state); void setButtonsInTimeline(bool state);
void setTimelineMaxWidth(int state); void setTimelineMaxWidth(int state);
void setDesktopNotifications(bool state); void setDesktopNotifications(bool state);
void setAlertOnNotification(bool state);
void setAvatarCircles(bool state); void setAvatarCircles(bool state);
void setDecryptSidebar(bool state); void setDecryptSidebar(bool state);
@ -108,6 +111,11 @@ public:
bool buttonsInTimeline() const { return buttonsInTimeline_; } bool buttonsInTimeline() const { return buttonsInTimeline_; }
bool readReceipts() const { return readReceipts_; } bool readReceipts() const { return readReceipts_; }
bool hasDesktopNotifications() const { return hasDesktopNotifications_; } bool hasDesktopNotifications() const { return hasDesktopNotifications_; }
bool hasAlertOnNotification() const { return hasAlertOnNotification_; }
bool hasNotifications() const
{
return hasDesktopNotifications() || hasAlertOnNotification();
}
int timelineMaxWidth() const { return timelineMaxWidth_; } int timelineMaxWidth() const { return timelineMaxWidth_; }
double fontSize() const { return baseFontSize_; } double fontSize() const { return baseFontSize_; }
QString font() const { return font_; } QString font() const { return font_; }
@ -126,6 +134,7 @@ signals:
void buttonInTimelineChanged(bool state); void buttonInTimelineChanged(bool state);
void readReceiptsChanged(bool state); void readReceiptsChanged(bool state);
void desktopNotificationsChanged(bool state); void desktopNotificationsChanged(bool state);
void alertOnNotificationChanged(bool state);
void avatarCirclesChanged(bool state); void avatarCirclesChanged(bool state);
void decryptSidebarChanged(bool state); void decryptSidebarChanged(bool state);
void timelineMaxWidthChanged(int state); void timelineMaxWidthChanged(int state);
@ -151,6 +160,7 @@ private:
bool buttonsInTimeline_; bool buttonsInTimeline_;
bool readReceipts_; bool readReceipts_;
bool hasDesktopNotifications_; bool hasDesktopNotifications_;
bool hasAlertOnNotification_;
bool avatarCircles_; bool avatarCircles_;
bool decryptSidebar_; bool decryptSidebar_;
int timelineMaxWidth_; int timelineMaxWidth_;
@ -208,6 +218,7 @@ private:
Toggle *readReceipts_; Toggle *readReceipts_;
Toggle *markdown_; Toggle *markdown_;
Toggle *desktopNotifications_; Toggle *desktopNotifications_;
Toggle *alertOnNotification_;
Toggle *avatarCircles_; Toggle *avatarCircles_;
Toggle *decryptSidebar_; Toggle *decryptSidebar_;
QLabel *deviceFingerprintValue_; QLabel *deviceFingerprintValue_;