From e68b7672a6379ea575c85826dad84e10c1977830 Mon Sep 17 00:00:00 2001 From: Patrick von Reth Date: Mon, 29 Jun 2015 14:34:10 +0200 Subject: [PATCH] fix emergency notification --- src/libsnore/utils.cpp | 5 +---- .../frontends/pushover/pushover_frontend.cpp | 12 +++++++++--- .../secondary_backends/pushover/pushover.cpp | 13 +++++++++++++ 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/libsnore/utils.cpp b/src/libsnore/utils.cpp index 79bf43d..ef15cba 100644 --- a/src/libsnore/utils.cpp +++ b/src/libsnore/utils.cpp @@ -84,10 +84,7 @@ QString Utils::normalizeMarkup(QString string, MARKUP_FLAGS tags) if(tags == ALL_MARKUP){ return string; } else if(tags == NO_MARKUP) { - if (Qt::mightBeRichText(string)) { - return QTextDocumentFragment::fromHtml(string).toPlainText(); - } - return string; + return QTextDocumentFragment::fromHtml(string).toPlainText(); } QMutexLocker lock(&mutex); diff --git a/src/plugins/frontends/pushover/pushover_frontend.cpp b/src/plugins/frontends/pushover/pushover_frontend.cpp index 55509a7..c2b8eb1 100644 --- a/src/plugins/frontends/pushover/pushover_frontend.cpp +++ b/src/plugins/frontends/pushover/pushover_frontend.cpp @@ -206,6 +206,8 @@ void PushoverFrontend::getMessages() reply->close(); reply->deleteLater(); + snoreDebug(SNORE_DEBUG) << input; + QJsonObject message = QJsonDocument::fromJson(input).object(); int latestID = -1; @@ -223,12 +225,13 @@ void PushoverFrontend::getMessages() Icon icon(QString("https://api.pushover.net/icons/%1.png").arg(notification.value("icon").toString())); app = Application(appName, icon); app.addAlert(Alert("Default", icon)); - if(notification.value("html").toInt() == 1) { - app.hints().setValue("use-markup", QVariant::fromValue(true)) ; - } SnoreCore::instance().registerApplication(app); } + if(notification.value("html").toInt() == 1) { + app.hints().setValue("use-markup", QVariant::fromValue(true)) ; + } + Notification n(app, *app.alerts().begin(), notification.value("title").toString(), notification.value("message").toString(), app.icon(), Notification::defaultTimeout(), static_cast(notification.value("priority").toInt())); @@ -271,10 +274,12 @@ void PushoverFrontend::acknowledgeNotification(Notification notification) if(notification.constHints().value("acked").toInt() == 1){ return; } + snoreDebug(SNORE_DEBUG) << notification.constHints().value("acked").toInt(); QString receipt = notification.constHints().value("receipt").toString(); QNetworkRequest request(QUrl(QString("https://api.pushover.net/1/receipts/%1/acknowledge.json").arg(receipt))); + snoreDebug(SNORE_WARNING) << request.url(); request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/x-www-form-urlencoded")); QNetworkReply *reply = m_manager.post(request, QString("secret=%1").arg(secret()).toUtf8().constData()); @@ -282,6 +287,7 @@ void PushoverFrontend::acknowledgeNotification(Notification notification) connect(reply, &QNetworkReply::finished, [reply]() { snoreDebug(SNORE_DEBUG) << reply->error(); snoreDebug(SNORE_DEBUG) << reply->readAll(); + //TODO:parse reply reply->close(); reply->deleteLater(); }); diff --git a/src/plugins/secondary_backends/pushover/pushover.cpp b/src/plugins/secondary_backends/pushover/pushover.cpp index 151504f..b619b6e 100644 --- a/src/plugins/secondary_backends/pushover/pushover.cpp +++ b/src/plugins/secondary_backends/pushover/pushover.cpp @@ -56,6 +56,7 @@ void Pushover::slotNotify(Notification notification) QHttpPart text; text.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"message\"")); + snoreDebug(SNORE_DEBUG) << "Use Markup" << notification.application().constHints().value("use-markup").toBool(); snoreDebug(SNORE_DEBUG) << "Message" << textString; text.setBody(textString.toUtf8().constData()); mp->append(text); @@ -64,6 +65,18 @@ void Pushover::slotNotify(Notification notification) priority.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"priority\"")); priority.setBody(QString::number(notification.priority()).toUtf8().constData()); mp->append(priority); + if(notification.priority() == Notification::EMERGENCY){ + + QHttpPart retry; + retry.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"retry\"")); + retry.setBody("30");// rety every 30 s + mp->append(retry); + + QHttpPart expire; + expire.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"expire\"")); + expire.setBody("300");//5 min + mp->append(expire); + } QHttpPart sound; sound.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"sound\""));