mirror of
https://github.com/friendica/friendica
synced 2025-09-17 00:51:06 +02:00
Improved handling of native quotes
This commit is contained in:
parent
f418687a71
commit
3c169b534e
11 changed files with 204 additions and 217 deletions
|
@ -827,10 +827,26 @@ class Processor
|
|||
|
||||
$content = self::addMentionLinks($content, $activity['tags']);
|
||||
|
||||
if (!empty($activity['quote-url'])) {
|
||||
$id = Item::fetchByLink($activity['quote-url']);
|
||||
if ($id) {
|
||||
$shared_item = Post::selectFirst(['uri-id'], ['id' => $id]);
|
||||
$item['quote-uri-id'] = $shared_item['uri-id'];
|
||||
} else {
|
||||
Logger::info('Quote was not fetched', ['guid' => $item['guid'], 'uri-id' => $item['uri-id'], 'quote' => $activity['quote-url']]);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($activity['source'])) {
|
||||
$item['body'] = $activity['source'];
|
||||
$item['raw-body'] = $content;
|
||||
$item['body'] = DI::contentItem()->improveSharedDataInBody($item);
|
||||
|
||||
$quote_uri_id = Item::getQuoteUriId($item['body']);
|
||||
if (empty($item['quote-uri-id']) && !empty($quote_uri_id)) {
|
||||
$item['quote-uri-id'] = $quote_uri_id;
|
||||
}
|
||||
|
||||
$item['body'] = BBCode::removeSharedData($item['body']);
|
||||
} else {
|
||||
$parent_uri = $item['parent-uri'] ?? $item['thr-parent'];
|
||||
if (empty($activity['directmessage']) && ($parent_uri != $item['uri']) && ($item['gravity'] == Item::GRAVITY_COMMENT)) {
|
||||
|
@ -848,10 +864,6 @@ class Processor
|
|||
}
|
||||
$item['content-warning'] = HTML::toBBCode($activity['summary'] ?? '');
|
||||
$item['raw-body'] = $item['body'] = $content;
|
||||
|
||||
if (!empty($activity['quote-url'])) {
|
||||
$item['body'] .= DI::contentItem()->createSharedPostByUrl($activity['quote-url']);
|
||||
}
|
||||
}
|
||||
|
||||
self::storeFromBody($item);
|
||||
|
|
|
@ -1664,20 +1664,17 @@ class Transmitter
|
|||
$body = preg_replace("/\s*\[attachment .*?\].*?\[\/attachment\]\s*/ism", '', $body);
|
||||
}
|
||||
|
||||
$body = BBCode::setMentionsToNicknames($body);
|
||||
$exists_reshare = BBCode::existsShare($body);
|
||||
$body = BBCode::setMentionsToNicknames($body);
|
||||
|
||||
if (!empty($item['quote-uri']) && Post::exists(['uri-id' => $item['quote-uri-id'], 'network' => [Protocol::ACTIVITYPUB, Protocol::DFRN]])) {
|
||||
$real_quote = true;
|
||||
if ($exists_reshare) {
|
||||
$body = BBCode::replaceSharedData($body);
|
||||
} elseif (strpos($body, $item['quote-uri']) === false) {
|
||||
$body .= "\n♲ " . $item['quote-uri'];
|
||||
if (!empty($item['quote-uri-id'])) {
|
||||
$body = BBCode::removeSharedData($body);
|
||||
if (Post::exists(['uri-id' => $item['quote-uri-id'], 'network' => [Protocol::ACTIVITYPUB, Protocol::DFRN]])) {
|
||||
$real_quote = true;
|
||||
$data['quoteUrl'] = $item['quote-uri'];
|
||||
$body = DI::contentItem()->addShareLink($body, $item['quote-uri-id']);
|
||||
} else {
|
||||
$body = DI::contentItem()->addSharedPost($item, $body);
|
||||
}
|
||||
$data['quoteUrl'] = $item['quote-uri'];
|
||||
} elseif (!empty($item['quote-uri']) && !$exists_reshare) {
|
||||
$body .= "\n" . DI::contentItem()->createSharedPostByUriId($item['quote-uri-id'], $item['uid'], true);
|
||||
$item['body'] = DI::contentItem()->improveSharedDataInBody($item, true);
|
||||
}
|
||||
|
||||
$data['content'] = BBCode::convertForUriId($item['uri-id'], $body, BBCode::ACTIVITYPUB);
|
||||
|
@ -1689,15 +1686,14 @@ class Transmitter
|
|||
$language = self::getLanguage($item);
|
||||
if (!empty($language)) {
|
||||
$richbody = BBCode::setMentionsToNicknames($item['body'] ?? '');
|
||||
|
||||
if ($real_quote) {
|
||||
if (BBCode::existsShare($richbody)) {
|
||||
$richbody = BBCode::replaceSharedData($richbody);
|
||||
} elseif (strpos($richbody, $item['quote-uri']) === false) {
|
||||
$richbody .= "\n♲ " . $item['quote-uri'];
|
||||
if (!empty($item['quote-uri-id'])) {
|
||||
$richbody = BBCode::removeSharedData($richbody);
|
||||
if ($real_quote) {
|
||||
$richbody = DI::contentItem()->addShareLink($richbody, $item['quote-uri-id']);
|
||||
} else {
|
||||
$richbody = DI::contentItem()->addSharedPost($item, $richbody);
|
||||
}
|
||||
}
|
||||
|
||||
$richbody = BBCode::removeAttachment($richbody);
|
||||
|
||||
$data['contentMap'][$language] = BBCode::convertForUriId($item['uri-id'], $richbody, BBCode::EXTERNAL);
|
||||
|
|
|
@ -774,7 +774,7 @@ class DFRN
|
|||
$entry->setAttribute("xmlns:statusnet", ActivityNamespace::STATUSNET);
|
||||
}
|
||||
|
||||
$body = Post\Media::addAttachmentsToBody($item['uri-id'], $item['body'] ?? '');
|
||||
$body = Post\Media::addAttachmentsToBody($item['uri-id'], DI::contentItem()->addSharedPost($item));
|
||||
|
||||
if ($item['private'] == Item::PRIVATE) {
|
||||
$body = Item::fixPrivatePhotos($body, $owner['uid'], $item, $cid);
|
||||
|
@ -1838,7 +1838,11 @@ class DFRN
|
|||
|
||||
$item['uri-id'] = ItemURI::insert(['uri' => $item['uri'], 'guid' => $item['guid']]);
|
||||
|
||||
$item['body'] = DI::contentItem()->improveSharedDataInBody($item);
|
||||
$quote_uri_id = Item::getQuoteUriId($item['body'], $item['uid']);
|
||||
if (!empty($quote_uri_id)) {
|
||||
$item['quote-uri-id'] = $quote_uri_id;
|
||||
$item['body'] = BBCode::removeSharedData($item['body']);
|
||||
}
|
||||
|
||||
Tag::storeFromBody($item['uri-id'], $item['body']);
|
||||
|
||||
|
|
|
@ -2364,13 +2364,13 @@ class Diaspora
|
|||
|
||||
$datarray = self::setDirection($datarray, $direction);
|
||||
|
||||
$datarray['body'] = DI::contentItem()->createSharedPostByGuid($root_guid, $importer['uid'], $original_person['url']);
|
||||
$datarray['body'] = Diaspora::replacePeopleGuid($datarray['body'], $datarray['author-link']);
|
||||
$datarray['quote-uri-id'] = self::getQuoteUriId($root_guid, $importer['uid'], $original_person['url']);
|
||||
if (empty($datarray['quote-uri-id'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// @todo Copy tag data from original post
|
||||
Tag::storeFromBody($datarray['uri-id'], $datarray['body']);
|
||||
|
||||
$datarray['plink'] = self::plink($author, $guid);
|
||||
$datarray['body'] = '';
|
||||
$datarray['plink'] = self::plink($author, $guid);
|
||||
$datarray['private'] = (($public == 'false') ? Item::PRIVATE : Item::PUBLIC);
|
||||
$datarray['changed'] = $datarray['created'] = $datarray['edited'] = $created_at;
|
||||
|
||||
|
@ -2401,6 +2401,25 @@ class Diaspora
|
|||
}
|
||||
}
|
||||
|
||||
private static function getQuoteUriId(string $guid, int $uid, string $host): int
|
||||
{
|
||||
$shared_item = Post::selectFirst(['uri-id'], ['guid' => $guid, 'uid' => [$uid, 0], 'private' => [Item::PUBLIC, Item::UNLISTED]]);
|
||||
|
||||
if (!DBA::isResult($shared_item) && !empty($host) && Diaspora::storeByGuid($guid, $host, true)) {
|
||||
Logger::debug('Fetched post', ['guid' => $guid, 'host' => $host, 'uid' => $uid]);
|
||||
$shared_item = Post::selectFirst(['uri-id'], ['guid' => $guid, 'uid' => [$uid, 0], 'private' => [Item::PUBLIC, Item::UNLISTED]]);
|
||||
} elseif (DBA::isResult($shared_item)) {
|
||||
Logger::debug('Found existing post', ['guid' => $guid, 'host' => $host, 'uid' => $uid]);
|
||||
}
|
||||
|
||||
if (!DBA::isResult($shared_item)) {
|
||||
Logger::notice('Post does not exist.', ['guid' => $guid, 'host' => $host, 'uid' => $uid]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return $shared_item['uri-id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes retractions
|
||||
*
|
||||
|
@ -3305,7 +3324,7 @@ class Diaspora
|
|||
$type = 'reshare';
|
||||
} else {
|
||||
$title = $item['title'];
|
||||
$body = Post\Media::addAttachmentsToBody($item['uri-id'], $item['body']);
|
||||
$body = Post\Media::addAttachmentsToBody($item['uri-id'], DI::contentItem()->addSharedPost($item));
|
||||
|
||||
// Fetch the title from an attached link - if there is one
|
||||
if (empty($item['title']) && DI::pConfig()->get($owner['uid'], 'system', 'attach_link_title')) {
|
||||
|
@ -3315,11 +3334,6 @@ class Diaspora
|
|||
}
|
||||
}
|
||||
|
||||
// @todo Check if this is obsolete and if we are still using different owners. (Possibly a fragment from the forum functionality)
|
||||
if ($item['author-link'] != $item['owner-link']) {
|
||||
$body = DI::contentItem()->createSharedBlockByArray($item);
|
||||
}
|
||||
|
||||
// convert to markdown
|
||||
$body = html_entity_decode(BBCode::toMarkdown($body));
|
||||
|
||||
|
@ -3527,7 +3541,7 @@ class Diaspora
|
|||
$thread_parent_item = Post::selectFirst(['guid', 'author-id', 'author-link', 'gravity'], ['uri' => $item['thr-parent'], 'uid' => $item['uid']]);
|
||||
}
|
||||
|
||||
$body = Post\Media::addAttachmentsToBody($item['uri-id'], $item['body']);
|
||||
$body = Post\Media::addAttachmentsToBody($item['uri-id'], DI::contentItem()->addSharedPost($item));
|
||||
|
||||
// The replied to autor mention is prepended for clarity if:
|
||||
// - Item replied isn't yours
|
||||
|
@ -4022,25 +4036,21 @@ class Diaspora
|
|||
|
||||
public static function performReshare(int $UriId, int $uid): int
|
||||
{
|
||||
$post = DI::contentItem()->createSharedPostByUriId($UriId, $uid);
|
||||
if (empty($post)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$owner = User::getOwnerDataById($uid);
|
||||
$author = Contact::getPublicIdByUserId($uid);
|
||||
|
||||
$item = [
|
||||
'uid' => $uid,
|
||||
'verb' => Activity::POST,
|
||||
'contact-id' => $owner['id'],
|
||||
'author-id' => $author,
|
||||
'owner-id' => $author,
|
||||
'body' => $post,
|
||||
'allow_cid' => $owner['allow_cid'] ?? '',
|
||||
'allow_gid' => $owner['allow_gid']?? '',
|
||||
'deny_cid' => $owner['deny_cid'] ?? '',
|
||||
'deny_gid' => $owner['deny_gid'] ?? '',
|
||||
'uid' => $uid,
|
||||
'verb' => Activity::POST,
|
||||
'contact-id' => $owner['id'],
|
||||
'author-id' => $author,
|
||||
'owner-id' => $author,
|
||||
'body' => '',
|
||||
'quote-uri-id' => $UriId,
|
||||
'allow_cid' => $owner['allow_cid'] ?? '',
|
||||
'allow_gid' => $owner['allow_gid']?? '',
|
||||
'deny_cid' => $owner['deny_cid'] ?? '',
|
||||
'deny_gid' => $owner['deny_gid'] ?? '',
|
||||
];
|
||||
|
||||
if (!empty($item['allow_cid'] . $item['allow_gid'] . $item['deny_cid'] . $item['deny_gid'])) {
|
||||
|
|
|
@ -1598,7 +1598,7 @@ class OStatus
|
|||
XML::addElement($doc, $entry, 'id', $item['uri']);
|
||||
XML::addElement($doc, $entry, 'title', html_entity_decode($title, ENT_QUOTES, 'UTF-8'));
|
||||
|
||||
$body = Post\Media::addAttachmentsToBody($item['uri-id'], $item['body']);
|
||||
$body = Post\Media::addAttachmentsToBody($item['uri-id'], DI::contentItem()->addSharedPost($item));
|
||||
$body = self::formatPicturePost($body, $item['uri-id']);
|
||||
|
||||
if (!empty($item['title'])) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue