Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Add image support on notification fixes #166 #171

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Message/PayloadNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ class PayloadNotification implements Arrayable
*/
protected $icon;

/**
* @internal
*
* @var null|string
*/
protected $image;

/**
* @internal
*
Expand Down Expand Up @@ -111,6 +118,7 @@ public function __construct(PayloadNotificationBuilder $builder)
$this->body = $builder->getBody();
$this->channelId = $builder->getChannelId();
$this->icon = $builder->getIcon();
$this->image = $builder->getImage();
$this->sound = $builder->getSound();
$this->badge = $builder->getBadge();
$this->tag = $builder->getTag();
Expand All @@ -134,6 +142,7 @@ public function toArray()
'body' => $this->body,
'android_channel_id' => $this->channelId,
'icon' => $this->icon,
'image' => $this->image,
'sound' => $this->sound,
'badge' => $this->badge,
'tag' => $this->tag,
Expand Down
32 changes: 32 additions & 0 deletions src/Message/PayloadNotificationBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ class PayloadNotificationBuilder
*/
protected $icon;

/**
* @internal
*
* @var null|string
*/
protected $image;

/**
* @internal
*
Expand Down Expand Up @@ -170,6 +177,21 @@ public function setIcon($icon)
return $this;
}

/**
* Indicates the image that can be displayed in the notification
* Supports an url or internal image.
*
* @param $image
*
* @return string|null
*/
public function setImage($image)
{
$this->image = $image;

return $this->image;
}

/**
* Indicates a sound to play when the device receives a notification.
* Supports default or the filename of a sound resource bundled in the app.
Expand Down Expand Up @@ -345,6 +367,16 @@ public function getIcon()
return $this->icon;
}

/**
* Get Image.
*
* @return string|null
*/
public function getImage()
{
return $this->image;
}

/**
* Get Sound.
*
Expand Down
12 changes: 8 additions & 4 deletions tests/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ public function it_construct_a_valid_json_with_notification()
"title":"test_title",
"body":"test_body",
"badge":"test_badge",
"sound":"test_sound"
"sound":"test_sound",
"image":"test_image"
}';

$targetFull = '{
Expand All @@ -101,15 +102,17 @@ public function it_construct_a_valid_json_with_notification()
"body_loc_args":"[ body0, body1 ]",
"title_loc_key":"test_title_key",
"title_loc_args":"[ title0, title1 ]",
"icon":"test_icon"
"icon":"test_icon",
"image":"test_image"
}';

$notificationBuilder = new PayloadNotificationBuilder();

$notificationBuilder->setTitle('test_title')
->setBody('test_body')
->setSound('test_sound')
->setBadge('test_badge');
->setBadge('test_badge')
->setImage('test_image');

$json = json_encode($notificationBuilder->build()->toArray());
$this->assertJsonStringEqualsJsonString($targetPartial, $json);
Expand All @@ -123,7 +126,8 @@ public function it_construct_a_valid_json_with_notification()
->setBodyLocationArgs('[ body0, body1 ]')
->setTitleLocationKey('test_title_key')
->setTitleLocationArgs('[ title0, title1 ]')
->setIcon('test_icon');
->setIcon('test_icon')
->setImage('test_image');

$json = json_encode($notificationBuilder->build()->toArray());
$this->assertJsonStringEqualsJsonString($targetFull, $json);
Expand Down