Add option to suppress notification previews (#521)

* Add Switch in Settings

* Don't set notification preview body

* Support the setting in appSettings

* fixup! Add Switch in Settings

* Just show message count

* Also show only when notifications are enabled at all

---------

Co-authored-by: nephros <nemo@pgxperiiia10>
This commit is contained in:
Peter G 2023-11-18 21:58:05 +00:00 committed by GitHub
parent e44c69281c
commit 3620b8ed03
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 1 deletions

View file

@ -147,6 +147,20 @@ AccordionItem {
}
}
TextSwitch {
width: parent.columnWidth
checked: appSettings.notificationSuppressContent && enabled
text: qsTr("Hide content in Notifications")
enabled: appSettings.notificationFeedback !== AppSettings.NotificationFeedbackNone
clip: height < implicitHeight
visible: height > 0
automaticCheck: false
onClicked: {
appSettings.notificationSuppressContent = !checked
}
Behavior on height { SmoothedAnimation { duration: 200 } }
}
TextSwitch {
width: parent.columnWidth
checked: appSettings.notificationTurnsDisplayOn && enabled

View file

@ -29,6 +29,7 @@ namespace {
const QString KEY_ANIMATE_STICKERS("animateStickers");
const QString KEY_NOTIFICATION_TURNS_DISPLAY_ON("notificationTurnsDisplayOn");
const QString KEY_NOTIFICATION_SOUNDS_ENABLED("notificationSoundsEnabled");
const QString KEY_NOTIFICATION_SUPPRESS_ENABLED("notificationSuppressContent");
const QString KEY_NOTIFICATION_FEEDBACK("notificationFeedback");
const QString KEY_STORAGE_OPTIMIZER("useStorageOptimizer");
const QString KEY_INLINEBOT_LOCATION_ACCESS("allowInlineBotLocationAccess");
@ -156,6 +157,20 @@ void AppSettings::setNotificationSoundsEnabled(bool enable)
}
}
bool AppSettings::notificationSuppressContent() const
{
return settings.value(KEY_NOTIFICATION_SUPPRESS_ENABLED, false).toBool();
}
void AppSettings::setNotificationSuppressContent(bool enable)
{
if (notificationSuppressContent() != enable) {
LOG(KEY_NOTIFICATION_SUPPRESS_ENABLED << enable);
settings.setValue(KEY_NOTIFICATION_SUPPRESS_ENABLED, enable);
emit notificationSuppressContentChanged();
}
}
AppSettings::NotificationFeedback AppSettings::notificationFeedback() const
{
return (NotificationFeedback) settings.value(KEY_NOTIFICATION_FEEDBACK, (int) NotificationFeedbackAll).toInt();

View file

@ -32,6 +32,7 @@ class AppSettings : public QObject {
Q_PROPERTY(bool animateStickers READ animateStickers WRITE setAnimateStickers NOTIFY animateStickersChanged)
Q_PROPERTY(bool notificationTurnsDisplayOn READ notificationTurnsDisplayOn WRITE setNotificationTurnsDisplayOn NOTIFY notificationTurnsDisplayOnChanged)
Q_PROPERTY(bool notificationSoundsEnabled READ notificationSoundsEnabled WRITE setNotificationSoundsEnabled NOTIFY notificationSoundsEnabledChanged)
Q_PROPERTY(bool notificationSuppressContent READ notificationSuppressContent WRITE setNotificationSuppressContent NOTIFY notificationSuppressContentChanged)
Q_PROPERTY(NotificationFeedback notificationFeedback READ notificationFeedback WRITE setNotificationFeedback NOTIFY notificationFeedbackChanged)
Q_PROPERTY(bool storageOptimizer READ storageOptimizer WRITE setStorageOptimizer NOTIFY storageOptimizerChanged)
Q_PROPERTY(bool allowInlineBotLocationAccess READ allowInlineBotLocationAccess WRITE setAllowInlineBotLocationAccess NOTIFY allowInlineBotLocationAccessChanged)
@ -84,6 +85,9 @@ public:
bool notificationSoundsEnabled() const;
void setNotificationSoundsEnabled(bool enable);
bool notificationSuppressContent() const;
void setNotificationSuppressContent(bool enable);
NotificationFeedback notificationFeedback() const;
void setNotificationFeedback(NotificationFeedback feedback);
@ -120,6 +124,7 @@ signals:
void animateStickersChanged();
void notificationTurnsDisplayOnChanged();
void notificationSoundsEnabledChanged();
void notificationSuppressContentChanged();
void notificationFeedbackChanged();
void storageOptimizerChanged();
void allowInlineBotLocationAccessChanged();

View file

@ -377,7 +377,11 @@ void NotificationManager::publishNotification(const NotificationGroup *notificat
nemoNotification->setHintValue(HINT_VISIBILITY, QString());
nemoNotification->setUrgency(Notification::Low);
} else {
nemoNotification->setPreviewBody(notificationBody);
if (!appSettings->notificationSuppressContent()) {
nemoNotification->setPreviewBody(notificationBody);
} else {
nemoNotification->setPreviewBody(tr("%Ln unread messages", "", notificationGroup->totalCount));
}
nemoNotification->setPreviewSummary(summary);
nemoNotification->setHintValue(HINT_SUPPRESS_SOUND, !appSettings->notificationSoundsEnabled());
nemoNotification->setHintValue(HINT_DISPLAY_ON, appSettings->notificationTurnsDisplayOn());