use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
-use Friendica\Core\System;
use Friendica\Core\Worker;
use Friendica\Database\DBA;
use Friendica\DI;
return;
}
+ // Try to fetch the language from the post itself
+ if (!empty($item['language'])) {
+ $language = array_key_first(json_decode($item['language'], true));
+ } else {
+ $language = '';
+ }
+
$did = DI::pConfig()->get($uid, 'bluesky', 'did');
$urls = bluesky_get_urls(Post\Media::removeFromBody($item['body']));
$item['body'] = $urls['body'];
$record = [
'text' => $facets['body'],
+ '$type' => 'app.bsky.feed.post',
'createdAt' => DateTimeFormat::utcNow(DateTimeFormat::ATOM),
- '$type' => 'app.bsky.feed.post'
];
+ if (!empty($language)) {
+ $record['langs'] = [$language];
+ }
+
if (!empty($facets['facets'])) {
$record['facets'] = $facets['facets'];
}
}
foreach (array_reverse($data->feed) as $entry) {
- if (!Relay::isWantedLanguage($entry->post->record->text)) {
+ $contact = bluesky_get_contact($entry->post->author, 0, $uid);
+ $languages = $entry->post->record->langs ?? [];
+
+ if (!Relay::isWantedLanguage($entry->post->record->text, 0, $contact['id'] ?? 0, $languages)) {
Logger::debug('Unwanted language detected', ['text' => $entry->post->record->text]);
continue;
}
$id = bluesky_process_post($entry->post, $uid, Item::PR_TAG, 0);
if (!empty($id)) {
$post = Post::selectFirst(['uri-id'], ['id' => $id]);
- $stored = Post\Category::storeFileByURIId($post['uri-id'], $uid, Post\Category::SUBCRIPTION, $feedname, $feedurl);
- Logger::debug('Stored tag subscription for user', ['uri-id' => $post['uri-id'], 'uid' => $uid, 'name' => $feedname, 'url' => $feedurl, 'stored' => $stored]);
+ if (!empty($post['uri-id'])) {
+ $stored = Post\Category::storeFileByURIId($post['uri-id'], $uid, Post\Category::SUBCRIPTION, $feedname, $feedurl);
+ Logger::debug('Stored tag subscription for user', ['uri-id' => $post['uri-id'], 'uid' => $uid, 'name' => $feedname, 'url' => $feedurl, 'stored' => $stored]);
+ } else {
+ Logger::notice('Post not found', ['id' => $id, 'entry' => $entry]);
+ }
}
if (!empty($entry->reason)) {
bluesky_process_reason($entry->reason, bluesky_get_uri($entry->post), $uid);
{
$uri = bluesky_get_uri($post);
- if ($id = Post::selectFirst(['id'], ['uri' => $uri, 'uid' => $uid]) || $id = Post::selectFirst(['id'], ['extid' => $uri, 'uid' => $uid])) {
- return $id;
+ if ($id = Post::selectFirst(['id'], ['uri' => $uri, 'uid' => $uid])) {
+ return $id['id'];
+ }
+
+ if ($id = Post::selectFirst(['id'], ['extid' => $uri, 'uid' => $uid])) {
+ return $id['id'];
}
Logger::debug('Importing post', ['uid' => $uid, 'indexedAt' => $post->indexedAt, 'uri' => $post->uri, 'cid' => $post->cid, 'root' => $post->record->reply->root ?? '']);
$item['body'] = bluesky_get_text($record);
$item['created'] = DateTimeFormat::utc($record->createdAt, DateTimeFormat::MYSQL);
+ $item['transmitted-languages'] = $record->langs ?? [];
return $item;
}
function bluesky_get_text(stdClass $record): string
{
- $text = $record->text;
+ $text = $record->text ?? '';
if (empty($record->facets)) {
return $text;
$shared = bluesky_add_media($single, $shared, $fetch_uid, $level);
}
}
- $id = Item::insert($shared);
- $shared = Post::selectFirst(['uri-id'], ['id' => $id]);
+ Item::insert($shared);
}
}
- if (!empty($shared)) {
+ if (!empty($shared['uri-id'])) {
$item['quote-uri-id'] = $shared['uri-id'];
}
break;
$shared = bluesky_add_media($single, $shared, $fetch_uid, $level);
}
}
-
- $id = Item::insert($shared);
- $shared = Post::selectFirst(['uri-id'], ['id' => $id]);
+ Item::insert($shared);
}
}
- if (!empty($shared)) {
+ if (!empty($shared['uri-id'])) {
$item['quote-uri-id'] = $shared['uri-id'];
}
function bluesky_get_uri(stdClass $post): string
{
if (empty($post->cid)) {
- Logger::info('Invalid URI', ['post' => $post, 'callstack' => System::callstack(10, 0, true)]);
+ Logger::info('Invalid URI', ['post' => $post]);
return '';
}
return $post->uri . ':' . $post->cid;
return $fallback;
}
- Logger::debug('Reply count', ['replies' => $data->thread->post->replyCount, 'level' => $level, 'uid' => $uid, 'uri' => $uri]);
+ Logger::debug('Reply count', ['level' => $level, 'uid' => $uid, 'uri' => $uri]);
if ($causer != 0) {
$cdata = Contact::getPublicAndUserContactID($causer, $uid);
function bluesky_process_thread(stdClass $thread, int $uid, array $cdata, int $level): string
{
+ if (empty($thread->post)) {
+ Logger::info('Invalid post', ['post' => $thread]);
+ return '';
+ }
$uri = bluesky_get_uri($thread->post);
+
$fetched_uri = bluesky_fetch_post($uri, $uid);
if (empty($fetched_uri)) {
Logger::debug('Process missing post', ['uri' => $uri]);