Skip to content

Commit

Permalink
Merge pull request #88 from utopia-php/fix-fcm-expiry
Browse files Browse the repository at this point in the history
Add index flag to map request to response order
  • Loading branch information
stnguyen90 authored Oct 22, 2024
2 parents b9dfafb + b59b2a3 commit f6790fb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/Utopia/Messaging/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ protected function request(
* @param array<string> $headers
* @param array<array<string, mixed>> $bodies
* @return array<array{
* index: int,
* url: string,
* statusCode: int,
* response: array<string, mixed>|null,
Expand Down Expand Up @@ -209,6 +210,7 @@ protected function requestMulti(
\curl_setopt($ch, CURLOPT_URL, $urls[$i]);
\curl_setopt($ch, CURLOPT_POSTFIELDS, $bodies[$i]);
\curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
\curl_setopt($ch, CURLOPT_PRIVATE, $i);
\curl_multi_add_handle($mh, \curl_copy_handle($ch));
}

Expand Down Expand Up @@ -236,6 +238,7 @@ protected function requestMulti(
}

$responses[] = [
'index' => (int)\curl_getinfo($ch, CURLINFO_PRIVATE),
'url' => \curl_getinfo($ch, CURLINFO_EFFECTIVE_URL),
'statusCode' => \curl_getinfo($ch, CURLINFO_RESPONSE_CODE),
'response' => $response,
Expand Down
6 changes: 3 additions & 3 deletions src/Utopia/Messaging/Adapter/Push/FCM.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,18 @@ protected function process(PushMessage $message): array

$response = new Response($this->getType());

foreach ($results as $index => $result) {
foreach ($results as $result) {
if ($result['statusCode'] === 200) {
$response->incrementDeliveredTo();
$response->addResult($message->getTo()[$index]);
$response->addResult($message->getTo()[$result['index']]);
} else {
$error =
($result['response']['error']['status'] ?? null) === 'UNREGISTERED'
|| ($result['response']['error']['status'] ?? null) === 'NOT_FOUND'
? $this->getExpiredErrorMessage()
: $result['response']['error']['message'] ?? 'Unknown error';

$response->addResult($message->getTo()[$index], $error);
$response->addResult($message->getTo()[$result['index']], $error);
}
}

Expand Down

0 comments on commit f6790fb

Please sign in to comment.