Skip to content

Commit f6790fb

Browse files
authored
Merge pull request #88 from utopia-php/fix-fcm-expiry
Add index flag to map request to response order
2 parents b9dfafb + b59b2a3 commit f6790fb

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/Utopia/Messaging/Adapter.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ protected function request(
136136
* @param array<string> $headers
137137
* @param array<array<string, mixed>> $bodies
138138
* @return array<array{
139+
* index: int,
139140
* url: string,
140141
* statusCode: int,
141142
* response: array<string, mixed>|null,
@@ -209,6 +210,7 @@ protected function requestMulti(
209210
\curl_setopt($ch, CURLOPT_URL, $urls[$i]);
210211
\curl_setopt($ch, CURLOPT_POSTFIELDS, $bodies[$i]);
211212
\curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
213+
\curl_setopt($ch, CURLOPT_PRIVATE, $i);
212214
\curl_multi_add_handle($mh, \curl_copy_handle($ch));
213215
}
214216

@@ -236,6 +238,7 @@ protected function requestMulti(
236238
}
237239

238240
$responses[] = [
241+
'index' => (int)\curl_getinfo($ch, CURLINFO_PRIVATE),
239242
'url' => \curl_getinfo($ch, CURLINFO_EFFECTIVE_URL),
240243
'statusCode' => \curl_getinfo($ch, CURLINFO_RESPONSE_CODE),
241244
'response' => $response,

src/Utopia/Messaging/Adapter/Push/FCM.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,18 +139,18 @@ protected function process(PushMessage $message): array
139139

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

142-
foreach ($results as $index => $result) {
142+
foreach ($results as $result) {
143143
if ($result['statusCode'] === 200) {
144144
$response->incrementDeliveredTo();
145-
$response->addResult($message->getTo()[$index]);
145+
$response->addResult($message->getTo()[$result['index']]);
146146
} else {
147147
$error =
148148
($result['response']['error']['status'] ?? null) === 'UNREGISTERED'
149149
|| ($result['response']['error']['status'] ?? null) === 'NOT_FOUND'
150150
? $this->getExpiredErrorMessage()
151151
: $result['response']['error']['message'] ?? 'Unknown error';
152152

153-
$response->addResult($message->getTo()[$index], $error);
153+
$response->addResult($message->getTo()[$result['index']], $error);
154154
}
155155
}
156156

0 commit comments

Comments
 (0)