From a9d397340ecb1d26b3128a844bbc77531deaa666 Mon Sep 17 00:00:00 2001 From: Pesakitan22 Date: Wed, 18 Oct 2017 13:02:28 +0700 Subject: [PATCH 1/6] changed gcm to FCM --- src/PusherMessage.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/PusherMessage.php b/src/PusherMessage.php index 4440051..ec5c6e5 100644 --- a/src/PusherMessage.php +++ b/src/PusherMessage.php @@ -288,13 +288,14 @@ public function toiOS() /** * Format the message for Android. + * Changed from GCM to FCM * * @return array */ public function toAndroid() { $message = [ - 'gcm' => [ + 'fcm' => [ 'notification' => [ 'title' => $this->title, 'body' => $this->body, From bc6c30cea939e4fb36bf53bdb04989a6104b6f03 Mon Sep 17 00:00:00 2001 From: Pesakitan22 Date: Wed, 18 Oct 2017 13:07:17 +0700 Subject: [PATCH 2/6] package name --- composer.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 76e1687..795fa2a 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "dees040/pusher-push-notifications", + "name": "pesakitan22/pusher-push-notifications", "description": "Pusher native Push Notifications driver.", "keywords": [ "pusher-push-notifications", @@ -29,6 +29,11 @@ "name": "Sebastian De Deyne", "email": "sebastian@spatie.be", "homepage": "https://sebastiandedeyne.com" + }, + { + "name": "Deni Putra Perdana", + "email": "pesakitan22@about.me", + "homepage": "https://about.me/pesakitan22" } ], "require": { From acba116ecc18292ff2ac794ffdbb12c9ed7797c8 Mon Sep 17 00:00:00 2001 From: Pesakitan22 Date: Wed, 18 Oct 2017 21:51:16 +0700 Subject: [PATCH 3/6] notification on background --- src/PusherMessage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PusherMessage.php b/src/PusherMessage.php index ec5c6e5..905f7b3 100644 --- a/src/PusherMessage.php +++ b/src/PusherMessage.php @@ -296,7 +296,7 @@ public function toAndroid() { $message = [ 'fcm' => [ - 'notification' => [ + 'data' => [ 'title' => $this->title, 'body' => $this->body, 'sound' => $this->sound, From c5311c7a1bd9d811b74dc7323339ec1fc8e209d3 Mon Sep 17 00:00:00 2001 From: Pesakitan22 Date: Fri, 27 Oct 2017 15:36:15 +0700 Subject: [PATCH 4/6] custom data --- src/PusherMessage.php | 642 ++++++++++++++++++++---------------------- 1 file changed, 312 insertions(+), 330 deletions(-) diff --git a/src/PusherMessage.php b/src/PusherMessage.php index 905f7b3..6ce02c1 100644 --- a/src/PusherMessage.php +++ b/src/PusherMessage.php @@ -5,334 +5,316 @@ use Illuminate\Support\Arr; use NotificationChannels\PusherPushNotifications\Exceptions\CouldNotCreateMessage; -class PusherMessage -{ - /** - * The device platform (iOS/Android). - * - * @var string - */ - protected $platform = 'iOS'; - - /** - * The message title. - * - * @var string - */ - protected $title; - - /** - * The message body. - * - * @var string - */ - protected $body; - - /** - * The phone number the message should be sent from. - * - * @var string - */ - protected $sound = 'default'; - - /** - * The message icon (Android). - * - * @var string - */ - protected $icon; - - /** - * The number to display next to the push notification (iOS). - * - * @var int - */ - protected $badge; - - /** - * Extra options that will get added to the message. - * - * @var array - */ - protected $options = []; - - /** - * An extra message to the other platform. - * - * @var - */ - protected $extraMessage; - - /** - * @param string $body - * - * @return static - */ - public static function create($body = '') - { - return new static($body); - } - - /** - * @param string $body - */ - public function __construct($body = '') - { - $this->body = $body; - } - - /** - * Set the platform [iOS/Android]. - * - * @param string $platform - * - * @return $this - * - * @throws \NotificationChannels\PusherPushNotifications\Exceptions\CouldNotCreateMessage - */ - public function platform($platform) - { - if (! in_array($platform, ['iOS', 'Android'])) { - throw CouldNotCreateMessage::invalidPlatformGiven($platform); - } - - $this->platform = $platform; - - return $this; - } - - /** - * Set the platform to iOS. - * - * @return $this - */ - public function iOS() - { - $this->platform = 'iOS'; - - return $this; - } - - /** - * Set the platform to Android. - * - * @return $this - */ - public function android() - { - $this->platform = 'Android'; - - return $this; - } - - /** - * Set an extra message to be sent to Android. - * - * @param \NotificationChannels\PusherPushNotifications\PusherMessage $message - * @return $this - */ - public function withAndroid(PusherMessage $message) - { - $this->withExtra($message->android()); - - return $this; - } - - /** - * Set an extra message to be sent to iOS. - * - * @param \NotificationChannels\PusherPushNotifications\PusherMessage $message - * @return $this - */ - public function withiOS(PusherMessage $message) - { - $this->withExtra($message->iOS()); - - return $this; - } - - /** - * Set an extra message to be sent to another platform. - * - * @param \NotificationChannels\PusherPushNotifications\PusherMessage $message - * @return void - */ - private function withExtra(PusherMessage $message) - { - if ($message->getPlatform() == $this->platform) { - throw CouldNotCreateMessage::platformConflict($this->platform); - } - - $this->extraMessage = $message; - } - - /** - * Set the message title. - * - * @param string $value - * - * @return $this - */ - public function title($value) - { - $this->title = $value; - - return $this; - } - - /** - * Set the message body. - * - * @param string $value - * - * @return $this - */ - public function body($value) - { - $this->body = $value; - - return $this; - } - - /** - * Set the message sound (Android). - * - * @param string $value - * - * @return $this - */ - public function sound($value) - { - $this->sound = $value; - - return $this; - } - - /** - * Set the message icon (Android). - * - * @param string $value - * - * @return $this - */ - public function icon($value) - { - $this->icon = $value; - - return $this; - } - - /** - * Set the message badge (iOS). - * - * @param int $value - * - * @return $this - */ - public function badge($value) - { - $this->badge = (int) $value; - - return $this; - } - - /** - * @param string $key - * @param mixed $value - * - * @return $this - */ - public function setOption($key, $value) - { - $this->options[$key] = $value; - - return $this; - } - - /** - * Get an array representation of the message. - * - * @return array - */ - public function toArray() - { - return $this->platform === 'iOS' - ? $this->toiOS() - : $this->toAndroid(); - } - - /** - * Format the message for iOS. - * - * @return array - */ - public function toiOS() - { - $message = [ - 'apns' => [ - 'aps' => [ - 'alert' => [ - 'title' => $this->title, - 'body' => $this->body, - ], - 'sound' => $this->sound, - 'badge' => $this->badge, - ], - ], - ]; - - $this->formatMessage($message); - - return $message; - } - - /** - * Format the message for Android. - * Changed from GCM to FCM - * - * @return array - */ - public function toAndroid() - { - $message = [ - 'fcm' => [ - 'data' => [ - 'title' => $this->title, - 'body' => $this->body, - 'sound' => $this->sound, - 'icon' => $this->icon, - ], - ], - ]; - - $this->formatMessage($message); - - return $message; - } - - /** - * Return the current platform. - * - * @return string - */ - public function getPlatform() - { - return $this->platform; - } - - /** - * Format the final Payload. - * - * @param $message - */ - private function formatMessage(&$message) - { - if ($this->extraMessage) { - $message = array_merge($message, $this->extraMessage->toArray()); - } - - foreach ($this->options as $option => $value) { - Arr::set($message, $option, $value); - } - } +class PusherMessage { + /** + * The device platform (iOS/Android). + * + * @var string + */ + protected $platform = 'iOS'; + + /** + * The message title. + * + * @var string + */ + protected $title; + + /** + * The message body. + * + * @var string + */ + protected $body; + + /** + * The phone number the message should be sent from. + * + * @var string + */ + protected $sound = 'default'; + + /** + * The message icon (Android). + * + * @var string + */ + protected $icon; + + /** + * The number to display next to the push notification (iOS). + * + * @var int + */ + protected $badge; + + /** + * Extra options that will get added to the message. + * + * @var array + */ + protected $options = []; + + /** + * An extra message to the other platform. + * + * @var + */ + protected $extraMessage; + + /** + * @param string $body + * + * @return static + */ + public static function create($body = '') { + return new static($body); + } + + /** + * @param string $body + */ + public function __construct($body = '') { + $this->body = $body; + } + + /** + * Set the platform [iOS/Android]. + * + * @param string $platform + * + * @return $this + * + * @throws \NotificationChannels\PusherPushNotifications\Exceptions\CouldNotCreateMessage + */ + public function platform($platform) { + if (!in_array($platform, ['iOS', 'Android'])) { + throw CouldNotCreateMessage::invalidPlatformGiven($platform); + } + + $this->platform = $platform; + + return $this; + } + + /** + * Set the platform to iOS. + * + * @return $this + */ + public function iOS() { + $this->platform = 'iOS'; + + return $this; + } + + /** + * Set the platform to Android. + * + * @return $this + */ + public function android() { + $this->platform = 'Android'; + + return $this; + } + + /** + * Set an extra message to be sent to Android. + * + * @param \NotificationChannels\PusherPushNotifications\PusherMessage $message + * @return $this + */ + public function withAndroid(PusherMessage $message) { + $this->withExtra($message->android()); + + return $this; + } + + /** + * Set an extra message to be sent to iOS. + * + * @param \NotificationChannels\PusherPushNotifications\PusherMessage $message + * @return $this + */ + public function withiOS(PusherMessage $message) { + $this->withExtra($message->iOS()); + + return $this; + } + + /** + * Set an extra message to be sent to another platform. + * + * @param \NotificationChannels\PusherPushNotifications\PusherMessage $message + * @return void + */ + private function withExtra(PusherMessage $message) { + if ($message->getPlatform() == $this->platform) { + throw CouldNotCreateMessage::platformConflict($this->platform); + } + + $this->extraMessage = $message; + } + + /** + * Set the message title. + * + * @param string $value + * + * @return $this + */ + public function title($value) { + $this->title = $value; + + return $this; + } + + /** + * Set the message body. + * + * @param string $value + * + * @return $this + */ + public function body($value) { + $this->body = $value; + + return $this; + } + + /** + * Set the message sound (Android). + * + * @param string $value + * + * @return $this + */ + public function sound($value) { + $this->sound = $value; + + return $this; + } + + /** + * Set the message icon (Android). + * + * @param string $value + * + * @return $this + */ + public function icon($value) { + $this->icon = $value; + + return $this; + } + + /** + * Set the message badge (iOS). + * + * @param int $value + * + * @return $this + */ + public function badge($value) { + $this->badge = (int) $value; + + return $this; + } + + /** + * @param string $key + * @param mixed $value + * + * @return $this + */ + public function setOption($key, $value) { + $this->options[$key] = $value; + + return $this; + } + + /** + * Get an array representation of the message. + * + * @return array + */ + public function toArray() { + return $this->platform === 'iOS' + ? $this->toiOS() + : $this->toAndroid(); + } + + /** + * Format the message for iOS. + * + * @return array + */ + public function toiOS() { + $message = [ + 'apns' => [ + 'aps' => [ + 'alert' => [ + 'title' => $this->title, + 'body' => $this->body, + ], + 'sound' => $this->sound, + 'badge' => $this->badge, + ], + 'custom' => $this->options['custom'], + ], + ]; + + $this->formatMessage($message); + + return $message; + } + + /** + * Format the message for Android. + * Changed from GCM to FCM + * + * @return array + */ + public function toAndroid() { + $message = [ + 'fcm' => [ + 'data' => [ + 'title' => $this->title, + 'body' => $this->body, + 'sound' => $this->sound, + 'icon' => $this->icon, + 'custom' => $this->options['custom'], + ], + ], + ]; + + $this->formatMessage($message); + + return $message; + } + + /** + * Return the current platform. + * + * @return string + */ + public function getPlatform() { + return $this->platform; + } + + /** + * Format the final Payload. + * + * @param $message + */ + private function formatMessage(&$message) { + if ($this->extraMessage) { + $message = array_merge($message, $this->extraMessage->toArray()); + } + + foreach ($this->options as $option => $value) { + Arr::set($message, $option, $value); + } + } } From d63ad84ba2e197b4ae143095ca45580422b5ec8e Mon Sep 17 00:00:00 2001 From: Pesakitan22 Date: Mon, 20 Nov 2017 18:49:31 +0700 Subject: [PATCH 5/6] ios custom data --- src/PusherMessage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PusherMessage.php b/src/PusherMessage.php index 6ce02c1..ca5b2a0 100644 --- a/src/PusherMessage.php +++ b/src/PusherMessage.php @@ -261,7 +261,7 @@ public function toiOS() { 'sound' => $this->sound, 'badge' => $this->badge, ], - 'custom' => $this->options['custom'], + 'data' => $this->options['custom'], ], ]; From f3636d57a66ca76cd0752bd5d2e533dc8853eceb Mon Sep 17 00:00:00 2001 From: Deni Putra Date: Sat, 19 Oct 2019 22:34:05 +0700 Subject: [PATCH 6/6] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 795fa2a..9ad375d 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "pesakitan22/pusher-push-notifications", + "name": "dees040/pusher-push-notifications", "description": "Pusher native Push Notifications driver.", "keywords": [ "pusher-push-notifications",