Skip to content

Commit 8b1ba00

Browse files
authored
Add support for custom feeds in posts (#4413)
1 parent 230edf6 commit 8b1ba00

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

bridges/BlueskyBridge.php

+33
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,10 @@ public function collectData()
255255
$description .= '<a href="' . $uri_reconstructed . '">Quoted post detached.</a>';
256256
} elseif (isset($quotedRecord['blocked']) && $quotedRecord['blocked']) { //blocked by quote author
257257
$description .= 'Author of quoted post has blocked OP.';
258+
} elseif (($quotedRecord['$type'] ?? '') === 'app.bsky.feed.defs#generatorView') {
259+
$description .= '</p>';
260+
$description .= $this->getGeneratorViewDescription($quotedRecord);
261+
$description .= '<p>';
258262
} else {
259263
$quotedAuthorDid = $quotedRecord['author']['did'];
260264
$quotedDisplayName = $quotedRecord['author']['displayName'] ?? '';
@@ -399,6 +403,10 @@ public function collectData()
399403
$description .= '<a href="' . $uri_reconstructed . '">Quoted post detached.</a>';
400404
} elseif (isset($replyQuotedRecord['blocked']) && $replyQuotedRecord['blocked']) { //blocked by quote author
401405
$description .= 'Author of quoted post has blocked OP.';
406+
} elseif (($replyQuotedRecord['$type'] ?? '') === 'app.bsky.feed.defs#generatorView') {
407+
$description .= '</p>';
408+
$description .= $this->getGeneratorViewDescription($replyQuotedRecord);
409+
$description .= '<p>';
402410
} else {
403411
$quotedAuthorDid = $replyQuotedRecord['author']['did'];
404412
$quotedDisplayName = $replyQuotedRecord['author']['displayName'] ?? '';
@@ -584,4 +592,29 @@ private function getAuthorFeed($did, $filter)
584592
$response = json_decode(getContents($uri), true);
585593
return $response;
586594
}
595+
596+
private function getGeneratorViewDescription(array $record): string
597+
{
598+
$avatar = e($record['avatar']);
599+
$displayName = e($record['displayName']);
600+
$displayHandle = e($record['creator']['handle']);
601+
$likeCount = e($record['likeCount']);
602+
preg_match('/\/([^\/]+)$/', $record['uri'], $matches);
603+
$uri = e('https://bsky.app/profile/' . $record['creator']['did'] . '/feed/' . $matches[1]);
604+
605+
return <<<END
606+
<a href="{$uri}" style="color: inherit;">
607+
<div style="border: 1px solid #333; padding: 10px;">
608+
<div style="display: flex; margin-bottom: 10px;">
609+
<img src="{$avatar}" height="50" width="50" style="margin-right: 10px;">
610+
<div style="display: flex; flex-direction: column; justify-content: center;">
611+
<h3>{$displayName}</h3>
612+
<span>Feed by @{$displayHandle}</span>
613+
</div>
614+
</div>
615+
<span>Liked by {$likeCount} users</span>
616+
</div>
617+
</a>
618+
END;
619+
}
587620
}

0 commit comments

Comments
 (0)