From e060032e6a8489533214d8bcda9c63ef1fa2768a Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Sat, 22 Feb 2025 10:33:52 -0500 Subject: [PATCH] Improve the notification setting description The current text has invited a lot of confusion around how notifications work in NeoChat, because it mentions "push notifications". Some users take it to mean that somehow the notifications appear in the background, but that's only supported if built with KUnifiedPush. To make it super clear, let's change the description dynamically based on whether: 1. NeoChat is built with KUnifiedPush support. 2. We were able to connect with the KUnifiedPush daemon and your server has a push gateway. --- src/neochatconnection.cpp | 17 +++++++++++++++++ src/neochatconnection.h | 15 +++++++++++++++ src/settings/GlobalNotificationsPage.qml | 12 +++++++++++- 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/neochatconnection.cpp b/src/neochatconnection.cpp index 1a4c1181a..1e7803f11 100644 --- a/src/neochatconnection.cpp +++ b/src/neochatconnection.cpp @@ -472,9 +472,12 @@ QCoro::Task NeoChatConnection::setupPushNotifications(QString endpoint) false); qInfo() << "Registered for push notifications"; + m_pushNotificationsEnabled = true; } else { qWarning() << "There's no gateway, not setting up push notifications."; + m_pushNotificationsEnabled = false; } + Q_EMIT enablePushNotificationsChanged(); #else Q_UNUSED(endpoint) co_return; @@ -536,4 +539,18 @@ bool NeoChatConnection::canEraseData() const return m_canEraseData; } +bool NeoChatConnection::pushNotificationsAvailable() const +{ +#ifdef HAVE_KUNIFIEDPUSH + return true; +#else + return false; +#endif +} + +bool NeoChatConnection::enablePushNotifications() const +{ + return m_pushNotificationsEnabled; +} + #include "moc_neochatconnection.cpp" diff --git a/src/neochatconnection.h b/src/neochatconnection.h index c0401d154..68c34d352 100644 --- a/src/neochatconnection.h +++ b/src/neochatconnection.h @@ -90,6 +90,16 @@ class NeoChatConnection : public Quotient::Connection */ Q_PROPERTY(bool canEraseData READ canEraseData NOTIFY canEraseDataChanged) + /** + * @brief Whether this build of NeoChat supports push notifications via KUnifiedPush. + */ + Q_PROPERTY(bool pushNotificationsAvailable READ pushNotificationsAvailable CONSTANT) + + /** + * @brief Whether we successfully set up push notifications with the server. + */ + Q_PROPERTY(bool enablePushNotifications READ enablePushNotifications NOTIFY enablePushNotificationsChanged) + public: /** * @brief Defines the status after an attempt to change the password on an account. @@ -178,6 +188,9 @@ public: // the reference could be destroyed before the task is finished QCoro::Task setupPushNotifications(QString endpoint); + bool pushNotificationsAvailable() const; + bool enablePushNotifications() const; + bool isOnline() const; LinkPreviewer *previewerForLink(const QUrl &link); @@ -196,6 +209,7 @@ Q_SIGNALS: void badgeNotificationCountChanged(NeoChatConnection *connection, int count); void canCheckMutualRoomsChanged(); void canEraseDataChanged(); + void enablePushNotificationsChanged(); /** * @brief Request a message be shown to the user of the given type. @@ -221,4 +235,5 @@ private: bool m_canCheckMutualRooms = false; bool m_canEraseData = false; + bool m_pushNotificationsEnabled = false; }; diff --git a/src/settings/GlobalNotificationsPage.qml b/src/settings/GlobalNotificationsPage.qml index 15532094a..69116e4a8 100644 --- a/src/settings/GlobalNotificationsPage.qml +++ b/src/settings/GlobalNotificationsPage.qml @@ -26,7 +26,17 @@ FormCard.FormCardPage { Layout.topMargin: Kirigami.Units.largeSpacing * 4 FormCard.FormCheckDelegate { text: i18n("Enable notifications for this account") - description: i18n("Whether push notifications are generated by your Matrix server") + description: { + if (connection.pushNotificationsAvailable) { + if (connection.enablePushNotifications) { + return i18n("Notifications can appear even when NeoChat isn't running."); + } else { + return i18n("Push notifications are available but could not be enabled."); + } + } else { + return i18n("Notifications will only appear when NeoChat is running."); + } + } checked: root.pushRuleModel.globalNotificationsEnabled enabled: root.pushRuleModel.globalNotificationsSet onToggled: {