Skip to content

Commit f117cbe

Browse files
authored
Merge pull request #3 from netiul/fix/do_not_serialize_empty_notification
Do not serialize notification object when it contains no serializable…
2 parents 62d514c + 0f9b2fc commit f117cbe

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/Message.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public function jsonSerialize()
174174
if ($this->contentAvailable) {
175175
$jsonData['content_available'] = $this->contentAvailable;
176176
}
177-
if ($this->notification) {
177+
if ($this->notification && $this->notification->hasNotificationData()) {
178178
$jsonData['notification'] = $this->notification;
179179
}
180180

src/Notification.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,14 @@ public function setTag($tag)
7777
return $this;
7878
}
7979

80+
public function hasNotificationData()
81+
{
82+
return $this->title || $this->body || $this->badge || $this->icon || $this->clickAction || $this->sound || $this->tag;
83+
}
84+
8085
public function jsonSerialize()
8186
{
82-
$jsonData = $this->getJsonData();
87+
$jsonData = [];
8388
if ($this->title) {
8489
$jsonData['title'] = $this->title;
8590
}

0 commit comments

Comments
 (0)