Skip to content

Commit

Permalink
Add support for custom feeds in posts (#4413)
Browse files Browse the repository at this point in the history
  • Loading branch information
burrow335 authored Jan 25, 2025
1 parent 230edf6 commit 8b1ba00
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions bridges/BlueskyBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ public function collectData()
$description .= '<a href="' . $uri_reconstructed . '">Quoted post detached.</a>';
} elseif (isset($quotedRecord['blocked']) && $quotedRecord['blocked']) { //blocked by quote author
$description .= 'Author of quoted post has blocked OP.';
} elseif (($quotedRecord['$type'] ?? '') === 'app.bsky.feed.defs#generatorView') {
$description .= '</p>';
$description .= $this->getGeneratorViewDescription($quotedRecord);
$description .= '<p>';
} else {
$quotedAuthorDid = $quotedRecord['author']['did'];
$quotedDisplayName = $quotedRecord['author']['displayName'] ?? '';
Expand Down Expand Up @@ -399,6 +403,10 @@ public function collectData()
$description .= '<a href="' . $uri_reconstructed . '">Quoted post detached.</a>';
} elseif (isset($replyQuotedRecord['blocked']) && $replyQuotedRecord['blocked']) { //blocked by quote author
$description .= 'Author of quoted post has blocked OP.';
} elseif (($replyQuotedRecord['$type'] ?? '') === 'app.bsky.feed.defs#generatorView') {
$description .= '</p>';
$description .= $this->getGeneratorViewDescription($replyQuotedRecord);
$description .= '<p>';
} else {
$quotedAuthorDid = $replyQuotedRecord['author']['did'];
$quotedDisplayName = $replyQuotedRecord['author']['displayName'] ?? '';
Expand Down Expand Up @@ -584,4 +592,29 @@ private function getAuthorFeed($did, $filter)
$response = json_decode(getContents($uri), true);
return $response;
}

private function getGeneratorViewDescription(array $record): string
{
$avatar = e($record['avatar']);
$displayName = e($record['displayName']);
$displayHandle = e($record['creator']['handle']);
$likeCount = e($record['likeCount']);
preg_match('/\/([^\/]+)$/', $record['uri'], $matches);
$uri = e('https://bsky.app/profile/' . $record['creator']['did'] . '/feed/' . $matches[1]);

return <<<END
<a href="{$uri}" style="color: inherit;">
<div style="border: 1px solid #333; padding: 10px;">
<div style="display: flex; margin-bottom: 10px;">
<img src="{$avatar}" height="50" width="50" style="margin-right: 10px;">
<div style="display: flex; flex-direction: column; justify-content: center;">
<h3>{$displayName}</h3>
<span>Feed by @{$displayHandle}</span>
</div>
</div>
<span>Liked by {$likeCount} users</span>
</div>
</a>
END;
}
}

0 comments on commit 8b1ba00

Please sign in to comment.