Allow configuring the plugin with a dummy backend

master
Michael Zanetti 2021-01-09 00:56:16 +01:00
parent 5ccc29a205
commit 38fbd0266d
3 changed files with 14 additions and 9 deletions

View File

@ -18,7 +18,7 @@ for iOS too. On Ubuntu, the UBPorts push services are used.
## More
During setup, the token, the push service system and a client id needs to be provided. The token is normally
obtained by the operating system. The push service should be selected from GCM, APNs or UBPorts. The client id
obtained by the operating system. The push service should be selected from FB-GCM, FB-APNs or UBPorts. The client id
must a unique per client and as persistent as possible.
> Note: Even when using APNs, the token must be obtained using the Firebase SDK as plain APNs does not support sending push notifications from a distributed setup like nymea, but always requires a centralized server on the internet handling all messages.

View File

@ -87,18 +87,19 @@ void IntegrationPluginPushNotifications::setupThing(ThingSetupInfo *info)
qCDebug(dcPushNotifications()) << "Setting up push notifications" << thing->name() << "(" << clientId << ") for service" << pushService << "with token" << (token.mid(0, 5) + "******");
if (token.isEmpty()) {
//: Error setting up thing
info->finish(Thing::ThingErrorMissingParameter, QT_TR_NOOP("The token must not be empty."));
return;
}
QStringList availablePushServices = {"FB-GCM", "FB-APNs", "UBPorts"};
QStringList availablePushServices = {"FB-GCM", "FB-APNs", "UBPorts", "None"};
if (!availablePushServices.contains(pushService)) {
//: Error setting up thing
info->finish(Thing::ThingErrorMissingParameter, QT_TR_NOOP("The push service must not be empty."));
return;
}
if (pushService != "None" && token.isEmpty()) {
//: Error setting up thing
info->finish(Thing::ThingErrorMissingParameter, QT_TR_NOOP("The token must not be empty."));
return;
}
// In case of Firebase, check if we have the required API key
if (pushService.startsWith("FB") && apiKeyStorage()->requestKey("firebase").data("apiKey").isEmpty()) {
//: Error setting up thing
@ -122,7 +123,7 @@ void IntegrationPluginPushNotifications::executeAction(ThingActionInfo *info)
QString title = action.param(pushNotificationsNotifyActionTitleParamTypeId).value().toString();
QString body = action.param(pushNotificationsNotifyActionBodyParamTypeId).value().toString();
if (token.isEmpty()) {
if (pushService != "None" && token.isEmpty()) {
return info->finish(Thing::ThingErrorAuthenticationFailure, QT_TR_NOOP("Push notifications need to be reconfigured."));
}
@ -196,6 +197,10 @@ void IntegrationPluginPushNotifications::executeAction(ThingActionInfo *info)
payload.insert("appid", "io.guh.nymeaapp_nymea-app");
payload.insert("expire_on", QDateTime::currentDateTime().toUTC().addMSecs(1000 * 60 * 10).toString(Qt::ISODate));
payload.insert("token", token.toUtf8().trimmed());
} else if (pushService == "None") {
// Nothing to do here... It's the clients responsibility to fetch it from nymea
info->finish(Thing::ThingErrorNoError);
return;
}
qCDebug(dcPushNotifications()) << "Sending notification" << request.url().toString() << qUtf8Printable(QJsonDocument::fromVariant(payload).toJson());

View File

@ -21,7 +21,7 @@
"name": "service",
"displayName": "Push service",
"type": "QString",
"allowedValues": ["FB-GCM", "FB-APNs", "UBPorts"]
"allowedValues": ["FB-GCM", "FB-APNs", "UBPorts", "None"]
},
{
"id": "12ec06b2-44e7-486a-9169-31c684b91c8f",