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

add support for images #2

Merged
merged 1 commit into from
Aug 29, 2020
Merged
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
33 changes: 33 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,22 @@ public function setIcon($icon)
return $this;
}

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

return $this;
}

/**
* 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 +368,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