Skip to content

Commit

Permalink
Add message priority enum
Browse files Browse the repository at this point in the history
  • Loading branch information
dwightwatson committed Mar 1, 2024
1 parent 3b2007a commit b343131
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 24 deletions.
8 changes: 4 additions & 4 deletions src/ApnAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
25 changes: 5 additions & 20 deletions src/ApnMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@

class ApnMessage
{
const PRIORITY_HIGH = 10;
const PRIORITY_LOW = 5;

/**
* The background push type.
*
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}
Expand Down
9 changes: 9 additions & 0 deletions src/ApnMessagePriority.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace NotificationChannels\Apn;

enum ApnMessagePriority
{
case Low;
case High;
}

0 comments on commit b343131

Please sign in to comment.