From 0593bf09dd4620796e62ba3705dba071a228095e Mon Sep 17 00:00:00 2001 From: JonatanRek Date: Mon, 30 Mar 2020 08:55:36 +0200 Subject: [PATCH] API device registration notification #FIX --- api.php | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/api.php b/api.php index ed77767..8433449 100644 --- a/api.php +++ b/api.php @@ -126,33 +126,29 @@ if ($token == null || $token == "") { //Vstupní Checky if (!DeviceManager::registeret($token)) { + //Notification data setup $notificationMng = new NotificationManager; - $notificationData = []; $notificationData = [ 'title' => 'Info', 'body' => 'New device Detected Found', 'icon' => BASEDIR . '/app/templates/images/icon-192x192.png', ]; + + //Subdevice Registration $deviceId = DeviceManager::create($token, $token); foreach ($values as $key => $value) { if (!SubDeviceManager::getSubDeviceByMaster($deviceId, $key)) { SubDeviceManager::create($deviceId, $key, UNITS[$key]); } - - if ($notificationData != []) { - $subscribers = $notificationMng::getSubscription(); - foreach ($subscribers as $key => $subscriber) { - $logManager->write("[NOTIFICATION] SENDING TO" . $subscriber['id'] . " ", LogRecordType::INFO); - $notificationMng::sendSimpleNotification(SERVERKEY, $subscriber['token'], $notificationData); - } - } } - + //Notification for newly added Device - $subscribers = $notificationMng::getSubscription(); - foreach ($subscribers as $key => $subscriber) { - $logManager->write("[NOTIFICATION] SENDING TO" . $subscriber['id'] . " ", LogRecordType::INFO); - $notificationMng::sendSimpleNotification(SERVERKEY, $subscriber['token'], $notificationData); + if ($notificationData != []) { + $subscribers = $notificationMng::getSubscription(); + foreach ($subscribers as $key => $subscriber) { + $logManager->write("[NOTIFICATION] SENDING TO" . $subscriber['id'] . " ", LogRecordType::INFO); + $notificationMng::sendSimpleNotification(SERVERKEY, $subscriber['token'], $notificationData); + } } header($_SERVER["SERVER_PROTOCOL"]." 401 Unauthorized");