From 8b1ba003a8e46bda757e3fad8971d182d5dcca79 Mon Sep 17 00:00:00 2001 From: burrow335 <190633847+burrow335@users.noreply.github.com> Date: Sat, 25 Jan 2025 18:46:12 +0100 Subject: [PATCH] Add support for custom feeds in posts (#4413) --- bridges/BlueskyBridge.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/bridges/BlueskyBridge.php b/bridges/BlueskyBridge.php index 89e5f3bc..67bb5af9 100644 --- a/bridges/BlueskyBridge.php +++ b/bridges/BlueskyBridge.php @@ -255,6 +255,10 @@ class BlueskyBridge extends BridgeAbstract $description .= 'Quoted post detached.'; } 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 .= '

'; + $description .= $this->getGeneratorViewDescription($quotedRecord); + $description .= '

'; } else { $quotedAuthorDid = $quotedRecord['author']['did']; $quotedDisplayName = $quotedRecord['author']['displayName'] ?? ''; @@ -399,6 +403,10 @@ class BlueskyBridge extends BridgeAbstract $description .= 'Quoted post detached.'; } 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 .= '

'; + $description .= $this->getGeneratorViewDescription($replyQuotedRecord); + $description .= '

'; } else { $quotedAuthorDid = $replyQuotedRecord['author']['did']; $quotedDisplayName = $replyQuotedRecord['author']['displayName'] ?? ''; @@ -584,4 +592,29 @@ class BlueskyBridge extends BridgeAbstract $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 << +

+
+ +
+

{$displayName}

+ Feed by @{$displayHandle} +
+
+ Liked by {$likeCount} users +
+ +END; + } }