From 0f9b2fc12124ecb751d9d219bb513af7ef880fe1 Mon Sep 17 00:00:00 2001 From: Zacharias Luiten Date: Thu, 17 Aug 2017 17:48:28 +0200 Subject: [PATCH] Do not serialize notification object when it contains no serializable data. This part of the payload is optional. --- src/Message.php | 2 +- src/Notification.php | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Message.php b/src/Message.php index 63d5a1c..973e609 100644 --- a/src/Message.php +++ b/src/Message.php @@ -174,7 +174,7 @@ public function jsonSerialize() if ($this->contentAvailable) { $jsonData['content_available'] = $this->contentAvailable; } - if ($this->notification) { + if ($this->notification && $this->notification->hasNotificationData()) { $jsonData['notification'] = $this->notification; } diff --git a/src/Notification.php b/src/Notification.php index cb0b289..0cd3a82 100644 --- a/src/Notification.php +++ b/src/Notification.php @@ -77,9 +77,14 @@ public function setTag($tag) return $this; } + public function hasNotificationData() + { + return $this->title || $this->body || $this->badge || $this->icon || $this->clickAction || $this->sound || $this->tag; + } + public function jsonSerialize() { - $jsonData = $this->getJsonData(); + $jsonData = []; if ($this->title) { $jsonData['title'] = $this->title; }