Skip to content

Commit

Permalink
Add index flag to map request to response order
Browse files Browse the repository at this point in the history
  • Loading branch information
abnegate committed Oct 21, 2024
1 parent b9dfafb commit de46d1b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/Utopia/Messaging/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,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 +237,7 @@ protected function requestMulti(
}

$responses[] = [
'index' => \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 de46d1b

Please sign in to comment.