From b343131cbbc995dfb0eeb2d0e39e929513d0bdae Mon Sep 17 00:00:00 2001 From: Dwight Watson Date: Fri, 1 Mar 2024 14:24:55 +1100 Subject: [PATCH] Add message priority enum --- src/ApnAdapter.php | 8 ++++---- src/ApnMessage.php | 25 +++++-------------------- src/ApnMessagePriority.php | 9 +++++++++ 3 files changed, 18 insertions(+), 24 deletions(-) create mode 100644 src/ApnMessagePriority.php diff --git a/src/ApnAdapter.php b/src/ApnAdapter.php index aaf65dd..c7a5e3f 100644 --- a/src/ApnAdapter.php +++ b/src/ApnAdapter.php @@ -107,12 +107,12 @@ public function adapt(ApnMessage $message, string $token): Notification $notification->setId($apnsId); } - if ($message->priority === ApnMessage::PRIORITY_HIGH) { - $notification->setHighPriority(); + if ($message->priority === ApnMessagePriority::Low) { + $notification->setLowPriority(); } - if ($message->priority === ApnMessage::PRIORITY_LOW) { - $notification->setLowPriority(); + if ($message->priority === ApnMessagePriority::High) { + $notification->setHighPriority(); } return $notification; diff --git a/src/ApnMessage.php b/src/ApnMessage.php index 9166030..a90fdc0 100644 --- a/src/ApnMessage.php +++ b/src/ApnMessage.php @@ -7,9 +7,6 @@ class ApnMessage { - const PRIORITY_HIGH = 10; - const PRIORITY_LOW = 5; - /** * The background push type. * @@ -119,9 +116,9 @@ class ApnMessage public ?string $apnsId = null; /** - * The priority of the notification. 10 - immediate. 5 - power considerations. + * The message priority. */ - public ?int $priority = null; + public ?ApnMessagePriority $priority = null; /** * Message specific client. @@ -290,23 +287,11 @@ public function apnsId(?string $apnsId): self } /** - * Set high priority. - */ - public function setHighPriority(): self - { - $this->priority = self::PRIORITY_HIGH; - - return $this; - } - - /** - * Set low priority. - * - * @return Notification + * Set the message priority. */ - public function setLowPriority(): self + public function priority(ApnMessagePriority $priority): self { - $this->priority = self::PRIORITY_LOW; + $this->priority = $priority; return $this; } diff --git a/src/ApnMessagePriority.php b/src/ApnMessagePriority.php new file mode 100644 index 0000000..30a57b3 --- /dev/null +++ b/src/ApnMessagePriority.php @@ -0,0 +1,9 @@ +