Merge PR #674: PushNotifications: Add more options for sending push notifications
commit
83d2c0f5a8
|
|
@ -122,11 +122,19 @@ void IntegrationPluginPushNotifications::executeAction(ThingActionInfo *info)
|
|||
QString title = action.param(pushNotificationsNotifyActionTitleParamTypeId).value().toString();
|
||||
QString body = action.param(pushNotificationsNotifyActionBodyParamTypeId).value().toString();
|
||||
QString data = action.paramValue(pushNotificationsNotifyActionDataParamTypeId).toString();
|
||||
QString notificationId = action.paramValue(pushNotificationsNotifyActionNotificationIdParamTypeId).toString();
|
||||
bool remove = action.paramValue(pushNotificationsNotifyActionRemoveParamTypeId).toBool();
|
||||
bool sound = action.paramValue(pushNotificationsNotifyActionSoundParamTypeId).toBool();
|
||||
|
||||
if (pushService != "None" && token.isEmpty()) {
|
||||
return info->finish(Thing::ThingErrorAuthenticationFailure, QT_TR_NOOP("Push notifications need to be reconfigured."));
|
||||
}
|
||||
|
||||
if (notificationId.isEmpty()) {
|
||||
notificationId = QUuid::createUuid().toString();
|
||||
}
|
||||
|
||||
|
||||
QVariantMap nymeaData;
|
||||
// FIXME: This is quite ugly but there isn't an API that allows to retrieve the server UUID yet
|
||||
NymeaSettings settings(NymeaSettings::SettingsRoleGlobal);
|
||||
|
|
@ -157,31 +165,39 @@ void IntegrationPluginPushNotifications::executeAction(ThingActionInfo *info)
|
|||
notification.insert("title", title);
|
||||
notification.insert("body", body);
|
||||
notification.insert("nymeaData", nymeaData);
|
||||
notification.insert("notificationId", notificationId);
|
||||
notification.insert("remove", remove);
|
||||
|
||||
|
||||
if (pushService == "FB-GCM") {
|
||||
|
||||
QVariantMap soundMap;
|
||||
soundMap.insert("sound", "default");
|
||||
notification.insert("sound", sound);
|
||||
|
||||
QVariantMap android;
|
||||
android.insert("priority", "high");
|
||||
android.insert("notification", soundMap);
|
||||
|
||||
payload.insert("android", android);
|
||||
payload.insert("data", notification);
|
||||
|
||||
} else if (pushService == "FB-APNs") {
|
||||
|
||||
notification.insert("sound", "default");
|
||||
if (sound) {
|
||||
notification.insert("sound", "default");
|
||||
}
|
||||
|
||||
QVariantMap headers;
|
||||
headers.insert("apns-priority", "10");
|
||||
headers.insert("apns-priority", sound ? "10" : "1");
|
||||
headers.insert("apns-collapse-id", notificationId);
|
||||
|
||||
QVariantMap apns;
|
||||
apns.insert("headers", headers);
|
||||
|
||||
notification.insert("tag", notificationId);
|
||||
|
||||
payload.insert("notification", notification);
|
||||
payload.insert("apns", apns);
|
||||
|
||||
payload.insert("collapse_key", notificationId);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -198,8 +214,8 @@ void IntegrationPluginPushNotifications::executeAction(ThingActionInfo *info)
|
|||
|
||||
QVariantMap notification;
|
||||
notification.insert("card", card);
|
||||
notification.insert("vibrate", true);
|
||||
notification.insert("sound", true);
|
||||
notification.insert("vibrate", sound);
|
||||
notification.insert("sound", sound);
|
||||
notification.insert("nymeaData", nymeaData);
|
||||
|
||||
QVariantMap data;
|
||||
|
|
@ -237,7 +253,7 @@ void IntegrationPluginPushNotifications::executeAction(ThingActionInfo *info)
|
|||
}
|
||||
|
||||
QVariantMap replyMap = jsonDoc.toVariant().toMap();
|
||||
// qDebug(dcPushNotifications) << qUtf8Printable(jsonDoc.toJson());
|
||||
// qDebug(dcPushNotifications) << qUtf8Printable(jsonDoc.toJson());
|
||||
|
||||
if (pushService == "FB-GCM" || pushService == "FB-APNs") {
|
||||
if (replyMap.value("success").toInt() != 1) {
|
||||
|
|
|
|||
|
|
@ -58,6 +58,27 @@
|
|||
"inputType": "TextArea",
|
||||
"defaultValue": ""
|
||||
},
|
||||
{
|
||||
"id": "a961c428-c824-410a-b4e6-527a13c4c4ed",
|
||||
"name": "notificationId",
|
||||
"displayName": "Notification ID",
|
||||
"type": "QString",
|
||||
"defaultValue": ""
|
||||
},
|
||||
{
|
||||
"id": "0f3c3661-e0c0-46df-a6da-aaf3a0e8157c",
|
||||
"name": "sound",
|
||||
"displayName": "Play sound",
|
||||
"type": "bool",
|
||||
"defaultValue": true
|
||||
},
|
||||
{
|
||||
"id": "92ffd4ff-4bb7-4261-a904-1ae3890704e0",
|
||||
"name": "remove",
|
||||
"displayName": "Remove",
|
||||
"type": "bool",
|
||||
"defaultValue": false
|
||||
},
|
||||
{
|
||||
"id": "ca36a33f-a7f2-4f59-8767-3522ecaaf8fb",
|
||||
"name": "data",
|
||||
|
|
|
|||
Loading…
Reference in New Issue