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: {