8000 bug #59742 [Notifier] [BlueSky] Change the value returned as the mess… · symfonyaml/symfony@6262b65 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6262b65

Browse files
bug symfony#59742 [Notifier] [BlueSky] Change the value returned as the message ID (javiereguiluz)
This PR was squashed before being merged into the 7.2 branch. Discussion ---------- [Notifier] [BlueSky] Change the value returned as the message ID | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | symfony#59739 | License | MIT Some BlueSky API actions require both the `cid` and the `uri` (see https://docs.bsky.app/docs/tutorials/like-repost) so we might re-add the `cid` to SentMessage's `info` in Symfony 7.3. Commits ------- 4121f68 [Notifier] [BlueSky] Change the value returned as the message ID
2 parents 7c709de + 4121f68 commit 6262b65

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

src/Symfony/Component/Notifier/Bridge/Bluesky/BlueskyTransport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ protected function doSend(MessageInterface $message): SentMessage
105105
if (200 === $statusCode) {
106106
$content = $response->toArray();
107107
$sentMessage = new SentMessage($message, (string) $this);
108-
$sentMessage->setMessageId($content['cid']);
108+
$sentMessage->setMessageId($content['uri']);
109109

110110
return $sentMessage;
111111
}

src/Symfony/Component/Notifier/Bridge/Bluesky/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
---
66

77
* Add option to attach a media
8+
* [BC Break] Change the returned message ID from record's 'cid' to 'uri'
89

910
7.1
1011
---

src/Symfony/Component/Notifier/Bridge/Bluesky/Tests/BlueskyTransportTest.php

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,11 @@ public function testParseFacetsUrlWithTrickyRegex()
276276

277277
public function testWithMedia()
278278
{
279-
$transport = $this->createTransport(new MockHttpClient((function () {
279+
// realistic sample values taken from https://docs.bsky.app/docs/advanced-guides/posts#post-record-structure
280+
$recordUri = 'at://did:plc:u5cwb2mwiv2bfq53cjufe6yn/app.bsky.feed.post/3k4duaz5vfs2b';
281+
$recordCid = 'bafyreibjifzpqj6o6wcq3hejh7y4z4z2vmiklkvykc57tw3pcbx3kxifpm';
282+
283+
$transport = $this->createTransport(new MockHttpClient((function () use ($recordUri, $recordCid) {
280284
yield function (string $method, string $url, array $options) {
281285
$this->assertSame('POST', $method);
282286
$this->assertSame('https://bsky.social/xrpc/com.atproto.server.createSession', $url);
@@ -299,21 +303,40 @@ public function testWithMedia()
299303
]]);
300304
};
301305

302-
yield function (string $method, string $url, array $options) {
306+
yield function (string $method, string $url, array $options) use ($recordUri, $recordCid) {
303307
$this->assertSame('POST', $method);
304308
$this->assertSame('https://bsky.social/xrpc/com.atproto.repo.createRecord', $url);
305309
$this->assertArrayHasKey('authorization', $options['normalized_headers']);
306310
$this->assertSame('{"repo":null,"collection":"app.bsky.feed.post","record":{"$type":"app.bsky.feed.post","text":"Hello World!","createdAt":"2024-04-28T08:40:17.000000Z","embed":{"$type":"app.bsky.embed.images","images":[{"alt":"A fixture","image":{"$type":"blob","ref":{"$link":"bafkreibabalobzn6cd366ukcsjycp4yymjymgfxcv6xczmlgpemzkz3cfa"},"mimeType":"image\/png","size":760898}}]}}}', $options['body']);
307311

308-
return new JsonMockResponse(['cid' => '103254962155278888']);
312+
return new JsonMockResponse(['uri' => $recordUri, 'cid' => $recordCid]);
309313
};
310314
})()));
311315

312316
$options = (new BlueskyOptions())
313317
->attachMedia(new File(__DIR__.'/fixtures.gif'), 'A fixture');
314318
$result = $transport->send(new ChatMessage('Hello World!', $options));
315319

316-
$this->assertSame('103254962155278888', $result->getMessageId());
320+
$this->assertSame($recordUri, $result->getMessageId());
321+
}
322+
323+
public function testReturnedMessageId()
324+
{
325+
// realistic sample values taken from https://docs.bsky.app/docs/advanced-guides/posts#post-record-structure
326+
$recordUri = 'at://did:plc:u5cwb2mwiv2bfq53cjufe6yn/app.bsky.feed.post/3k4duaz5vfs2b';
327+
$recordCid = 'bafyreibjifzpqj6o6wcq3hejh7y4z4z2vmiklkvykc57tw3pcbx3kxifpm';
328+
329+
$client = new MockHttpClient(function () use ($recordUri, $recordCid) {
330+
return new JsonMockResponse([
331+
'uri' => $recordUri,
332+
'cid' => $recordCid,
333+
]);
334+
});
335+
336+
$transport = self::createTransport($client);
337+
$message = $transport->send(new ChatMessage('Hello!'));
338+
339+
$this->assertSame($recordUri, $message->getMessageId());
317340
}
318341

319342
/**

0 commit comments

Comments
 (0)
0