]> git.mxchange.org Git - friendica-addons.git/commitdiff
Bluesky: Preparation to be able to fetch AT links
authorMichael <heluecht@pirati.ca>
Fri, 27 Dec 2024 10:26:20 +0000 (10:26 +0000)
committerTobias Diekershoff <tobias@noreply.git.friendi.ca>
Sat, 28 Dec 2024 21:23:22 +0000 (22:23 +0100)
bluesky/bluesky.php

index d6b7624babebd20d48d633cb8860783b457b5a40..1355f00024e706a8c463c06e60cd9605bfefbc93 100644 (file)
@@ -97,27 +97,25 @@ function bluesky_item_by_link(array &$hookData)
                return;
        }
 
-       $token = DI::atProtocol()->getUserToken($hookData['uid']);
-       if (empty($token)) {
-               return;
-       }
-
-       // @todo also support the URI format (at://did/app.bsky.feed.post/cid)
-       if (!preg_match('#^' . ATProtocol::WEB . '/profile/(.+)/post/(.+)#', $hookData['uri'], $matches)) {
-               return;
-       }
+       if (substr($hookData['uri'], 0, 5) != 'at://') {
+               if (!preg_match('#^' . ATProtocol::WEB . '/profile/(.+)/post/(.+)#', $hookData['uri'], $matches)) {
+                       return;
+               }
 
-       $did = DI::atProtocol()->getDid($matches[1]);
-       if (empty($did)) {
-               return;
+               $did = DI::atProtocol()->getDid($matches[1]);
+               if (empty($did)) {
+                       return;
+               }
+       
+               Logger::debug('Found bluesky post', ['uri' => $hookData['uri'], 'did' => $did, 'cid' => $matches[2]]);
+       
+               $uri = 'at://' . $did . '/app.bsky.feed.post/' . $matches[2];
+       } else {
+               $uri = $hookData['uri'];
        }
 
-       Logger::debug('Found bluesky post', ['url' => $hookData['uri'], 'did' => $did, 'cid' => $matches[2]]);
-
-       $uri = 'at://' . $did . '/app.bsky.feed.post/' . $matches[2];
-
        $uri = DI::atpProcessor()->fetchMissingPost($uri, $hookData['uid'], Item::PR_FETCHED, 0, 0);
-       Logger::debug('Got post', ['did' => $did, 'cid' => $matches[2], 'result' => $uri]);
+       Logger::debug('Got post', ['uri' => $uri]);
        if (!empty($uri)) {
                $item = Post::selectFirst(['id'], ['uri' => $uri, 'uid' => $hookData['uid']]);
                if (!empty($item['id'])) {