diff --git a/bridges/BlueskyBridge.php b/bridges/BlueskyBridge.php index 67bb5af9..f0e609d9 100644 --- a/bridges/BlueskyBridge.php +++ b/bridges/BlueskyBridge.php @@ -180,7 +180,7 @@ class BlueskyBridge extends BridgeAbstract if (Debug::isEnabled()) { $url = explode('/', $post['post']['uri']); - error_log('https://bsky.app/profile/' . $url[2] . '/post/' . $url[4]); + $this->logger->debug('https://bsky.app/profile/' . $url[2] . '/post/' . $url[4]); } $description = ''; @@ -255,10 +255,16 @@ 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 .= ''; + } elseif ( + ($quotedRecord['$type'] ?? '') === 'app.bsky.feed.defs#generatorView' || + ($quotedRecord['$type'] ?? '') === 'app.bsky.graph.defs#listView' + ) { + $description .= $this->getListFeedDescription($quotedRecord); + } elseif ( + ($quotedRecord['$type'] ?? '') === 'app.bsky.graph.starterpack' || + ($quotedRecord['$type'] ?? '') === 'app.bsky.graph.defs#starterPackViewBasic' + ) { + $description .= $this->getStarterPackDescription($post['post']['embed']['record']); } else { $quotedAuthorDid = $quotedRecord['author']['did']; $quotedDisplayName = $quotedRecord['author']['displayName'] ?? ''; @@ -403,10 +409,16 @@ 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 .= '';
+ } elseif (
+ ($replyQuotedRecord['$type'] ?? '') === 'app.bsky.feed.defs#generatorView' ||
+ ($replyQuotedRecord['$type'] ?? '') === 'app.bsky.graph.defs#listView'
+ ) {
+ $description .= $this->getListFeedDescription($replyQuotedRecord);
+ } elseif (
+ ($replyQuotedRecord['$type'] ?? '') === 'app.bsky.graph.starterpack' ||
+ ($replyQuotedRecord['$type'] ?? '') === 'app.bsky.graph.defs#starterPackViewBasic'
+ ) {
+ $description .= $this->getStarterPackDescription($replyPost['embed']['record']);
} else {
$quotedAuthorDid = $replyQuotedRecord['author']['did'];
$quotedDisplayName = $replyQuotedRecord['author']['displayName'] ?? '';
@@ -554,11 +566,19 @@ class BlueskyBridge extends BridgeAbstract
}
$title .= ', replying to ' . $replyAuthor;
}
- if (isset($post['post']['embed']) && isset($post['post']['embed']['record'])) {
+
+ if (
+ isset($post['post']['embed']) &&
+ isset($post['post']['embed']['record']) &&
+ //if not starter pack, feed or list
+ ($post['post']['embed']['record']['$type'] ?? '') !== 'app.bsky.feed.defs#generatorView' &&
+ ($post['post']['embed']['record']['$type'] ?? '') !== 'app.bsky.graph.defs#listView' &&
+ ($post['post']['embed']['record']['$type'] ?? '') !== 'app.bsky.graph.defs#starterPackViewBasic'
+ ) {
if (isset($post['post']['embed']['record']['blocked'])) {
$quotedAuthor = 'blocked user';
} elseif (isset($post['post']['embed']['record']['notFound'])) {
- $quotedAuthor = 'deleted post';
+ $quotedAuthor = 'deleted psost';
} elseif (isset($post['post']['embed']['record']['detached'])) {
$quotedAuthor = 'detached post';
} else {
@@ -587,34 +607,64 @@ class BlueskyBridge extends BridgeAbstract
{
$uri = 'https://public.api.bsky.app/xrpc/app.bsky.feed.getAuthorFeed?actor=' . urlencode($did) . '&filter=' . urlencode($filter) . '&limit=30';
if (Debug::isEnabled()) {
- error_log($uri);
+ $this->logger->debug($uri);
}
$response = json_decode(getContents($uri), true);
return $response;
}
- private function getGeneratorViewDescription(array $record): string
+ //Embed for generated feeds and lists
+ private function getListFeedDescription(array $record): string
{
- $avatar = e($record['avatar']);
- $displayName = e($record['displayName']);
- $displayHandle = e($record['creator']['handle']);
- $likeCount = e($record['likeCount']);
+ $feedViewAvatar = isset($record['avatar']) ? '' : '';
+ $feedViewName = e($record['displayName'] ?? $record['name']);
+ $feedViewDescription = e($record['description'] ?? '');
+ $authorDisplayName = e($record['creator']['displayName']);
+ $authorHandle = e($record['creator']['handle']);
+ $likeCount = isset($record['likeCount']) ? '
Liked by ' . e($record['likeCount']) . ' users' : '';
preg_match('/\/([^\/]+)$/', $record['uri'], $matches);
- $uri = e('https://bsky.app/profile/' . $record['creator']['did'] . '/feed/' . $matches[1]);
+ if (($record['purpose'] ?? '') === 'app.bsky.graph.defs#modlist') {
+ $typeURL = '/lists/';
+ $typeDesc = 'moderation list';
+ } elseif (($record['purpose'] ?? '') === 'app.bsky.graph.defs#curatelist') {
+ $typeURL = '/lists/';
+ $typeDesc = 'list';
+ } else {
+ $typeURL = '/feed/';
+ $typeDesc = 'feed';
+ }
+ $uri = e('https://bsky.app/profile/' . $record['creator']['did'] . $typeURL . $matches[1]);
return <<
-
{$displayName}
- Feed by @{$displayHandle}
-
+{$feedViewName}
+END;
+ }
+
+ private function getStarterPackDescription(array $record): string
+ {
+ if (!isset($record['record'])) {
+ return 'Failed to get starter pack information.';
+ }
+ $starterpackRecord = $record['record'];
+ $starterpackName = e($starterpackRecord['name']);
+ $starterpackDescription = e($starterpackRecord['description']);
+ $creatorDisplayName = e($record['creator']['displayName']);
+ $creatorHandle = e($record['creator']['handle']);
+ preg_match('/\/([^\/]+)$/', $starterpackRecord['list'], $matches);
+ $uri = e('https://bsky.app/starter-pack/' . $record['creator']['did'] . '/' . $matches[1]);
+ return <<
+Bluesky {$typeDesc} by {$authorDisplayName} @{$authorHandle}
+
+Bluesky starter pack by {$creatorDisplayName} @{$creatorHandle}
+{$starterpackDescription}
+
END;
}
}