Skip to content
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
4 changes: 2 additions & 2 deletions src/OneSignalMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

use Illuminate\Support\Arr;
use NotificationChannels\OneSignal\Traits\{
Categories\AppearanceHelpers, Categories\AttachmentHelpers, Categories\ButtonHelpers, Categories\DeliveryHelpers, Categories\GroupingHelpers, Deprecated
Categories\AppearanceHelpers, Categories\AttachmentHelpers, Categories\ButtonHelpers, Categories\DeliveryHelpers, Categories\GroupingHelpers, Categories\SilentHelpers, Deprecated
};


class OneSignalMessage
{

use AppearanceHelpers, AttachmentHelpers, ButtonHelpers, DeliveryHelpers, GroupingHelpers, Deprecated;
use AppearanceHelpers, AttachmentHelpers, ButtonHelpers, DeliveryHelpers, GroupingHelpers, SilentHelpers, Deprecated;

/** @var array */
protected $payload = [];
Expand Down
18 changes: 18 additions & 0 deletions src/Traits/Categories/SilentHelpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace NotificationChannels\OneSignal\Traits\Categories;
use Illuminate\Support\Arr;

trait SilentHelpers
{
/**
* Enables silent mode
*
* @return $this
*/
public function setSilent()
{
Arr::forget($this->payload, 'contents'); //removes any contents that are set by constructor.
return $this->setParameter('content_available', 1);
}
}
19 changes: 19 additions & 0 deletions tests/ChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,23 @@ public function it_sends_nothing_and_returns_null_when_player_id_empty()
$channel_response = $this->channel->send(new EmptyNotifiable(), new TestNotification());
$this->assertNull($channel_response);
}

public function it_can_send_a_silent_notification()
{
$response = new Response(200);

$this->oneSignal->shouldReceive('sendNotificationCustom')
->once()
->with([
'content_available' => 1,
'data.action' => 'reload',
'data.target' => 'inbox',
'include_player_ids' => collect('player_id'),
])
->andReturn($response);

$channel_response = $this->channel->send(new Notifiable(), new TestSilentNotification());

$this->assertInstanceOf(ResponseInterface::class, $channel_response);
}
}
17 changes: 17 additions & 0 deletions tests/TestSilentNotification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace NotificationChannels\OneSignal\Test;

use Illuminate\Notifications\Notification;
use NotificationChannels\OneSignal\OneSignalMessage;

class TestSilentNotification extends Notification
{
public function toOneSignal($notifiable)
{
return (new OneSignalMessage())
->setSilent()
->setData('action', 'reload')
->setData('target', 'inbox');
}
}