diff --git a/CHANGELOG.md b/CHANGELOG.md index 4119825..7f9f830 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## [2.0.0](https://github.com/ankurk91/laravel-bundler/compare/1.5.1..2.0.0) + +* Require `kreait/firebase-php@^7.5` due to [Discontinued FCM Messaging API](https://github.com/kreait/firebase-php/issues/804) + ## [1.5.1](https://github.com/ankurk91/laravel-bundler/compare/1.5.0..1.5.1) * Add support for Laravel 10 diff --git a/composer.json b/composer.json index a18c0dd..1e202e4 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,8 @@ "illuminate/events": "^9.34 || ^10.0", "illuminate/notifications": "^9.34 || ^10.0", "illuminate/support": "^9.34 || ^10.0", - "kreait/laravel-firebase": "^5.0" + "kreait/firebase-php": "^7.5", + "kreait/laravel-firebase": "^5.2" }, "require-dev": { "orchestra/testbench": "^7.10 || ^8.0", diff --git a/src/FCMChannel.php b/src/FCMChannel.php index 4e0959d..f74d8ff 100644 --- a/src/FCMChannel.php +++ b/src/FCMChannel.php @@ -8,13 +8,11 @@ use Illuminate\Notifications\Notification; use Illuminate\Support\Arr; use Illuminate\Support\Str; -use Kreait\Firebase\Contract\Messaging; use Kreait\Firebase\Contract\Messaging as MessagingClient; use Kreait\Firebase\Exception\FirebaseException; use Kreait\Firebase\Exception\Messaging\NotFound; use Kreait\Firebase\Exception\MessagingException; use Kreait\Firebase\Messaging\CloudMessage; -use Kreait\Firebase\Messaging\Http\Request\SendMessageToTokens; use Kreait\Firebase\Messaging\MessageTarget; use Kreait\Laravel\Firebase\Facades\Firebase; use NotificationChannels\FCM\Exception\HttpException; @@ -24,8 +22,6 @@ class FCMChannel { - protected const BATCH_MESSAGE_LIMIT = Messaging::BATCH_MESSAGE_LIMIT; - public function __construct(protected Dispatcher $events) { // @@ -36,11 +32,11 @@ public function __construct(protected Dispatcher $events) * * @param mixed $notifiable * @param Notification $notification - * @return array + * @return array|null|\Kreait\Firebase\Messaging\MulticastSendReport * * @throws FirebaseException */ - public function send($notifiable, Notification $notification): array + public function send($notifiable, Notification $notification) { // Build the target [$targetType, $targetValue] = $this->getTarget($notifiable, $notification); @@ -50,7 +46,7 @@ public function send($notifiable, Notification $notification): array // Check if there is a target, otherwise return an empty array if (empty($targetValue)) { - return []; + return null; } // Make the messaging client @@ -60,23 +56,14 @@ public function send($notifiable, Notification $notification): array try { // Send multicast if ($this->canSendToMulticast($targetType, $targetValue)) { - $chunkedTokens = array_chunk($targetValue, self::BATCH_MESSAGE_LIMIT); - - $responses = []; - foreach ($chunkedTokens as $chunkedToken) { - $responses[] = $client->sendMulticast($message, $chunkedToken); - } - - return $responses; + return $client->sendMulticast($message, $targetValue); } // Set the target and type; since we are sure that target is single $message = $message->withChangedTarget($targetType, Arr::first($targetValue)); // Send to single target - return [ - $client->send($message) - ]; + return $client->send($message); } catch (NotFound $exception) { $this->emitFailedEvent($notifiable, $notification, $exception); diff --git a/tests/FCMChannelTest.php b/tests/FCMChannelTest.php index 40c58fd..5e7dac0 100644 --- a/tests/FCMChannelTest.php +++ b/tests/FCMChannelTest.php @@ -5,7 +5,6 @@ use Closure; use Illuminate\Contracts\Events\Dispatcher; -use Illuminate\Support\Arr; use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Notification; use Kreait\Firebase\Contract\Messaging as MessagingClient; @@ -86,8 +85,7 @@ public function a_message_can_be_send_to_a_target() $response = $this->channel->send(new TestModel, new TestNotification); $this->assertIsArray($response); - $this->assertIsArray(Arr::first($response)); - $this->assertArrayHasKey('response-key', Arr::first($response)); + $this->assertArrayHasKey('response-key', $response); } /** @test */ @@ -109,8 +107,7 @@ public function a_message_can_be_send_to_a_topic() $response = $this->channel->send(new TestModel(MessageTarget::TOPIC), new TestNotification); $this->assertIsArray($response); - $this->assertIsArray(Arr::first($response)); - $this->assertArrayHasKey('response-key', Arr::first($response)); + $this->assertArrayHasKey('response-key', $response); } /** @test */ @@ -126,14 +123,13 @@ public function a_message_can_be_send_to_a_condition() ], $this->getPropertyValue($message, 'notification')->jsonSerialize()); return true; - })->andReturn(['response-key' => 2]); + })->andReturn(['response-key' => 3]); }); $response = $this->channel->send(new TestModel(MessageTarget::CONDITION), new TestNotification); $this->assertIsArray($response); - $this->assertIsArray(Arr::first($response)); - $this->assertArrayHasKey('response-key', Arr::first($response)); + $this->assertArrayHasKey('response-key', $response); } /** @test */ @@ -152,8 +148,7 @@ public function a_message_can_be_send_to_multicast() $response = $this->channel->send(new TestModel(MessageTarget::TOKEN, true), new TestNotification); - $this->assertIsArray($response); - $this->assertInstanceOf(MulticastSendReport::class, Arr::first($response)); + $this->assertInstanceOf(MulticastSendReport::class, $response); } /** @test */ @@ -189,8 +184,7 @@ public function nothing_is_sent_when_no_token_is_supplied() { $response = $this->channel->send(new TestModel(null), new TestNotification); - $this->assertIsArray($response); - $this->assertEmpty($response); + $this->assertNull($response); } /** @test */ @@ -206,7 +200,7 @@ public function it_supports_anonymous_notifiable() ], $this->getPropertyValue($message, 'notification')->jsonSerialize()); return true; - })->andReturn(['response-key' => 1]); + })->andReturn(['response-key' => 5]); }); Event::fake();