fix emergency notification
This commit is contained in:
parent
5f52062425
commit
e68b7672a6
|
@ -84,10 +84,7 @@ QString Utils::normalizeMarkup(QString string, MARKUP_FLAGS tags)
|
||||||
if(tags == ALL_MARKUP){
|
if(tags == ALL_MARKUP){
|
||||||
return string;
|
return string;
|
||||||
} else if(tags == NO_MARKUP) {
|
} else if(tags == NO_MARKUP) {
|
||||||
if (Qt::mightBeRichText(string)) {
|
return QTextDocumentFragment::fromHtml(string).toPlainText();
|
||||||
return QTextDocumentFragment::fromHtml(string).toPlainText();
|
|
||||||
}
|
|
||||||
return string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QMutexLocker lock(&mutex);
|
QMutexLocker lock(&mutex);
|
||||||
|
|
|
@ -206,6 +206,8 @@ void PushoverFrontend::getMessages()
|
||||||
reply->close();
|
reply->close();
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
|
|
||||||
|
snoreDebug(SNORE_DEBUG) << input;
|
||||||
|
|
||||||
QJsonObject message = QJsonDocument::fromJson(input).object();
|
QJsonObject message = QJsonDocument::fromJson(input).object();
|
||||||
|
|
||||||
int latestID = -1;
|
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()));
|
Icon icon(QString("https://api.pushover.net/icons/%1.png").arg(notification.value("icon").toString()));
|
||||||
app = Application(appName, icon);
|
app = Application(appName, icon);
|
||||||
app.addAlert(Alert("Default", icon));
|
app.addAlert(Alert("Default", icon));
|
||||||
if(notification.value("html").toInt() == 1) {
|
|
||||||
app.hints().setValue("use-markup", QVariant::fromValue(true)) ;
|
|
||||||
}
|
|
||||||
SnoreCore::instance().registerApplication(app);
|
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(),
|
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()));
|
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){
|
if(notification.constHints().value("acked").toInt() == 1){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
snoreDebug(SNORE_DEBUG) << notification.constHints().value("acked").toInt();
|
||||||
QString receipt = notification.constHints().value("receipt").toString();
|
QString receipt = notification.constHints().value("receipt").toString();
|
||||||
|
|
||||||
QNetworkRequest request(QUrl(QString("https://api.pushover.net/1/receipts/%1/acknowledge.json").arg(receipt)));
|
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"));
|
request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/x-www-form-urlencoded"));
|
||||||
QNetworkReply *reply = m_manager.post(request, QString("secret=%1").arg(secret()).toUtf8().constData());
|
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]() {
|
connect(reply, &QNetworkReply::finished, [reply]() {
|
||||||
snoreDebug(SNORE_DEBUG) << reply->error();
|
snoreDebug(SNORE_DEBUG) << reply->error();
|
||||||
snoreDebug(SNORE_DEBUG) << reply->readAll();
|
snoreDebug(SNORE_DEBUG) << reply->readAll();
|
||||||
|
//TODO:parse reply
|
||||||
reply->close();
|
reply->close();
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
});
|
});
|
||||||
|
|
|
@ -56,6 +56,7 @@ void Pushover::slotNotify(Notification notification)
|
||||||
|
|
||||||
QHttpPart text;
|
QHttpPart text;
|
||||||
text.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"message\""));
|
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;
|
snoreDebug(SNORE_DEBUG) << "Message" << textString;
|
||||||
text.setBody(textString.toUtf8().constData());
|
text.setBody(textString.toUtf8().constData());
|
||||||
mp->append(text);
|
mp->append(text);
|
||||||
|
@ -64,6 +65,18 @@ void Pushover::slotNotify(Notification notification)
|
||||||
priority.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"priority\""));
|
priority.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"priority\""));
|
||||||
priority.setBody(QString::number(notification.priority()).toUtf8().constData());
|
priority.setBody(QString::number(notification.priority()).toUtf8().constData());
|
||||||
mp->append(priority);
|
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;
|
QHttpPart sound;
|
||||||
sound.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"sound\""));
|
sound.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"sound\""));
|
||||||
|
|
Loading…
Reference in New Issue