From bef4cd74aef6636f7bb8c5528d14bdfcc229bc6e Mon Sep 17 00:00:00 2001 From: Waterticket Date: Wed, 29 Dec 2021 04:27:03 +0000 Subject: [PATCH 1/3] =?UTF-8?q?FCM=20notification=20=ED=95=AD=EB=AA=A9=20?= =?UTF-8?q?=EB=A9=94=EC=86=8C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/framework/drivers/push/fcm.php | 24 +++++ common/framework/push.php | 138 ++++++++++++++++++++++++++ 2 files changed, 162 insertions(+) diff --git a/common/framework/drivers/push/fcm.php b/common/framework/drivers/push/fcm.php index 54b69c030..6e20a6598 100644 --- a/common/framework/drivers/push/fcm.php +++ b/common/framework/drivers/push/fcm.php @@ -66,6 +66,30 @@ class FCM extends Base implements \Rhymix\Framework\Drivers\PushInterface { $notification['click_action'] = $message->getClickAction(); } + if($message->getSound()) + { + $notification['sound'] = $message->getSound(); + } + if($message->getBadge()) + { + $notification['badge'] = $message->getBadge(); + } + if($message->getIcon()) + { + $notification['icon'] = $message->getIcon(); + } + if($message->getTag()) + { + $notification['tag'] = $message->getTag(); + } + if($message->getColor()) + { + $notification['color'] = $message->getColor(); + } + if($message->getAndroidChannelId()) + { + $notification['android_channel_id'] = $message->getAndroidChannelId(); + } $chunked_token = array_chunk($tokens, 1000); foreach($chunked_token as $token_unit) diff --git a/common/framework/push.php b/common/framework/push.php index 031536d4c..48b407263 100644 --- a/common/framework/push.php +++ b/common/framework/push.php @@ -15,6 +15,12 @@ class Push protected $subject = ''; protected $content = ''; protected $click_action = ''; + protected $sound = ''; + protected $badge = ''; + protected $icon = ''; + protected $tag = ''; + protected $color = ''; + protected $android_channel_id = ''; protected $data = []; protected $errors = array(); protected $success_tokens = array(); @@ -218,6 +224,138 @@ class Push { return $this->click_action; } + + /** + * Set a sound to associate with this push notification. + * + * @param string $sound + * @return bool + */ + public function setSound(string $sound): bool + { + $this->sound = utf8_trim(utf8_clean($sound)); + return true; + } + + /** + * Get the sound associated with this push notification. + * + * @return string + */ + public function getSound(): string + { + return $this->sound; + } + + /** + * Set a badge to associate with this push notification. + * + * @param string $badge + * @return bool + */ + public function setBadge(string $badge): bool + { + $this->badge = utf8_trim(utf8_clean($badge)); + return true; + } + + /** + * Get the badge associated with this push notification. + * + * @return string + */ + public function getBadge(): string + { + return $this->badge; + } + + /** + * Set an icon to associate with this push notification. + * + * @param string $icon + * @return bool + */ + public function setIcon(string $icon): bool + { + $this->icon = utf8_trim(utf8_clean($icon)); + return true; + } + + /** + * Get the icon associated with this push notification. + * + * @return string + */ + public function getIcon(): string + { + return $this->icon; + } + + /** + * Set a tag to associate with this push notification. + * + * @param string $tag + * @return bool + */ + public function setTag(string $tag): bool + { + $this->tag = utf8_trim(utf8_clean($tag)); + return true; + } + + /** + * Get the tag associated with this push notification. + * + * @return string + */ + public function getTag(): string + { + return $this->tag; + } + + /** + * Set a color to associate with this push notification. + * + * @param string $color + * @return bool + */ + public function setColor(string $color): bool + { + $this->color = utf8_trim(utf8_clean($color)); + return true; + } + + /** + * Get the color associated with this push notification. + * + * @return string + */ + public function getColor(): string + { + return $this->color; + } + + /** + * Set an android-channel-id to associate with this push notification. + * + * @param string $android_channel_id + * @return bool + */ + public function setAndroidChannelId(string $android_channel_id): bool + { + $this->android_channel_id = utf8_trim(utf8_clean($android_channel_id)); + return true; + } + + /** + * Get the android-channel-id associated with this push notification. + * + * @return string + */ + public function getAndroidChannelId(): string + { + return $this->android_channel_id; + } /** * Set a data to associate with this push notification. From f295f1a49da03746a77726ce9296f874cedb4824 Mon Sep 17 00:00:00 2001 From: Waterticket Date: Wed, 29 Dec 2021 05:48:04 +0000 Subject: [PATCH 2/3] =?UTF-8?q?notification=20=EB=A9=94=EC=86=8C=EB=93=9C?= =?UTF-8?q?=20=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/framework/drivers/push/fcm.php | 30 +-------- common/framework/push.php | 90 ++++----------------------- 2 files changed, 13 insertions(+), 107 deletions(-) diff --git a/common/framework/drivers/push/fcm.php b/common/framework/drivers/push/fcm.php index 6e20a6598..938c18358 100644 --- a/common/framework/drivers/push/fcm.php +++ b/common/framework/drivers/push/fcm.php @@ -59,37 +59,9 @@ class FCM extends Base implements \Rhymix\Framework\Drivers\PushInterface ); // Set notification - $notification = []; + $notification = $message->getNotifications() ?? []; $notification['title'] = $message->getSubject(); $notification['body'] = $message->getContent(); - if($message->getClickAction()) - { - $notification['click_action'] = $message->getClickAction(); - } - if($message->getSound()) - { - $notification['sound'] = $message->getSound(); - } - if($message->getBadge()) - { - $notification['badge'] = $message->getBadge(); - } - if($message->getIcon()) - { - $notification['icon'] = $message->getIcon(); - } - if($message->getTag()) - { - $notification['tag'] = $message->getTag(); - } - if($message->getColor()) - { - $notification['color'] = $message->getColor(); - } - if($message->getAndroidChannelId()) - { - $notification['android_channel_id'] = $message->getAndroidChannelId(); - } $chunked_token = array_chunk($tokens, 1000); foreach($chunked_token as $token_unit) diff --git a/common/framework/push.php b/common/framework/push.php index 48b407263..12268f820 100644 --- a/common/framework/push.php +++ b/common/framework/push.php @@ -14,13 +14,7 @@ class Push protected $to = array(); protected $subject = ''; protected $content = ''; - protected $click_action = ''; - protected $sound = ''; - protected $badge = ''; - protected $icon = ''; - protected $tag = ''; - protected $color = ''; - protected $android_channel_id = ''; + protected $notification = []; protected $data = []; protected $errors = array(); protected $success_tokens = array(); @@ -211,20 +205,10 @@ class Push */ public function setClickAction(string $click_action): bool { - $this->click_action = utf8_trim(utf8_clean($click_action)); + $this->notification['click_action'] = utf8_trim(utf8_clean($click_action)); return true; } - /** - * Get the click-action associated with this push notification. - * - * @return string - */ - public function getClickAction(): string - { - return $this->click_action; - } - /** * Set a sound to associate with this push notification. * @@ -233,20 +217,10 @@ class Push */ public function setSound(string $sound): bool { - $this->sound = utf8_trim(utf8_clean($sound)); + $this->notification['sound'] = utf8_trim(utf8_clean($sound)); return true; } - /** - * Get the sound associated with this push notification. - * - * @return string - */ - public function getSound(): string - { - return $this->sound; - } - /** * Set a badge to associate with this push notification. * @@ -255,19 +229,9 @@ class Push */ public function setBadge(string $badge): bool { - $this->badge = utf8_trim(utf8_clean($badge)); + $this->notification['badge'] = utf8_trim(utf8_clean($badge)); return true; } - - /** - * Get the badge associated with this push notification. - * - * @return string - */ - public function getBadge(): string - { - return $this->badge; - } /** * Set an icon to associate with this push notification. @@ -277,19 +241,9 @@ class Push */ public function setIcon(string $icon): bool { - $this->icon = utf8_trim(utf8_clean($icon)); + $this->notification['icon'] = utf8_trim(utf8_clean($icon)); return true; } - - /** - * Get the icon associated with this push notification. - * - * @return string - */ - public function getIcon(): string - { - return $this->icon; - } /** * Set a tag to associate with this push notification. @@ -299,20 +253,10 @@ class Push */ public function setTag(string $tag): bool { - $this->tag = utf8_trim(utf8_clean($tag)); + $this->notification['tag'] = utf8_trim(utf8_clean($tag)); return true; } - /** - * Get the tag associated with this push notification. - * - * @return string - */ - public function getTag(): string - { - return $this->tag; - } - /** * Set a color to associate with this push notification. * @@ -321,20 +265,10 @@ class Push */ public function setColor(string $color): bool { - $this->color = utf8_trim(utf8_clean($color)); + $this->notification['color'] = utf8_trim(utf8_clean($color)); return true; } - /** - * Get the color associated with this push notification. - * - * @return string - */ - public function getColor(): string - { - return $this->color; - } - /** * Set an android-channel-id to associate with this push notification. * @@ -343,18 +277,18 @@ class Push */ public function setAndroidChannelId(string $android_channel_id): bool { - $this->android_channel_id = utf8_trim(utf8_clean($android_channel_id)); + $this->notification['android_channel_id'] = utf8_trim(utf8_clean($android_channel_id)); return true; } /** - * Get the android-channel-id associated with this push notification. + * Get notification array * - * @return string + * @return array */ - public function getAndroidChannelId(): string + public function getNotifications(): array { - return $this->android_channel_id; + return $this->notification; } /** From 6e7a058671d2a29c5afb0c5a49bf606ab80ccc84 Mon Sep 17 00:00:00 2001 From: Waterticket Date: Wed, 29 Dec 2021 06:10:12 +0000 Subject: [PATCH 3/3] =?UTF-8?q?getClickAction=20=EC=9E=AC=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/framework/push.php | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/common/framework/push.php b/common/framework/push.php index 12268f820..5ff836593 100644 --- a/common/framework/push.php +++ b/common/framework/push.php @@ -14,7 +14,7 @@ class Push protected $to = array(); protected $subject = ''; protected $content = ''; - protected $notification = []; + protected $metadata = []; protected $data = []; protected $errors = array(); protected $success_tokens = array(); @@ -205,9 +205,19 @@ class Push */ public function setClickAction(string $click_action): bool { - $this->notification['click_action'] = utf8_trim(utf8_clean($click_action)); + $this->metadata['click_action'] = utf8_trim(utf8_clean($click_action)); return true; } + + /** + * Get the click-action associated with this push notification. + * + * @return string + */ + public function getClickAction(): string + { + return $this->metadata['click_action']; + } /** * Set a sound to associate with this push notification. @@ -217,7 +227,7 @@ class Push */ public function setSound(string $sound): bool { - $this->notification['sound'] = utf8_trim(utf8_clean($sound)); + $this->metadata['sound'] = utf8_trim(utf8_clean($sound)); return true; } @@ -229,7 +239,7 @@ class Push */ public function setBadge(string $badge): bool { - $this->notification['badge'] = utf8_trim(utf8_clean($badge)); + $this->metadata['badge'] = utf8_trim(utf8_clean($badge)); return true; } @@ -241,7 +251,7 @@ class Push */ public function setIcon(string $icon): bool { - $this->notification['icon'] = utf8_trim(utf8_clean($icon)); + $this->metadata['icon'] = utf8_trim(utf8_clean($icon)); return true; } @@ -253,7 +263,7 @@ class Push */ public function setTag(string $tag): bool { - $this->notification['tag'] = utf8_trim(utf8_clean($tag)); + $this->metadata['tag'] = utf8_trim(utf8_clean($tag)); return true; } @@ -265,7 +275,7 @@ class Push */ public function setColor(string $color): bool { - $this->notification['color'] = utf8_trim(utf8_clean($color)); + $this->metadata['color'] = utf8_trim(utf8_clean($color)); return true; } @@ -277,7 +287,7 @@ class Push */ public function setAndroidChannelId(string $android_channel_id): bool { - $this->notification['android_channel_id'] = utf8_trim(utf8_clean($android_channel_id)); + $this->metadata['android_channel_id'] = utf8_trim(utf8_clean($android_channel_id)); return true; } @@ -288,7 +298,7 @@ class Push */ public function getNotifications(): array { - return $this->notification; + return $this->metadata; } /**