Skip to content

Commit

Permalink
Merge pull request #34 from kutia-software-company/1.x
Browse files Browse the repository at this point in the history
Merge 1.x to Master
  • Loading branch information
gentritabazi committed Jan 10, 2022
2 parents c9b7fc3 + 158fe43 commit b0a5ea3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
4 changes: 4 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ class MyController
->withIcon('https://seeklogo.com/images/F/firebase-logo-402F407EE0-seeklogo.com.png')
->withClickAction('admin/notifications')
->withPriority('high')
->withAdditionalData([
'routing_key' => 'some_screen',
'routing_value' => 42
])
->sendNotification($this->deviceTokens);

// Or
Expand Down
13 changes: 12 additions & 1 deletion src/Messages/FirebaseMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class FirebaseMessage
const PRIORITY_NORMAL = 'normal';

private $title;

private $body;

private $clickAction;
Expand All @@ -18,6 +18,8 @@ class FirebaseMessage

private $icon;

private $additionalData;

private $priority = self::PRIORITY_NORMAL;

private $fromArray;
Expand Down Expand Up @@ -57,6 +59,13 @@ public function withIcon($icon)
return $this;
}

public function withAdditionalData($additionalData)
{
$this->additionalData = $additionalData;

return $this;
}

public function withPriority($priority)
{
$this->priority = $priority;
Expand All @@ -83,6 +92,7 @@ public function asNotification($deviceTokens)
->withImage($this->image)
->withIcon($this->icon)
->withPriority($this->priority)
->withAdditionalData($this->additionalData)
->sendNotification($deviceTokens);
}

Expand All @@ -98,6 +108,7 @@ public function asMessage($deviceTokens)
->withImage($this->image)
->withIcon($this->icon)
->withPriority($this->priority)
->withAdditionalData($this->additionalData)
->sendMessage($deviceTokens);
}
}
30 changes: 21 additions & 9 deletions src/Services/Larafirebase.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Larafirebase
const PRIORITY_NORMAL = 'normal';

private $title;

private $body;

private $clickAction;
Expand All @@ -19,6 +19,8 @@ class Larafirebase

private $icon;

private $additionalData;

private $priority = self::PRIORITY_NORMAL;

private $fromArray;
Expand Down Expand Up @@ -69,6 +71,13 @@ public function withPriority($priority)
return $this;
}

public function withAdditionalData($additionalData)
{
$this->additionalData = $additionalData;

return $this;
}

public function fromArray($fromArray)
{
$this->fromArray = $fromArray;
Expand All @@ -94,25 +103,28 @@ public function sendNotification($tokens)
'icon' => $this->icon,
'click_action' => $this->clickAction
],
'data' => $this->additionalData,
'priority' => $this->priority
);

return $this->callApi($fields);
}

public function sendMessage($tokens)
{
$data = ($this->fromArray) ? $this->fromArray : [
'title' => $this->title,
'body' => $this->body,
'image' => $this->image,
'icon' => $this->icon
];

$data = $this->additionalData ? array_merge($data, $this->additionalData) : $data;

$fields = array(
'registration_ids' => $this->validateToken($tokens),
'data' => ($this->fromArray) ? $this->fromArray : [
'title' => $this->title,
'body' => $this->body,
'image' => $this->image,
'icon' => $this->icon
],
'data' => $data,
'priority' => $this->priority
);

return $this->callApi($fields);
}

Expand Down

0 comments on commit b0a5ea3

Please sign in to comment.