From a9947ff9f77ab65eb011c1a15bcfd47a43f2808f Mon Sep 17 00:00:00 2001 From: Johannes Bachmann <45299708+dscheinah@users.noreply.github.com> Date: Sat, 18 Nov 2023 23:11:17 +0100 Subject: [PATCH] Always append last message content to notifications (#514) * always append last message content to notifications * make "always show notification" configurable * add unfinished translations * Fix spacing if no sender is printed --- .../settingsPage/SettingsBehavior.qml | 11 ++++++++++ src/appsettings.cpp | 15 ++++++++++++++ src/appsettings.h | 5 +++++ src/notificationmanager.cpp | 20 +++++++++++-------- translations/harbour-fernschreiber-de.ts | 8 ++++++++ translations/harbour-fernschreiber-en.ts | 8 ++++++++ translations/harbour-fernschreiber-es.ts | 8 ++++++++ translations/harbour-fernschreiber-fi.ts | 8 ++++++++ translations/harbour-fernschreiber-fr.ts | 8 ++++++++ translations/harbour-fernschreiber-hu.ts | 8 ++++++++ translations/harbour-fernschreiber-it.ts | 8 ++++++++ translations/harbour-fernschreiber-pl.ts | 8 ++++++++ translations/harbour-fernschreiber-ru.ts | 8 ++++++++ translations/harbour-fernschreiber-sk.ts | 8 ++++++++ translations/harbour-fernschreiber-sv.ts | 8 ++++++++ translations/harbour-fernschreiber-zh_CN.ts | 8 ++++++++ translations/harbour-fernschreiber.ts | 8 ++++++++ 17 files changed, 147 insertions(+), 8 deletions(-) diff --git a/qml/components/settingsPage/SettingsBehavior.qml b/qml/components/settingsPage/SettingsBehavior.qml index 17746f7..9c6b961 100644 --- a/qml/components/settingsPage/SettingsBehavior.qml +++ b/qml/components/settingsPage/SettingsBehavior.qml @@ -191,6 +191,17 @@ AccordionItem { } Behavior on height { SmoothedAnimation { duration: 200 } } } + + TextSwitch { + width: parent.columnWidth + checked: appSettings.notificationAlwaysShowPreview + text: qsTr("Always append message preview to notifications") + description: qsTr("In addition to showing the number of unread messages, the latest message will also be appended to notifications.") + automaticCheck: false + onClicked: { + appSettings.notificationAlwaysShowPreview = !checked + } + } } } } diff --git a/src/appsettings.cpp b/src/appsettings.cpp index 146d296..caf64d5 100644 --- a/src/appsettings.cpp +++ b/src/appsettings.cpp @@ -31,6 +31,7 @@ namespace { const QString KEY_NOTIFICATION_SOUNDS_ENABLED("notificationSoundsEnabled"); const QString KEY_NOTIFICATION_SUPPRESS_ENABLED("notificationSuppressContent"); const QString KEY_NOTIFICATION_FEEDBACK("notificationFeedback"); + const QString KEY_NOTIFICATION_ALWAYS_SHOW_PREVIEW("notificationAlwaysShowPreview"); const QString KEY_STORAGE_OPTIMIZER("useStorageOptimizer"); const QString KEY_INLINEBOT_LOCATION_ACCESS("allowInlineBotLocationAccess"); const QString KEY_REMAINING_INTERACTION_HINTS("remainingInteractionHints"); @@ -185,6 +186,20 @@ void AppSettings::setNotificationFeedback(NotificationFeedback feedback) } } +bool AppSettings::notificationAlwaysShowPreview() const +{ + return settings.value(KEY_NOTIFICATION_ALWAYS_SHOW_PREVIEW, false).toBool(); +} + +void AppSettings::setNotificationAlwaysShowPreview(bool enable) +{ + if (notificationAlwaysShowPreview() != enable) { + LOG(KEY_NOTIFICATION_ALWAYS_SHOW_PREVIEW << enable); + settings.setValue(KEY_NOTIFICATION_ALWAYS_SHOW_PREVIEW, enable); + emit notificationAlwaysShowPreviewChanged(); + } +} + bool AppSettings::storageOptimizer() const { return settings.value(KEY_STORAGE_OPTIMIZER, true).toBool(); diff --git a/src/appsettings.h b/src/appsettings.h index 7ddc7ca..e4a1a2d 100644 --- a/src/appsettings.h +++ b/src/appsettings.h @@ -34,6 +34,7 @@ class AppSettings : public QObject { 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 notificationAlwaysShowPreview READ notificationAlwaysShowPreview WRITE setNotificationAlwaysShowPreview NOTIFY notificationAlwaysShowPreviewChanged) Q_PROPERTY(bool storageOptimizer READ storageOptimizer WRITE setStorageOptimizer NOTIFY storageOptimizerChanged) Q_PROPERTY(bool allowInlineBotLocationAccess READ allowInlineBotLocationAccess WRITE setAllowInlineBotLocationAccess NOTIFY allowInlineBotLocationAccessChanged) Q_PROPERTY(int remainingInteractionHints READ remainingInteractionHints WRITE setRemainingInteractionHints NOTIFY remainingInteractionHintsChanged) @@ -91,6 +92,9 @@ public: NotificationFeedback notificationFeedback() const; void setNotificationFeedback(NotificationFeedback feedback); + bool notificationAlwaysShowPreview() const; + void setNotificationAlwaysShowPreview(bool enable); + bool storageOptimizer() const; void setStorageOptimizer(bool enable); @@ -126,6 +130,7 @@ signals: void notificationSoundsEnabledChanged(); void notificationSuppressContentChanged(); void notificationFeedbackChanged(); + void notificationAlwaysShowPreviewChanged(); void storageOptimizerChanged(); void allowInlineBotLocationAccessChanged(); void remainingInteractionHintsChanged(); diff --git a/src/notificationmanager.cpp b/src/notificationmanager.cpp index 2bd4bd8..f4d6127 100644 --- a/src/notificationmanager.cpp +++ b/src/notificationmanager.cpp @@ -341,8 +341,18 @@ void NotificationManager::publishNotification(const NotificationGroup *notificat QString notificationBody; const QVariantMap senderInformation = messageMap.value(SENDER_ID).toMap(); - if (notificationGroup->totalCount == 1 && !messageMap.isEmpty()) { + bool outputMessageCount = notificationGroup->totalCount > 1; + bool messageIsEmpty = messageMap.isEmpty(); + if (outputMessageCount || messageIsEmpty) { + // Either we have more than one notification or we have no content to display + LOG("Group" << notificationGroup->notificationGroupId << "has" << notificationGroup->totalCount << "notifications"); + notificationBody = tr("%Ln unread messages", "", notificationGroup->totalCount); + } + if ((!outputMessageCount || appSettings->notificationAlwaysShowPreview()) && !messageIsEmpty) { LOG("Group" << notificationGroup->notificationGroupId << "has 1 notification"); + if (outputMessageCount) { + notificationBody += "; "; + } if (chatInformation && (chatInformation->type == TDLibWrapper::ChatTypeBasicGroup || (chatInformation->type == TDLibWrapper::ChatTypeSupergroup && !chatInformation->isChannel))) { // Add author @@ -352,15 +362,9 @@ void NotificationManager::publishNotification(const NotificationGroup *notificat } else { fullName = FernschreiberUtils::getUserName(tdLibWrapper->getUserInformation(senderInformation.value(USER_ID).toString())); } - - notificationBody = notificationBody + fullName.trimmed() + ": "; + notificationBody += fullName.trimmed() + ": "; } notificationBody += FernschreiberUtils::getMessageShortText(tdLibWrapper, messageMap.value(CONTENT).toMap(), (chatInformation ? chatInformation->isChannel : false), tdLibWrapper->getUserInformation().value(ID).toLongLong(), senderInformation ); - nemoNotification->setBody(notificationBody); - } else { - // Either we have more than one notification or we have no content to display - LOG("Group" << notificationGroup->notificationGroupId << "has" << notificationGroup->totalCount << "notifications"); - notificationBody = tr("%Ln unread messages", "", notificationGroup->totalCount); } const QString summary(chatInformation ? chatInformation->title : QString()); diff --git a/translations/harbour-fernschreiber-de.ts b/translations/harbour-fernschreiber-de.ts index 2009446..9624d96 100644 --- a/translations/harbour-fernschreiber-de.ts +++ b/translations/harbour-fernschreiber-de.ts @@ -1575,6 +1575,14 @@ When sounds are enabled, Fernschreiber will use the current Sailfish OS notification sound for chats, which can be configured in the system settings. Wenn Töne eingeschaltet sind, wird Fernschreiber den aktuellen Sailfish OS-Hinweiston für Chats verwenden, der in den Systemeinstellungen konfiguriert werden kann. + + Always append message preview to notifications + Immer bei Hinweisen die Nachricht ausgeben + + + In addition to showing the number of unread messages, the latest message will also be appended to notifications. + Zusätzlich zur Anzahl der ungelesenen Nachrichten wird immer die neuste Nachricht an Hinweise angefügt. + SettingsPage diff --git a/translations/harbour-fernschreiber-en.ts b/translations/harbour-fernschreiber-en.ts index 5d29139..e3c7b3c 100644 --- a/translations/harbour-fernschreiber-en.ts +++ b/translations/harbour-fernschreiber-en.ts @@ -1577,6 +1577,14 @@ messages When sounds are enabled, Fernschreiber will use the current Sailfish OS notification sound for chats, which can be configured in the system settings. When sounds are enabled, Fernschreiber will use the current Sailfish OS notification sound for chats, which can be configured in the system settings. + + Always append message preview to notifications + Always append message preview to notifications + + + In addition to showing the number of unread messages, the latest message will also be appended to notifications. + In addition to showing the number of unread messages, the latest message will also be appended to notifications. + SettingsPage diff --git a/translations/harbour-fernschreiber-es.ts b/translations/harbour-fernschreiber-es.ts index 4c35f53..6a637ba 100644 --- a/translations/harbour-fernschreiber-es.ts +++ b/translations/harbour-fernschreiber-es.ts @@ -1575,6 +1575,14 @@ When sounds are enabled, Fernschreiber will use the current Sailfish OS notification sound for chats, which can be configured in the system settings. Cuando los sonidos están habilitados, Fernschreiber utilizará el sonido de notificación actual de Sailfish OS para los grupos, que se puede configurar en la configuración del sistema. + + Always append message preview to notifications + + + + In addition to showing the number of unread messages, the latest message will also be appended to notifications. + + SettingsPage diff --git a/translations/harbour-fernschreiber-fi.ts b/translations/harbour-fernschreiber-fi.ts index ac089e9..c462838 100644 --- a/translations/harbour-fernschreiber-fi.ts +++ b/translations/harbour-fernschreiber-fi.ts @@ -1576,6 +1576,14 @@ When sounds are enabled, Fernschreiber will use the current Sailfish OS notification sound for chats, which can be configured in the system settings. Kun äänet ovat käytössä, Fernschreiber käyttää Sailfish OS:n ilmoitusääniä keskusteluille, jotia voit muuttaa järjestelmäasetuksista. + + Always append message preview to notifications + + + + In addition to showing the number of unread messages, the latest message will also be appended to notifications. + + SettingsPage diff --git a/translations/harbour-fernschreiber-fr.ts b/translations/harbour-fernschreiber-fr.ts index 6fc3cde..fb8b385 100644 --- a/translations/harbour-fernschreiber-fr.ts +++ b/translations/harbour-fernschreiber-fr.ts @@ -1575,6 +1575,14 @@ When sounds are enabled, Fernschreiber will use the current Sailfish OS notification sound for chats, which can be configured in the system settings. Lorsque le son est activé, Fernschreiber utilisera le réglage de Sailfish OS. Celui-ci est paramétrable depuis les paramètres du système. + + Always append message preview to notifications + + + + In addition to showing the number of unread messages, the latest message will also be appended to notifications. + + SettingsPage diff --git a/translations/harbour-fernschreiber-hu.ts b/translations/harbour-fernschreiber-hu.ts index 9926c27..0571486 100644 --- a/translations/harbour-fernschreiber-hu.ts +++ b/translations/harbour-fernschreiber-hu.ts @@ -1548,6 +1548,14 @@ When sounds are enabled, Fernschreiber will use the current Sailfish OS notification sound for chats, which can be configured in the system settings. + + Always append message preview to notifications + + + + In addition to showing the number of unread messages, the latest message will also be appended to notifications. + + SettingsPage diff --git a/translations/harbour-fernschreiber-it.ts b/translations/harbour-fernschreiber-it.ts index c3bec32..7e45e52 100644 --- a/translations/harbour-fernschreiber-it.ts +++ b/translations/harbour-fernschreiber-it.ts @@ -1575,6 +1575,14 @@ When sounds are enabled, Fernschreiber will use the current Sailfish OS notification sound for chats, which can be configured in the system settings. Quando i suoni di notifica sono attivi, Fernschreiber utilizza l'attuale suono di notifica per i messaggi scelto per Sailfish OS, il quale può essere modificato dalle impostazioni di sistema. + + Always append message preview to notifications + + + + In addition to showing the number of unread messages, the latest message will also be appended to notifications. + + SettingsPage diff --git a/translations/harbour-fernschreiber-pl.ts b/translations/harbour-fernschreiber-pl.ts index 498951b..ab12670 100644 --- a/translations/harbour-fernschreiber-pl.ts +++ b/translations/harbour-fernschreiber-pl.ts @@ -1602,6 +1602,14 @@ When sounds are enabled, Fernschreiber will use the current Sailfish OS notification sound for chats, which can be configured in the system settings. Gdy dźwięki są włączone, Fernschreiber użyje bieżącego dźwięku powiadomienia Sailfish OS do czatów, które można skonfigurować w ustawieniach systemu. + + Always append message preview to notifications + + + + In addition to showing the number of unread messages, the latest message will also be appended to notifications. + + SettingsPage diff --git a/translations/harbour-fernschreiber-ru.ts b/translations/harbour-fernschreiber-ru.ts index 9db0913..2b291a8 100644 --- a/translations/harbour-fernschreiber-ru.ts +++ b/translations/harbour-fernschreiber-ru.ts @@ -1605,6 +1605,14 @@ When sounds are enabled, Fernschreiber will use the current Sailfish OS notification sound for chats, which can be configured in the system settings. Если звуки разрешены, Fernschreiber использует звук, выбранный для чатов в настройках Sailfish OS. + + Always append message preview to notifications + + + + In addition to showing the number of unread messages, the latest message will also be appended to notifications. + + SettingsPage diff --git a/translations/harbour-fernschreiber-sk.ts b/translations/harbour-fernschreiber-sk.ts index 1f055cb..c450cb4 100644 --- a/translations/harbour-fernschreiber-sk.ts +++ b/translations/harbour-fernschreiber-sk.ts @@ -1602,6 +1602,14 @@ When sounds are enabled, Fernschreiber will use the current Sailfish OS notification sound for chats, which can be configured in the system settings. Keď sú povolené zvukové upozornenia, Fernschreiber použije aktuálne zvukové upozornenia Sailfish OS pre čety, ktoré môžu byť upravené v nastaveniach systému. + + Always append message preview to notifications + + + + In addition to showing the number of unread messages, the latest message will also be appended to notifications. + + SettingsPage diff --git a/translations/harbour-fernschreiber-sv.ts b/translations/harbour-fernschreiber-sv.ts index 8288034..c18e20b 100644 --- a/translations/harbour-fernschreiber-sv.ts +++ b/translations/harbour-fernschreiber-sv.ts @@ -1575,6 +1575,14 @@ When sounds are enabled, Fernschreiber will use the current Sailfish OS notification sound for chats, which can be configured in the system settings. När ljud är aktiverat, använder Fernschreiber aktuell Sailfish-signal för chatt-avisering, vilken kan ställas in i systemets ljudinställningar. + + Always append message preview to notifications + + + + In addition to showing the number of unread messages, the latest message will also be appended to notifications. + + SettingsPage diff --git a/translations/harbour-fernschreiber-zh_CN.ts b/translations/harbour-fernschreiber-zh_CN.ts index 6a83637..4fec0e9 100644 --- a/translations/harbour-fernschreiber-zh_CN.ts +++ b/translations/harbour-fernschreiber-zh_CN.ts @@ -1549,6 +1549,14 @@ When sounds are enabled, Fernschreiber will use the current Sailfish OS notification sound for chats, which can be configured in the system settings. 如果开启声音,Fernschreiber 会采用当前旗鱼系统通知声音作为对话通知声音,你可以在系统设置进行配置。 + + Always append message preview to notifications + + + + In addition to showing the number of unread messages, the latest message will also be appended to notifications. + + SettingsPage diff --git a/translations/harbour-fernschreiber.ts b/translations/harbour-fernschreiber.ts index 7a65c7a..dea8736 100644 --- a/translations/harbour-fernschreiber.ts +++ b/translations/harbour-fernschreiber.ts @@ -1575,6 +1575,14 @@ When sounds are enabled, Fernschreiber will use the current Sailfish OS notification sound for chats, which can be configured in the system settings. + + Always append message preview to notifications + + + + In addition to showing the number of unread messages, the latest message will also be appended to notifications. + + SettingsPage