Skip to content

Commit

Permalink
General: Allow broadcast to be sent with empty endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
brianstoop authored and pprkut committed Dec 6, 2024
1 parent ede4d86 commit e7ea585
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Lunr/Vortex/PushNotificationDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function dispatch(array $endpoints, array $payloads): void

foreach ($payloads as $platform => $platform_payloads)
{
if (!isset($grouped_endpoints[$platform]))
if (!isset($grouped_endpoints[$platform]) && array_filter($platform_payloads, fn($payload) => $payload->is_broadcast()) === [])
{
continue;
}
Expand All @@ -104,18 +104,20 @@ public function dispatch(array $endpoints, array $payloads): void

foreach ($platform_payloads as $payload_type => $payload)
{
if (!isset($grouped_endpoints[$platform][$payload_type]))
if (!isset($grouped_endpoints[$platform][$payload_type]) && $payload->is_broadcast() === FALSE)
{
continue;
}

$endpoints = $grouped_endpoints[$platform][$payload_type] ?? [];

if ($this->dispatchers[$platform] instanceof PushNotificationMultiDispatcherInterface)
{
$this->dispatch_multiple($platform, $grouped_endpoints[$platform][$payload_type], $payload);
$this->dispatch_multiple($platform, $endpoints, $payload);
}
else
{
$this->dispatch_single($platform, $grouped_endpoints[$platform][$payload_type], $payload);
$this->dispatch_single($platform, $endpoints, $payload);
}
}
}
Expand Down
37 changes: 37 additions & 0 deletions src/Lunr/Vortex/Tests/PushNotificationDispatcherDispatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,43 @@ public function testDispatchMultiCastWithDeferredResponse(): void
$this->assertPropertySame('statuses', $expected_statuses);
}

/**
* Test dispatch send correct broadcast payload.
*
* @covers Lunr\Vortex\PushNotificationDispatcher::dispatch
*/
public function testDispatchSendsCorrectBroadcastPayload(): void
{
$dispatchers = [
'apns' => $this->apns,
'fcm' => $this->fcm,
'email' => $this->email,
];
$this->set_reflection_property_value('dispatchers', $dispatchers);

$data_payload = $this->getMockBuilder(FCMPayload::class)
->disableOriginalConstructor()
->getMock();

$payloads = [
'fcm' => [ 'data' => $data_payload ],
];

$data_payload->expects($this->exactly(2))
->method('is_broadcast')
->willReturn(TRUE);

$this->fcm->expects($this->once())
->method('push')
->with($data_payload, [])
->willReturn($this->fcm_response);

$this->fcm_response->expects($this->never())
->method('get_status');

$this->class->dispatch([], $payloads);
}

}

?>

0 comments on commit e7ea585

Please sign in to comment.