fix emergency notification

This commit is contained in:
Patrick von Reth 2015-06-29 14:34:10 +02:00
parent 5f52062425
commit e68b7672a6
3 changed files with 23 additions and 7 deletions

View File

@ -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);

View File

@ -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::Prioritys>(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();
});

View File

@ -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\""));