diff --git a/bridges/BlueskyBridge.php b/bridges/BlueskyBridge.php index ada24128..6dd49bde 100644 --- a/bridges/BlueskyBridge.php +++ b/bridges/BlueskyBridge.php @@ -173,7 +173,7 @@ class BlueskyBridge extends BridgeAbstract $item['author'] = $this->fallbackAuthor($post['post']['author'], 'display'); $postAuthorDID = $post['post']['author']['did']; - $postAuthorHandle = $post['post']['author']['handle'] !== 'handle.invalid' ? '@' . $post['post']['author']['handle'] . ' ' : ''; + $postAuthorHandle = $post['post']['author']['handle'] !== 'handle.invalid' ? '@' . $post['post']['author']['handle'] . '' : ''; $postDisplayName = $post['post']['author']['displayName'] ?? ''; $postDisplayName = e($postDisplayName); $postUri = $item['uri']; @@ -340,7 +340,7 @@ class BlueskyBridge extends BridgeAbstract } else { $replyPostRecord = $replyPost['record']; $replyPostAuthorDID = $replyPost['author']['did']; - $replyPostAuthorHandle = $replyPost['author']['handle'] !== 'handle.invalid' ? '@' . $replyPost['author']['handle'] . ' ' : ''; + $replyPostAuthorHandle = $replyPost['author']['handle'] !== 'handle.invalid' ? '@' . $replyPost['author']['handle'] . '' : ''; $replyPostDisplayName = $replyPost['author']['displayName'] ?? ''; $replyPostDisplayName = e($replyPostDisplayName); $replyPostUri = self::URI . '/profile/' . $this->fallbackAuthor($replyPost['author'], 'url') . '/post/' . explode('app.bsky.feed.post/', $replyPost['uri'])[1]; @@ -528,8 +528,9 @@ class BlueskyBridge extends BridgeAbstract $postType = isset($postRecord['reply']) ? 'reply' : 'post'; $description .= "Replying to $postDisplayName $postAuthorHandle's $postType:
"; } else { - // aaa @aaa.com posted: - $description .= "$postDisplayName $postAuthorHandle posted:
"; + // aaa @aaa.com posted/replied: + $postType = isset($postRecord['reply']) ? 'replied' : 'posted'; + $description .= "$postDisplayName $postAuthorHandle $postType:
"; } $description .= $this->textToDescription($postRecord); return $description; @@ -555,9 +556,19 @@ class BlueskyBridge extends BridgeAbstract //use "Post by A, replying to B, quoting C" instead of post contents $title = ''; if (isset($post['reason']) && str_contains($post['reason']['$type'], 'reasonRepost')) { - $title .= 'Repost by ' . $this->fallbackAuthor($post['reason']['by'], 'display') . ', post by ' . $this->fallbackAuthor($post['post']['author'], 'display'); + $title .= 'Repost by ' . $this->fallbackAuthor($post['reason']['by'], 'display'); + if (isset($post['reply'])) { + $title .= ', reply by '; + } else { + $title .= ', post by '; + } + $title .= $this->fallbackAuthor($post['post']['author'], 'display'); } else { - $title .= 'Post by ' . $this->fallbackAuthor($post['post']['author'], 'display'); + if (isset($post['reply'])) { + $title .= 'Reply by ' . $this->fallbackAuthor($post['post']['author'], 'display'); + } else { + $title .= 'Post by ' . $this->fallbackAuthor($post['post']['author'], 'display'); + } } if (isset($post['reply'])) { @@ -595,15 +606,21 @@ class BlueskyBridge extends BridgeAbstract private function resolveHandle($handle) { - $uri = 'https://public.api.bsky.app/xrpc/com.atproto.identity.resolveHandle?handle=' . urlencode($handle); - $response = json_decode(getContents($uri), true); + $url = 'https://public.api.bsky.app/xrpc/com.atproto.identity.resolveHandle?handle=' . urlencode($handle); + $response = $this->loadCacheValue($url) ?? json_decode(getContents($url), true); + if (isset($response['did'])) { + $this->saveCacheValue($url, $response, 604800); + } return $response['did']; } private function getProfile($did) { - $uri = 'https://public.api.bsky.app/xrpc/app.bsky.actor.getProfile?actor=' . urlencode($did); - $response = json_decode(getContents($uri), true); + $url = 'https://public.api.bsky.app/xrpc/app.bsky.actor.getProfile?actor=' . urlencode($did); + $response = $this->loadCacheValue($url) ?? json_decode(getContents($url), true); + if ($response['did'] === $did ?? false) { + $this->saveCacheValue($url, $response); + } return $response; }