From 26c8469ba164b262ce1143e61575bd8a2746cc37 Mon Sep 17 00:00:00 2001 From: dunice Date: Mon, 13 Jan 2020 12:43:57 -0300 Subject: [PATCH 1/2] Added attributes to PushMessage class and some adjustments to PushChannel --- src/Channels/GcmChannel.php | 1 + src/Channels/PushChannel.php | 10 +++++----- src/Messages/PushMessage.php | 30 ++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/Channels/GcmChannel.php b/src/Channels/GcmChannel.php index 8997f98..2b9a42f 100644 --- a/src/Channels/GcmChannel.php +++ b/src/Channels/GcmChannel.php @@ -26,6 +26,7 @@ protected function buildData(PushMessage $message) 'title' => $message->title, 'body' => $message->body, 'sound' => $message->sound, + 'color' => $message->color, 'click_action' => $message->click_action, ], ]; diff --git a/src/Channels/PushChannel.php b/src/Channels/PushChannel.php index 1642938..d23ff83 100644 --- a/src/Channels/PushChannel.php +++ b/src/Channels/PushChannel.php @@ -32,13 +32,13 @@ public function __construct(PushNotification $push) */ public function send($notifiable, Notification $notification) { - if (! $to = $notifiable->routeNotificationFor($this->notificationFor())) { - return; - } - $message = $this->buildMessage($notifiable, $notification); - $data = $this->buildData($message); + $to = $message->to ?? $notifiable->routeNotificationFor($this->notificationFor()); + + if (! $to) { + return; + } $this->push($this->pushServiceName(), $to, $data, $message); } diff --git a/src/Messages/PushMessage.php b/src/Messages/PushMessage.php index 30bdc0d..b9247a6 100644 --- a/src/Messages/PushMessage.php +++ b/src/Messages/PushMessage.php @@ -4,6 +4,11 @@ class PushMessage { + /** + * @var string + */ + public $to; + /** * @var string */ @@ -49,6 +54,11 @@ class PushMessage */ public $config = []; + /** + * @var string + */ + public $color = '#000000'; + /** * Create a new message instance. * @@ -60,6 +70,13 @@ public function __construct($body = '') $this->body = $body; } + public function to($to) + { + $this->to = $to; + + return $this; + } + /** * Set the message body. * @@ -151,6 +168,19 @@ public function badge($badge) return $this; } + /** + * Set notification icon color. + * + * @param string $color + * @return $this + */ + public function color($color = '') + { + $this->color = $color; + + return $this; + } + /** * Set message extra data. * From f68e218c2d2bb373362b17cbff654b5301bfb572 Mon Sep 17 00:00:00 2001 From: dunice Date: Mon, 20 Jan 2020 12:11:55 -0300 Subject: [PATCH 2/2] Removed default value for color() method --- src/Messages/PushMessage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Messages/PushMessage.php b/src/Messages/PushMessage.php index b9247a6..76c2794 100644 --- a/src/Messages/PushMessage.php +++ b/src/Messages/PushMessage.php @@ -174,7 +174,7 @@ public function badge($badge) * @param string $color * @return $this */ - public function color($color = '') + public function color($color) { $this->color = $color;