Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of FEP-e232 for quoted posts #14032

Merged
merged 1 commit into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Content/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -800,14 +800,14 @@
*/
public function addShareLink(string $body, int $quote_uri_id): string
{
$post = Post::selectFirstPost(['uri', 'plink'], ['uri-id' => $quote_uri_id]);
$post = Post::selectFirstPost(['uri'], ['uri-id' => $quote_uri_id]);

Check warning on line 803 in src/Content/Item.php

View check run for this annotation

Codecov / codecov/patch

src/Content/Item.php#L803

Added line #L803 was not covered by tests
if (empty($post)) {
return $body;
}

$body = BBCode::removeSharedData($body);

$body .= "\n♲ " . ($post['plink'] ?: $post['uri']);
$body .= "\nRE: " . $post['uri'];

Check warning on line 810 in src/Content/Item.php

View check run for this annotation

Codecov / codecov/patch

src/Content/Item.php#L810

Added line #L810 was not covered by tests

return $body;
}
Expand Down
15 changes: 11 additions & 4 deletions src/Protocol/ActivityPub/Receiver.php
Original file line number Diff line number Diff line change
Expand Up @@ -1577,7 +1577,8 @@
$element = [
'type' => str_replace('as:', '', JsonLD::fetchElement($tag, '@type') ?? ''),
'href' => JsonLD::fetchElement($tag, 'as:href', '@id'),
'name' => JsonLD::fetchElement($tag, 'as:name', '@value')
'name' => JsonLD::fetchElement($tag, 'as:name', '@value'),
'mediaType' => JsonLD::fetchElement($tag, 'as:mediaType', '@value')

Check warning on line 1581 in src/Protocol/ActivityPub/Receiver.php

View check run for this annotation

Codecov / codecov/patch

src/Protocol/ActivityPub/Receiver.php#L1580-L1581

Added lines #L1580 - L1581 were not covered by tests
];

if (empty($element['type'])) {
Expand Down Expand Up @@ -2094,12 +2095,18 @@
}

// Support for quoted posts (Pleroma, Fedibird and Misskey)
$object_data['quote-url'] = JsonLD::fetchElement($object, 'as:quoteUrl', '@value');
$object_data['quote-url'] = JsonLD::fetchElement($object, 'as:quoteUrl', '@id');

Check warning on line 2098 in src/Protocol/ActivityPub/Receiver.php

View check run for this annotation

Codecov / codecov/patch

src/Protocol/ActivityPub/Receiver.php#L2098

Added line #L2098 was not covered by tests
if (empty($object_data['quote-url'])) {
$object_data['quote-url'] = JsonLD::fetchElement($object, 'fedibird:quoteUri', '@value');
$object_data['quote-url'] = JsonLD::fetchElement($object, 'fedibird:quoteUri', '@id');

Check warning on line 2100 in src/Protocol/ActivityPub/Receiver.php

View check run for this annotation

Codecov / codecov/patch

src/Protocol/ActivityPub/Receiver.php#L2100

Added line #L2100 was not covered by tests
}
if (empty($object_data['quote-url'])) {
$object_data['quote-url'] = JsonLD::fetchElement($object, 'misskey:_misskey_quote', '@value');
$object_data['quote-url'] = JsonLD::fetchElement($object, 'misskey:_misskey_quote', '@id');

Check warning on line 2103 in src/Protocol/ActivityPub/Receiver.php

View check run for this annotation

Codecov / codecov/patch

src/Protocol/ActivityPub/Receiver.php#L2103

Added line #L2103 was not covered by tests
}

foreach ($object_data['tags'] as $tag) {
if (HTTPSignature::isValidContentType($tag['mediaType'] ?? '', $tag['href'])) {
$object_data['quote-url'] = $tag['href'];

Check warning on line 2108 in src/Protocol/ActivityPub/Receiver.php

View check run for this annotation

Codecov / codecov/patch

src/Protocol/ActivityPub/Receiver.php#L2106-L2108

Added lines #L2106 - L2108 were not covered by tests
}
}

// Misskey adds some data to the standard "content" value for quoted posts for backwards compatibility.
Expand Down
16 changes: 8 additions & 8 deletions src/Protocol/ActivityPub/Transmitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -1589,15 +1589,14 @@
$tags[] = ['type' => 'Mention', 'href' => $announce['actor']['url'], 'name' => '@' . $announce['actor']['addr']];
}

// @see https://codeberg.org/fediverse/fep/src/branch/main/feps/fep-e232.md
// @see https://codeberg.org/fediverse/fep/src/branch/main/fep/e232/fep-e232.md
if (!empty($quote_url)) {
// Currently deactivated because of compatibility issues with Pleroma
//$tags[] = [
// 'type' => 'Link',
// 'mediaType' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
// 'href' => $quote_url,
// 'name' => '♲ ' . BBCode::convertForUriId($item['uri-id'], $quote_url, BBCode::ACTIVITYPUB)
//];
$tags[] = [
'type' => 'Link',
'mediaType' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
'href' => $quote_url,
'name' => 'RE: ' . $quote_url,
];

Check warning on line 1599 in src/Protocol/ActivityPub/Transmitter.php

View check run for this annotation

Codecov / codecov/patch

src/Protocol/ActivityPub/Transmitter.php#L1594-L1599

Added lines #L1594 - L1599 were not covered by tests
}

return $tags;
Expand Down Expand Up @@ -1862,6 +1861,7 @@
if (!empty($item['quote-uri-id']) && ($item['quote-uri-id'] != $item['uri-id'])) {
if (Post::exists(['uri-id' => $item['quote-uri-id'], 'network' => [Protocol::ACTIVITYPUB, Protocol::DFRN]])) {
$real_quote = true;
$data['_misskey_content'] = BBCode::removeSharedData($body);

Check warning on line 1864 in src/Protocol/ActivityPub/Transmitter.php

View check run for this annotation

Codecov / codecov/patch

src/Protocol/ActivityPub/Transmitter.php#L1864

Added line #L1864 was not covered by tests
$data['quoteUrl'] = $item['quote-uri'];
$body = DI::contentItem()->addShareLink($body, $item['quote-uri-id']);
} else {
Expand Down