Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(config): makes the push notifications per request limit configurable #26

Merged
merged 1 commit into from
Mar 6, 2024
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ You must publish the configuration file with:
php artisan vendor:publish --provider="YieldStudio\LaravelExpoNotifier\ExpoNotificationsServiceProvider" --tag="expo-notifications-config" --tag="expo-notifications-migration"
```

### Available environment variables
- `EXPO_PUSH_NOTIFICATIONS_PER_REQUEST_LIMIT` : sets the max notifications sent on a bulk request. [The official documentation says the limit should be 100](https://docs.expo.dev/push-notifications/sending-notifications/#request-errors) but in fact it's failing. You can tweak it by setting a value under 100.

## Usage

### Send notification
Expand Down
4 changes: 4 additions & 0 deletions config/expo-notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@
'service' => [
'api_url' => 'https://exp.host/--/api/v2/push',
'host' => 'exp.host',
'limits' => [
// https://docs.expo.dev/push-notifications/sending-notifications/#request-errors
'push_notifications_per_request' => (int) env('EXPO_PUSH_NOTIFICATIONS_PER_REQUEST_LIMIT', 99),
],
],
];
8 changes: 5 additions & 3 deletions src/ExpoNotificationsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

final class ExpoNotificationsService implements ExpoNotificationsServiceInterface
{
public const PUSH_NOTIFICATIONS_PER_REQUEST_LIMIT = 100;

public const SEND_NOTIFICATION_ENDPOINT = '/send';

private PendingRequest $http;
Expand All @@ -35,12 +33,16 @@ final class ExpoNotificationsService implements ExpoNotificationsServiceInterfac

private Collection $tickets;

private int $pushNotificationsPerRequestLimit;

public function __construct(
string $apiUrl,
string $host,
protected readonly ExpoPendingNotificationStorageInterface $notificationStorage,
protected readonly ExpoTicketStorageInterface $ticketStorage
) {
$this->pushNotificationsPerRequestLimit = config('expo-notifications.service.limits.push_notifications_per_request');

$this->http = Http::withHeaders([
'host' => $host,
'accept' => 'application/json',
Expand Down Expand Up @@ -148,7 +150,7 @@ private function prepareNotificationsToSendNow(): ExpoNotificationsService
->values();

// Splits into multiples chunks of max limitation
$this->notificationChunks = $this->notificationsToSend->chunk(self::PUSH_NOTIFICATIONS_PER_REQUEST_LIMIT);
$this->notificationChunks = $this->notificationsToSend->chunk($this->pushNotificationsPerRequestLimit);

return $this;
}
Expand Down
Loading