Skip to content

Commit

Permalink
Merge pull request #3 from netiul/fix/do_not_serialize_empty_notifica…
Browse files Browse the repository at this point in the history
…tion

Do not serialize notification object when it contains no serializable…
  • Loading branch information
redjanym committed Aug 21, 2017
2 parents 62d514c + 0f9b2fc commit f117cbe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
7 changes: 6 additions & 1 deletion src/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit f117cbe

Please sign in to comment.