From a43f70397139209fcf2eefb1eb0b264f5f949d31 Mon Sep 17 00:00:00 2001 From: sochs Date: Thu, 14 Dec 2023 16:51:53 +0100 Subject: [PATCH] Add android channel id Add android channel id to app devices --- src/API.cpp | 1 + src/Notification.cpp | 6 ++++++ src/Notification.h | 1 + src/WebHandler.cpp | 6 ++++++ 4 files changed, 14 insertions(+) diff --git a/src/API.cpp b/src/API.cpp index 52366c9e..b483d0c1 100644 --- a/src/API.cpp +++ b/src/API.cpp @@ -310,6 +310,7 @@ void API::notificationObj(JsonObject &jObj) _app["token"] = String(pushApp.devices[i].token); _app["device_id"] = DeviceId::get(); _app["sound"] = gSystem->notification.getNotificationSound(pushApp.devices[i].sound); + _app["android_channel_id"] = String(pushApp.devices[i].androidchannelid); } } } diff --git a/src/Notification.cpp b/src/Notification.cpp index ba7488ed..408e471b 100644 --- a/src/Notification.cpp +++ b/src/Notification.cpp @@ -221,6 +221,7 @@ void Notification::saveConfig() device["id"] = pushApp.devices[i].id; device["token"] = pushApp.devices[i].token; device["sound"] = pushApp.devices[i].sound; + device["androidchannelid"] = pushApp.devices[i].androidchannelid; } } @@ -317,6 +318,11 @@ void Notification::loadConfig() pushApp.devices[deviceIndex].sound = _device["sound"].as(); } + if (_device.containsKey("androidchannelid")) + { + strcpy(pushApp.devices[deviceIndex].androidchannelid, _device["androidchannelid"].asString()); + } + deviceIndex++; } } diff --git a/src/Notification.h b/src/Notification.h index e0c9981d..d6fc42f9 100644 --- a/src/Notification.h +++ b/src/Notification.h @@ -73,6 +73,7 @@ typedef struct char name[31]; char id[65]; char token[255]; + char androidchannelid[255]; uint8_t sound; } PushAppDeviceType; diff --git a/src/WebHandler.cpp b/src/WebHandler.cpp index 0298734b..0d7515ee 100644 --- a/src/WebHandler.cpp +++ b/src/WebHandler.cpp @@ -863,6 +863,7 @@ bool NanoWebHandler::setPush(AsyncWebServerRequest *request, uint8_t *datas) boolean hasToken = _device.containsKey("token"); boolean hasHashedToken = _device.containsKey("token_sha256"); boolean hasSound = _device.containsKey("sound"); + boolean hasAndroidChannelID = _device.containsKey("android_channel_id"); // check length of name and id if ((strlen(_device["name"].asString()) >= sizeof(PushAppDeviceType::name)) && @@ -900,6 +901,11 @@ bool NanoWebHandler::setPush(AsyncWebServerRequest *request, uint8_t *datas) app.devices[deviceIndex].sound = _device["sound"].as(); } + if(hasAndroidChannelID) + { + strcpy(app.devices[deviceIndex].androidchannelid, _device["android_channel_id"].asString()); + } + deviceIndex++; } }