From 7f22a073125457e1ebf27255a4f0043714fe34fd Mon Sep 17 00:00:00 2001 From: Klaas Freitag Date: Fri, 11 Mar 2016 15:16:09 +0100 Subject: [PATCH] Notifications: Check if the account is connected before querying. Also avoid memory leaks if it is not connected. --- src/gui/servernotificationhandler.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/gui/servernotificationhandler.cpp b/src/gui/servernotificationhandler.cpp index 94ff13144..14a9e0710 100644 --- a/src/gui/servernotificationhandler.cpp +++ b/src/gui/servernotificationhandler.cpp @@ -28,16 +28,19 @@ ServerNotificationHandler::ServerNotificationHandler(QObject *parent) void ServerNotificationHandler::slotFetchNotifications(AccountState *ptr) { - /* start the notification fetch job as well */ - if( !ptr) { + // check connectivity and credentials + if( !( ptr && ptr->isConnected() && ptr->account() && + ptr->account()->credentials() && + ptr->account()->credentials()->ready() ) ) { + deleteLater(); return; } - // check if the account has notifications enabled. If the capabilities are // not yet valid, its assumed that notifications are available. - if( ptr->account() && ptr->account()->capabilities().isValid() ) { + if( ptr->account()->capabilities().isValid() ) { if( ! ptr->account()->capabilities().notificationsAvailable() ) { qDebug() << Q_FUNC_INFO << "Account" << ptr->account()->displayName() << "does not have notifications enabled."; + deleteLater(); return; } } @@ -55,6 +58,7 @@ void ServerNotificationHandler::slotNotificationsReceived(const QVariantMap& jso { if( statusCode != 200 ) { qDebug() << Q_FUNC_INFO << "Notifications failed with status code " << statusCode; + deleteLater(); return; }