From 38fbd0266d171ae007ba20be8ddee2f8964a9269 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Sat, 9 Jan 2021 00:56:16 +0100 Subject: [PATCH] Allow configuring the plugin with a dummy backend --- pushnotifications/README.md | 2 +- .../integrationpluginpushnotifications.cpp | 19 ++++++++++++------- .../integrationpluginpushnotifications.json | 2 +- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/pushnotifications/README.md b/pushnotifications/README.md index b5a6d620..c0f105a9 100644 --- a/pushnotifications/README.md +++ b/pushnotifications/README.md @@ -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. diff --git a/pushnotifications/integrationpluginpushnotifications.cpp b/pushnotifications/integrationpluginpushnotifications.cpp index 27779fcb..74b7e7e6 100644 --- a/pushnotifications/integrationpluginpushnotifications.cpp +++ b/pushnotifications/integrationpluginpushnotifications.cpp @@ -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()); diff --git a/pushnotifications/integrationpluginpushnotifications.json b/pushnotifications/integrationpluginpushnotifications.json index ef1b916a..382b613b 100644 --- a/pushnotifications/integrationpluginpushnotifications.json +++ b/pushnotifications/integrationpluginpushnotifications.json @@ -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",