Compare commits

..

7 commits

2 changed files with 26 additions and 24 deletions

View file

@ -38,6 +38,7 @@ use Friendica\Core\Worker;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\Conversation;
use Friendica\Model\GServer; use Friendica\Model\GServer;
use Friendica\Model\Item; use Friendica\Model\Item;
use Friendica\Model\ItemURI; use Friendica\Model\ItemURI;
@ -139,7 +140,7 @@ function bluesky_probe_detect(array &$hookData)
return; return;
} }
} elseif (Network::isValidHttpUrl($hookData['uri'])) { } elseif (Network::isValidHttpUrl($hookData['uri'])) {
$did = bluesky_get_did_by_profile($hookData['uri']); $did = bluesky_get_did_by_profile($hookData['uri'], $pconfig['uid']);
if (empty($did)) { if (empty($did)) {
return; return;
} }
@ -181,21 +182,21 @@ function bluesky_item_by_link(array &$hookData)
return; return;
} }
$did = bluesky_get_did_by_profile($hookData['uri']); if (!preg_match('#^' . BLUESKY_WEB . '/profile/(.+)/post/(.+)#', $hookData['uri'], $matches)) {
return;
}
$did = bluesky_get_did($matches[1], $hookData['uid']);
if (empty($did)) { if (empty($did)) {
return; return;
} }
if (!preg_match('#/profile/.+/post/(.+)#', $hookData['uri'], $matches)) { Logger::debug('Found bluesky post', ['url' => $hookData['uri'], 'did' => $did, 'cid' => $matches[2]]);
return;
}
Logger::debug('Found bluesky post', ['url' => $hookData['uri'], 'did' => $did, 'cid' => $matches[1]]); $uri = 'at://' . $did . '/app.bsky.feed.post/' . $matches[2];
$uri = 'at://' . $did . '/app.bsky.feed.post/' . $matches[1];
$uri = bluesky_fetch_missing_post($uri, $hookData['uid'], $hookData['uid'], Item::PR_FETCHED, 0, 0, 0); $uri = bluesky_fetch_missing_post($uri, $hookData['uid'], $hookData['uid'], Item::PR_FETCHED, 0, 0, 0);
Logger::debug('Got post', ['did' => $did, 'cid' => $matches[1], 'result' => $uri]); Logger::debug('Got post', ['did' => $did, 'cid' => $matches[2], 'result' => $uri]);
if (!empty($uri)) { if (!empty($uri)) {
$item = Post::selectFirst(['id'], ['uri' => $uri, 'uid' => $hookData['uid']]); $item = Post::selectFirst(['id'], ['uri' => $uri, 'uid' => $hookData['uid']]);
if (!empty($item['id'])) { if (!empty($item['id'])) {
@ -278,14 +279,12 @@ function bluesky_block(array &$hook_data)
return; return;
} }
Logger::debug('Check if contact is bluesky', ['data' => $hook_data]); if ($hook_data['contact']['network'] != Protocol::BLUESKY) {
$contact = DBA::selectFirst('contact', [], ['network' => Protocol::BLUESKY, 'url' => $hook_data['url'], 'uid' => [0, $hook_data['uid']]]);
if (empty($contact)) {
return; return;
} }
$record = [ $record = [
'subject' => $contact['url'], 'subject' => $hook_data['contact']['url'],
'createdAt' => DateTimeFormat::utcNow(DateTimeFormat::ATOM), 'createdAt' => DateTimeFormat::utcNow(DateTimeFormat::ATOM),
'$type' => 'app.bsky.graph.block' '$type' => 'app.bsky.graph.block'
]; ];
@ -1060,6 +1059,7 @@ function bluesky_process_reason(stdClass $reason, string $uri, int $uid)
$item = [ $item = [
'network' => Protocol::BLUESKY, 'network' => Protocol::BLUESKY,
'protocol' => Conversation::PARCEL_CONNECTOR,
'uid' => $uid, 'uid' => $uid,
'wall' => false, 'wall' => false,
'uri' => $reason->by->did . '/app.bsky.feed.repost/' . $reason->indexedAt, 'uri' => $reason->by->did . '/app.bsky.feed.repost/' . $reason->indexedAt,
@ -1259,6 +1259,7 @@ function bluesky_get_header(stdClass $post, string $uri, int $uid, int $fetch_ui
$contact = bluesky_get_contact($post->author, $uid, $fetch_uid); $contact = bluesky_get_contact($post->author, $uid, $fetch_uid);
$item = [ $item = [
'network' => Protocol::BLUESKY, 'network' => Protocol::BLUESKY,
'protocol' => Conversation::PARCEL_CONNECTOR,
'uid' => $uid, 'uid' => $uid,
'wall' => false, 'wall' => false,
'uri' => $uri, 'uri' => $uri,
@ -1297,6 +1298,7 @@ function bluesky_get_header(stdClass $post, string $uri, int $uid, int $fetch_ui
// When "ver" is set to "1" it was flagged by some automated process. // When "ver" is set to "1" it was flagged by some automated process.
if (empty($label->ver)) { if (empty($label->ver)) {
$item['sensitive'] = true; $item['sensitive'] = true;
$item['content-warning'] = $label->val ?? '';
Logger::debug('Sensitive content', ['uri-id' => $item['uri-id'], 'label' => $label]); Logger::debug('Sensitive content', ['uri-id' => $item['uri-id'], 'label' => $label]);
} }
} }
@ -1460,8 +1462,8 @@ function bluesky_add_media(stdClass $embed, array $item, int $fetch_uid, int $le
'url' => $embed->playlist, 'url' => $embed->playlist,
'preview' => $embed->thumbnail, 'preview' => $embed->thumbnail,
'description' => $embed->alt ?? '', 'description' => $embed->alt ?? '',
'height' => $embed->aspectRatio->height, 'height' => $embed->aspectRatio->height ?? null,
'width' => $embed->aspectRatio->width, 'width' => $embed->aspectRatio->width ?? null,
]; ];
Post\Media::insert($media); Post\Media::insert($media);
break; break;
@ -1832,8 +1834,14 @@ function bluesky_get_preferences(int $uid): ?stdClass
return $data; return $data;
} }
function bluesky_get_did_by_profile(string $url): string function bluesky_get_did_by_profile(string $url, int $uid): string
{ {
if (preg_match('#^' . BLUESKY_WEB . '/profile/(.+)#', $url, $matches)) {
$did = bluesky_get_did($matches[1], $uid);
if (!empty($did)) {
return $did;
}
}
try { try {
$curlResult = DI::httpClient()->get($url, HttpClientAccept::HTML, [HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]); $curlResult = DI::httpClient()->get($url, HttpClientAccept::HTML, [HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]);
} catch (\Throwable $th) { } catch (\Throwable $th) {
@ -1942,13 +1950,6 @@ function bluesky_get_did(string $handle, int $uid): string
return $did; return $did;
} }
// The profile page can contain hints to the DID as well
$did = bluesky_get_did_by_profile('https://' . $handle);
if ($did != '') {
Logger::debug('Got DID by profile page', ['handle' => $handle, 'did' => $did]);
return $did;
}
// And finally we use the default PDS from Bluesky. // And finally we use the default PDS from Bluesky.
$data = bluesky_get(BLUESKY_PDS . '/xrpc/com.atproto.identity.resolveHandle?handle=' . urlencode($handle)); $data = bluesky_get(BLUESKY_PDS . '/xrpc/com.atproto.identity.resolveHandle?handle=' . urlencode($handle));
if (!empty($data) && !empty($data->did)) { if (!empty($data) && !empty($data->did)) {

View file

@ -22,6 +22,7 @@ use Friendica\Core\Worker;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\Conversation;
use Friendica\Model\Item; use Friendica\Model\Item;
use Friendica\Model\Photo; use Friendica\Model\Photo;
use Friendica\Model\Post; use Friendica\Model\Post;
@ -31,7 +32,6 @@ use Friendica\Network\HTTPClient\Client\HttpClientAccept;
use Friendica\Network\HTTPClient\Client\HttpClientOptions; use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Protocol\Activity; use Friendica\Protocol\Activity;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
use Friendica\Util\Strings; use Friendica\Util\Strings;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Exception\RequestException;
@ -850,6 +850,7 @@ function tumblr_get_header(stdClass $post, string $uri, int $uid): array
$contact = tumblr_get_contact($post->blog, $uid); $contact = tumblr_get_contact($post->blog, $uid);
$item = [ $item = [
'network' => Protocol::TUMBLR, 'network' => Protocol::TUMBLR,
'protocol' => Conversation::PARCEL_CONNECTOR,
'uid' => $uid, 'uid' => $uid,
'wall' => false, 'wall' => false,
'uri' => $uri, 'uri' => $uri,