Merge pull request #11947 from annando/ap-quote

Support for quoted links is added
This commit is contained in:
Hypolite Petovan 2022-09-29 12:20:46 -04:00 committed by GitHub
commit 1edcd65e0e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 63 additions and 1 deletions

View file

@ -848,6 +848,10 @@ class Processor
} }
$item['content-warning'] = HTML::toBBCode($activity['summary'] ?? ''); $item['content-warning'] = HTML::toBBCode($activity['summary'] ?? '');
$item['raw-body'] = $item['body'] = $content; $item['raw-body'] = $item['body'] = $content;
if (!empty($activity['quote-url'])) {
$item['body'] .= self::addSharedData($activity['quote-url']);
}
} }
self::storeFromBody($item); self::storeFromBody($item);
@ -866,6 +870,40 @@ class Processor
return $item; return $item;
} }
/**
* Add a share block for the given quote link
*
* @param string $url
* @return string
*/
private static function addSharedData(string $url): string
{
$id = Item::fetchByLink($url);
if (empty($id)) {
return '';
}
$shared_item = Post::selectFirst(['author-name', 'author-link', 'author-avatar', 'plink', 'created', 'guid', 'title', 'body'], ['id' => $id]);
if (!DBA::isResult($shared_item)) {
return '';
}
$prefix = BBCode::getShareOpeningTag(
$shared_item['author-name'],
$shared_item['author-link'],
$shared_item['author-avatar'],
$shared_item['plink'],
$shared_item['created'],
$shared_item['guid']
);
if (!empty($shared_item['title'])) {
$prefix .= '[h3]' . $shared_item['title'] . "[/h3]\n";
}
return $prefix . $shared_item['body'] . '[/share]';
}
/** /**
* Store hashtags and mentions * Store hashtags and mentions
* *

View file

@ -1916,6 +1916,24 @@ class Receiver
$object_data['attachments'] = array_merge($object_data['attachments'], self::processAttachmentUrls($object['as:url'] ?? [])); $object_data['attachments'] = array_merge($object_data['attachments'], self::processAttachmentUrls($object['as:url'] ?? []));
} }
// Support for quoted posts (Pleroma, Fedibird and Misskey)
$object_data['quote-url'] = JsonLD::fetchElement($object, 'as:quoteUrl', '@value');
if (empty($object_data['quote-url'])) {
$object_data['quote-url'] = JsonLD::fetchElement($object, 'fedibird:quoteUri', '@value');
}
if (empty($object_data['quote-url'])) {
$object_data['quote-url'] = JsonLD::fetchElement($object, 'misskey:_misskey_quote', '@value');
}
// Misskey adds some data to the standard "content" value for quoted posts for backwards compatibility.
// Their own "_misskey_content" value does then contain the content without this extra data.
if (!empty($object_data['quote-url'])) {
$misskey_content = JsonLD::fetchElement($object, 'misskey:_misskey_content', '@value');
if (!empty($misskey_content)) {
$object_data['content'] = $misskey_content;
}
}
// For page types we expect that the alternate url posts to some page. // For page types we expect that the alternate url posts to some page.
// So we add this to the attachments if it differs from the id. // So we add this to the attachments if it differs from the id.
// Currently only Lemmy is using the page type. // Currently only Lemmy is using the page type.

View file

@ -157,6 +157,8 @@ class JsonLD
'sc' => (object)['@id' => 'http://schema.org#', '@type' => '@id'], 'sc' => (object)['@id' => 'http://schema.org#', '@type' => '@id'],
'pt' => (object)['@id' => 'https://joinpeertube.org/ns#', '@type' => '@id'], 'pt' => (object)['@id' => 'https://joinpeertube.org/ns#', '@type' => '@id'],
'mobilizon' => (object)['@id' => 'https://joinmobilizon.org/ns#', '@type' => '@id'], 'mobilizon' => (object)['@id' => 'https://joinmobilizon.org/ns#', '@type' => '@id'],
'fedibird' => (object)['@id' => 'http://fedibird.com/ns#', '@type' => '@id'],
'misskey' => (object)['@id' => 'https://misskey-hub.net/ns#', '@type' => '@id'],
]; ];
$orig_json = $json; $orig_json = $json;

View file

@ -17,6 +17,7 @@
"ostatus": "http://ostatus.org#", "ostatus": "http://ostatus.org#",
"schema": "http://schema.org#", "schema": "http://schema.org#",
"toot": "http://joinmastodon.org/ns#", "toot": "http://joinmastodon.org/ns#",
"fedibird": "http://fedibird.com/ns#",
"value": "schema:value", "value": "schema:value",
"sensitive": "as:sensitive", "sensitive": "as:sensitive",
"litepub": "http://litepub.social/ns#", "litepub": "http://litepub.social/ns#",
@ -26,6 +27,8 @@
"@id": "litepub:listMessage", "@id": "litepub:listMessage",
"@type": "@id" "@type": "@id"
}, },
"quoteUrl": "as:quoteUrl",
"quoteUri": "fedibird:quoteUri",
"oauthRegistrationEndpoint": { "oauthRegistrationEndpoint": {
"@id": "litepub:oauthRegistrationEndpoint", "@id": "litepub:oauthRegistrationEndpoint",
"@type": "@id" "@type": "@id"
@ -35,7 +38,8 @@
"alsoKnownAs": { "alsoKnownAs": {
"@id": "as:alsoKnownAs", "@id": "as:alsoKnownAs",
"@type": "@id" "@type": "@id"
} },
"vcard": "http://www.w3.org/2006/vcard/ns#"
} }
] ]
} }