use SimpleXMLElement;
/**
- * This class contain functions to create and send Diaspora XML files
+ * This class contains functions to communicate via the Diaspora protocol
+ * @see https://diaspora.github.io/diaspora_federation/
*/
class Diaspora
{
}
$items = Post::select(['author-id', 'author-link', 'parent-author-link', 'parent-guid', 'guid'],
- ['parent' => $item['parent'], 'gravity' => [GRAVITY_COMMENT, GRAVITY_ACTIVITY]]);
+ ['parent' => $item['parent'], 'gravity' => [Item::GRAVITY_COMMENT, Item::GRAVITY_ACTIVITY]]);
while ($item = Post::fetch($items)) {
$contact = DBA::selectFirst('contact', ['id', 'url', 'name', 'protocol', 'batch', 'network'],
['id' => $item['author-id']]);
return false;
}
- $children = $basedom->children('http://salmon-protocol.org/ns/magic-env');
+ $children = $basedom->children(ActivityNamespace::SALMON_ME);
if (sizeof($children) == 0) {
Logger::notice('XML has no children');
// Is it a private post? Then decrypt the outer Salmon
if (is_object($data)) {
- $encrypted_aes_key_bundle = base64_decode($data->aes_key);
- $ciphertext = base64_decode($data->encrypted_magic_envelope);
+ try {
+ if (!isset($data->aes_key) || !isset($data->encrypted_magic_envelope)) {
+ Logger::info('Missing keys "aes_key" and/or "encrypted_magic_envelope"', ['data' => $data]);
+ throw new \RuntimeException('Missing keys "aes_key" and/or "encrypted_magic_envelope"');
+ }
- $outer_key_bundle = '';
- @openssl_private_decrypt($encrypted_aes_key_bundle, $outer_key_bundle, $privKey);
- $j_outer_key_bundle = json_decode($outer_key_bundle);
+ $encrypted_aes_key_bundle = base64_decode($data->aes_key);
+ $ciphertext = base64_decode($data->encrypted_magic_envelope);
+
+ $outer_key_bundle = '';
+ @openssl_private_decrypt($encrypted_aes_key_bundle, $outer_key_bundle, $privKey);
+ $j_outer_key_bundle = json_decode($outer_key_bundle);
+
+ if (!is_object($j_outer_key_bundle)) {
+ Logger::info('Unable to decode outer key bundle', ['outer_key_bundle' => $outer_key_bundle]);
+ throw new \RuntimeException('Unable to decode outer key bundle');
+ }
+
+ if (!isset($j_outer_key_bundle->iv) || !isset($j_outer_key_bundle->key)) {
+ Logger::info('Missing keys "iv" and/or "key" from outer Salmon', ['j_outer_key_bundle' => $j_outer_key_bundle]);
+ throw new \RuntimeException('Missing keys "iv" and/or "key" from outer Salmon');
+ }
+
+ $outer_iv = base64_decode($j_outer_key_bundle->iv);
+ $outer_key = base64_decode($j_outer_key_bundle->key);
- if (!is_object($j_outer_key_bundle)) {
+ $xml = self::aesDecrypt($outer_key, $outer_iv, $ciphertext);
+ } catch (\Throwable $e) {
Logger::notice('Outer Salmon did not verify. Discarding.');
if ($no_exit) {
return false;
throw new \Friendica\Network\HTTPException\BadRequestException();
}
}
-
- $outer_iv = base64_decode($j_outer_key_bundle->iv);
- $outer_key = base64_decode($j_outer_key_bundle->key);
-
- $xml = self::aesDecrypt($outer_key, $outer_iv, $ciphertext);
} else {
$xml = $raw;
}
}
if (!($fields = self::validPosting($msg))) {
- Logger::notice('Invalid posting');
+ Logger::warning('Invalid posting');
return false;
}
if (is_null($fields)) {
$private = true;
if (!($fields = self::validPosting($msg))) {
- Logger::notice('Invalid posting');
+ Logger::warning('Invalid posting');
return false;
}
} else {
$type = $element->getName();
$orig_type = $type;
- Logger::debug('Got message type ' . $type . ': ' . $msg['message']);
+ Logger::debug('Got message', ['type' => $type, 'message' => $msg['message']]);
// All retractions are handled identically from now on.
// In the new version there will only be "retraction".
if (!in_array($type, ['comment', 'like'])) {
return $fields;
}
+
+ if (!isset($author_signature) && ($msg['author'] == $fields->author)) {
+ Logger::debug('No author signature, but the sender matches the author', ['type' => $type, 'msg-author' => $msg['author'], 'message' => $msg['message']]);
+ return $fields;
+ }
+
// No author_signature? This is a must, so we quit.
if (!isset($author_signature)) {
- Logger::info('No author signature for type ' . $type . ' - Message: ' . $msg['message']);
+ Logger::info('No author signature', ['type' => $type, 'msg-author' => $msg['author'], 'fields-author' => $fields->author, 'message' => $msg['message']]);
return false;
}
}
if (!Crypto::rsaVerify($signed_data, $parent_author_signature, $key, 'sha256')) {
- Logger::info('No valid parent author signature for parent author ' . $msg['author'] . ' in type ' . $type . ' - signed data: ' . $signed_data . ' - Message: ' . $msg['message'] . ' - Signature ' . $parent_author_signature);
+ Logger::info('No valid parent author signature', ['author' => $msg['author'], 'type' => $type, 'signed data' => $signed_data, 'message' => $msg['message'], 'signature' => $parent_author_signature]);
return false;
}
}
}
if (!Crypto::rsaVerify($signed_data, $author_signature, $key, 'sha256')) {
- Logger::info('No valid author signature for author ' . $fields->author . ' in type ' . $type . ' - signed data: ' . $signed_data . ' - Message: ' . $msg['message'] . ' - Signature ' . $author_signature);
+ Logger::info('No valid author signature for author', ['author' => $fields->author, 'type' => $type, 'signed data' => $signed_data, 'message' => $msg['message'], 'signature' => $author_signature]);
return false;
} else {
return $fields;
return '';
}
- /**
- * get a handle (user@domain.tld) from a given contact id
- *
- * @param int $contact_id The id in the contact table
- * @param int $pcontact_id The id in the contact table (Used for the public contact)
- *
- * @return string the handle
- * @throws \Exception
- */
- private static function handleFromContact(int $contact_id, int $pcontact_id = 0): string
- {
- $handle = '';
-
- if ($pcontact_id != 0) {
- $contact = Contact::getById($pcontact_id, ['addr']);
- if (DBA::isResult($contact)) {
- $handle = $contact['addr'];
- }
- }
-
- if (empty($handle)) {
- $contact = Contact::getById($contact_id, ['addr']);
- if (DBA::isResult($contact)) {
- $handle = $contact['addr'];
- }
- }
-
- return strtolower($handle);
- }
-
/**
* Get a contact id for a given handle
*
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
- private static function storeByGuid(string $guid, string $server, bool $force)
+ public static function storeByGuid(string $guid, string $server, bool $force)
{
$serverparts = parse_url($server);
$datarray['uri-id'] = ItemURI::insert(['uri' => $datarray['uri'], 'guid' => $datarray['guid']]);
$datarray['verb'] = Activity::POST;
- $datarray['gravity'] = GRAVITY_COMMENT;
+ $datarray['gravity'] = Item::GRAVITY_COMMENT;
$datarray['thr-parent'] = $thr_parent ?: $toplevel_parent_item['uri'];
}
}
if (!$conversation) {
- Logger::notice('Unable to create conversation.');
+ Logger::warning('Unable to create conversation.');
return false;
}
$datarray['uri'] = self::getUriFromGuid($author, $guid);
$datarray['verb'] = $verb;
- $datarray['gravity'] = GRAVITY_ACTIVITY;
+ $datarray['gravity'] = Item::GRAVITY_ACTIVITY;
$datarray['thr-parent'] = $toplevel_parent_item['uri'];
$datarray['object-type'] = Activity\ObjectType::NOTE;
$datarray['changed'] = $datarray['created'] = $datarray['edited'] = DateTimeFormat::utcNow();
// like on comments have the comment as parent. So we need to fetch the toplevel parent
- if ($toplevel_parent_item['gravity'] != GRAVITY_PARENT) {
+ if ($toplevel_parent_item['gravity'] != Item::GRAVITY_PARENT) {
$toplevel = Post::selectFirst(['origin'], ['id' => $toplevel_parent_item['parent']]);
$origin = $toplevel['origin'];
} else {
$datarray['uri'] = self::getUriFromGuid($author, $guid);
$datarray['verb'] = Activity::FOLLOW;
- $datarray['gravity'] = GRAVITY_ACTIVITY;
+ $datarray['gravity'] = Item::GRAVITY_ACTIVITY;
$datarray['thr-parent'] = $toplevel_parent_item['uri'];
$datarray['object-type'] = Activity\ObjectType::NOTE;
Logger::info('Participation stored', ['id' => $message_id, 'guid' => $guid, 'parent_guid' => $parent_guid, 'author' => $author]);
// Send all existing comments and likes to the requesting server
- $comments = Post::select(['id', 'uri-id', 'parent-author-network', 'author-network', 'verb'],
- ['parent' => $toplevel_parent_item['id'], 'gravity' => [GRAVITY_COMMENT, GRAVITY_ACTIVITY]]);
+ $comments = Post::select(['id', 'uri-id', 'parent-author-network', 'author-network', 'verb', 'gravity'],
+ ['parent' => $toplevel_parent_item['id'], 'gravity' => [Item::GRAVITY_COMMENT, Item::GRAVITY_ACTIVITY]]);
while ($comment = Post::fetch($comments)) {
- if (in_array($comment['verb'], [Activity::FOLLOW, Activity::TAG])) {
- Logger::info('participation messages are not relayed', ['item' => $comment['id']]);
+ if (($comment['gravity'] == Item::GRAVITY_ACTIVITY) && !in_array($comment['verb'], [Activity::LIKE, Activity::DISLIKE])) {
+ Logger::info('Unsupported activities are not relayed', ['item' => $comment['id'], 'verb' => $comment['verb']]);
continue;
}
}
Logger::info('Deliver participation', ['item' => $comment['id'], 'contact' => $author_contact['cid']]);
- if (Worker::add(PRIORITY_HIGH, 'Delivery', Delivery::POST, $comment['id'], $author_contact['cid'])) {
+ if (Worker::add(Worker::PRIORITY_HIGH, 'Delivery', Delivery::POST, $comment['uri-id'], $author_contact['cid'], $datarray['uid'])) {
Post\DeliveryData::incrementQueueCount($comment['uri-id'], 1);
}
}
return true;
}
- /**
- * Fetches a message with a given guid
- *
- * @param string $guid message guid
- * @param string $orig_author handle of the original post
- * @return array|bool The fetched item or false on failure
- * @throws \Friendica\Network\HTTPException\InternalServerErrorException
- * @throws \ImagickException
- */
- public static function originalItem(string $guid, string $orig_author)
- {
- if (empty($guid)) {
- Logger::notice('Empty guid. Quitting.');
- return false;
- }
-
- // Do we already have this item?
- $fields = ['body', 'title', 'app', 'created', 'object-type', 'uri', 'guid',
- 'author-name', 'author-link', 'author-avatar', 'plink', 'uri-id'];
- $condition = ['guid' => $guid, 'visible' => true, 'deleted' => false, 'private' => [Item::PUBLIC, Item::UNLISTED]];
- $item = Post::selectFirst($fields, $condition);
-
- if (DBA::isResult($item)) {
- Logger::notice("reshared message " . $guid . " already exists on system.");
-
- // Maybe it is already a reshared item?
- // Then refetch the content, if it is a reshare from a reshare.
- // If it is a reshared post from another network then reformat to avoid display problems with two share elements
- if (self::isReshare($item['body'], true)) {
- $item = [];
- } elseif (self::isReshare($item['body'], false) || strstr($item['body'], '[share')) {
- $item['body'] = Markdown::toBBCode(BBCode::toMarkdown($item['body']));
-
- $item['body'] = self::replacePeopleGuid($item['body'], $item['author-link']);
-
- return $item;
- } else {
- return $item;
- }
- }
-
- if (!DBA::isResult($item)) {
- if (empty($orig_author)) {
- Logger::notice('Empty author for guid ' . $guid . '. Quitting.');
- return false;
- }
-
- $server = 'https://' . substr($orig_author, strpos($orig_author, '@') + 1);
- Logger::notice('1st try: reshared message ' . $guid . ' will be fetched via SSL from the server ' . $server);
- $stored = self::storeByGuid($guid, $server, true);
-
- if (!$stored) {
- $server = 'http://' . substr($orig_author, strpos($orig_author, '@') + 1);
- Logger::notice('2nd try: reshared message ' . $guid . ' will be fetched without SSL from the server ' . $server);
- $stored = self::storeByGuid($guid, $server, true);
- }
-
- if ($stored) {
- $fields = ['body', 'title', 'app', 'created', 'object-type', 'uri', 'guid',
- 'author-name', 'author-link', 'author-avatar', 'plink', 'uri-id'];
- $condition = ['guid' => $guid, 'visible' => true, 'deleted' => false, 'private' => [Item::PUBLIC, Item::UNLISTED]];
- $item = Post::selectFirst($fields, $condition);
-
- if (DBA::isResult($item)) {
- // If it is a reshared post from another network then reformat to avoid display problems with two share elements
- if (self::isReshare($item['body'], false)) {
- $item['body'] = Markdown::toBBCode(BBCode::toMarkdown($item['body']));
- $item['body'] = self::replacePeopleGuid($item['body'], $item['author-link']);
- }
-
- return $item;
- }
- }
- }
- return false;
- }
-
/**
* Stores a reshare activity
*
$datarray['thr-parent'] = $parent['uri'];
$datarray['verb'] = $datarray['body'] = Activity::ANNOUNCE;
- $datarray['gravity'] = GRAVITY_ACTIVITY;
+ $datarray['gravity'] = Item::GRAVITY_ACTIVITY;
$datarray['object-type'] = Activity\ObjectType::NOTE;
$datarray['protocol'] = $item['protocol'];
return true;
}
- $original_item = self::originalItem($root_guid, $root_author);
- if (!$original_item) {
+ $original_person = FContact::getByURL($root_author);
+ if (!$original_person) {
return false;
}
- if (empty($original_item['plink'])) {
- $original_item['plink'] = self::plink($root_author, $root_guid);
- }
-
$datarray = [];
$datarray['uid'] = $importer['uid'];
$datarray['uri-id'] = ItemURI::insert(['uri' => $datarray['uri'], 'guid' => $datarray['guid']]);
$datarray['verb'] = Activity::POST;
- $datarray['gravity'] = GRAVITY_PARENT;
+ $datarray['gravity'] = Item::GRAVITY_PARENT;
$datarray['protocol'] = Conversation::PARCEL_DIASPORA;
$datarray['source'] = $xml;
$datarray = self::setDirection($datarray, $direction);
- /// @todo Copy tag data from original post
-
- $prefix = BBCode::getShareOpeningTag(
- $original_item['author-name'],
- $original_item['author-link'],
- $original_item['author-avatar'],
- $original_item['plink'],
- $original_item['created'],
- $original_item['guid']
- );
-
- if (!empty($original_item['title'])) {
- $prefix .= '[h3]' . $original_item['title'] . "[/h3]\n";
+ $datarray['quote-uri-id'] = self::getQuoteUriId($root_guid, $importer['uid'], $original_person['url']);
+ if (empty($datarray['quote-uri-id'])) {
+ return false;
}
- $datarray['body'] = $prefix.$original_item['body'] . '[/share]';
-
- Tag::storeFromBody($datarray['uri-id'], $datarray['body']);
-
- $datarray['app'] = $original_item['app'];
-
- $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;
- $datarray['object-type'] = $original_item['object-type'];
-
self::fetchGuid($datarray);
if (Item::isTooOld($datarray)) {
}
}
+ 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
*
$datarray['owner-id'] = $datarray['author-id'];
$datarray['verb'] = Activity::POST;
- $datarray['gravity'] = GRAVITY_PARENT;
+ $datarray['gravity'] = Item::GRAVITY_PARENT;
$datarray['protocol'] = Conversation::PARCEL_DIASPORA;
$datarray['source'] = $xml;
]
];
- $namespaces = ['me' => 'http://salmon-protocol.org/ns/magic-env'];
+ $namespaces = ['me' => ActivityNamespace::SALMON_ME];
return XML::fromArray($xmldata, $xml, false, $namespaces);
}
}
/**
- * Checks a message body if it is a reshare
+ * Fetch reshare details
*
- * @param string $body The message body that is to be check
- * @param bool $complete Should it be a complete check or a simple check?
+ * @param array $item The message body that is to be check
*
- * @return array|bool Reshare details or "false" if no reshare
+ * @return array Reshare details (empty if the item is no reshare)
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
- public static function isReshare(string $body, bool $complete = true)
+ public static function getReshareDetails(array $item): array
{
- $body = trim($body);
-
- $reshared = Item::getShareArray(['body' => $body]);
+ $reshared = DI::contentItem()->getSharedPost($item, ['guid', 'network', 'author-addr']);
if (empty($reshared)) {
- return false;
- }
-
- // Skip if it isn't a pure repeated messages
- // Does it start with a share?
- if (!empty($reshared['comment']) && $complete) {
- return false;
- }
-
- if (!empty($reshared['guid']) && $complete) {
- $condition = ['guid' => $reshared['guid'], 'network' => [Protocol::DFRN, Protocol::DIASPORA]];
- $item = Post::selectFirst(['contact-id'], $condition);
- if (DBA::isResult($item)) {
- $ret = [];
- $ret['root_handle'] = self::handleFromContact($item['contact-id']);
- $ret['root_guid'] = $reshared['guid'];
- return $ret;
- } elseif ($complete) {
- // We are resharing something that isn't a DFRN or Diaspora post.
- // So we have to return "false" on "$complete" to not trigger a reshare.
- return false;
- }
- } elseif (empty($reshared['guid']) && $complete) {
- return false;
- }
-
- $ret = [];
-
- if (!empty($reshared['profile']) && ($cid = Contact::getIdForURL($reshared['profile']))) {
- $contact = DBA::selectFirst('contact', ['addr'], ['id' => $cid]);
- if (!empty($contact['addr'])) {
- $ret['root_handle'] = $contact['addr'];
- }
+ return [];
}
- if (empty($ret) && !$complete) {
- return true;
+ // Skip if it isn't a pure repeated messages or not a real reshare
+ if (!empty($reshared['comment']) || !in_array($reshared['post']['network'], [Protocol::DFRN, Protocol::DIASPORA])) {
+ return [];
}
- return $ret;
+ return [
+ 'root_handle' => strtolower($reshared['post']['author-addr']),
+ 'root_guid' => $reshared['post']['guid'],
+ ];
}
/**
$edited = DateTimeFormat::utc($item['edited'] ?? $item['created'], DateTimeFormat::ATOM);
// Detect a share element and do a reshare
- if (($item['private'] != Item::PRIVATE) && ($ret = self::isReshare($item['body']))) {
+ if (($item['private'] != Item::PRIVATE) && ($ret = self::getReshareDetails($item))) {
$message = [
'author' => $myaddr,
'guid' => $item['guid'],
$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')) {
}
}
- if ($item['author-link'] != $item['owner-link']) {
- $body = BBCode::getShareOpeningTag($item['author-name'], $item['author-link'], $item['author-avatar'],
- $item['plink'], $item['created']) . $body . '[/share]';
- }
-
// convert to markdown
$body = html_entity_decode(BBCode::toMarkdown($body));
$attend_answer = 'tentative';
break;
default:
- Logger::notice('Unknown verb ' . $item['verb'] . ' in item ' . $item['guid']);
+ Logger::warning('Unknown verb ' . $item['verb'] . ' in item ' . $item['guid']);
return false;
}
$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
// - Implicit mentions are enabled
if (
$item['author-id'] != $thread_parent_item['author-id']
- && ($thread_parent_item['gravity'] != GRAVITY_PARENT)
+ && ($thread_parent_item['gravity'] != Item::GRAVITY_PARENT)
&& (empty($item['uid']) || !Feature::isEnabled($item['uid'], 'explicit_mentions'))
&& !DI::config()->get('system', 'disable_implicit_mentions')
) {
Logger::info('Got relayable data ' . $type . ' for item ' . $item['guid'] . ' (' . $item['id'] . ')');
- $msg = json_decode($item['signed_text'], true);
+ $msg = json_decode($item['signed_text'] ?? '', true);
$message = [];
if (is_array($msg)) {
*/
public static function sendRetraction(array $item, array $owner, array $contact, bool $public_batch = false, bool $relay = false): int
{
- $itemaddr = self::handleFromContact($item['contact-id'], $item['author-id']);
+ $itemaddr = strtolower($item['author-addr']);
$msg_type = 'retraction';
- if ($item['gravity'] == GRAVITY_PARENT) {
+ if ($item['gravity'] == Item::GRAVITY_PARENT) {
$target_type = 'Post';
} elseif (in_array($item['verb'], [Activity::LIKE, Activity::DISLIKE])) {
$target_type = 'Like';
$data['birthday'] = DateTimeFormat::utc($year . '-' . $month . '-' . $day, 'Y-m-d');
}
- $data['about'] = BBCode::toMarkdown($profile['about']);
+ $data['about'] = BBCode::toMarkdown($profile['about'] ?? '');
$data['location'] = $profile['location'];
$data['tag_string'] = '';
return false;
}
+ if (!self::parentSupportDiaspora($item['thr-parent-id'])) {
+ Logger::info('One of the parents does not support Diaspora. A signature will not be created.', ['uri-id' => $item['uri-id'], 'guid' => $item['guid']]);
+ return false;
+ }
+
$message = self::constructComment($item, $owner);
if ($message === false) {
return false;
return $message;
}
- public static function performReshare(int $UriId, int $uid): int
+ /**
+ * Check if the parent and their parents support Diaspora
+ *
+ * @param integer $parent_id
+ * @return boolean
+ */
+ private static function parentSupportDiaspora(int $parent_id): bool
{
- $fields = ['uri-id', 'body', 'title', 'author-name', 'author-link', 'author-avatar', 'guid', 'created', 'plink'];
- $item = Post::selectFirst($fields, ['uri-id' => $UriId, 'uid' => [$uid, 0], 'private' => [Item::PUBLIC, Item::UNLISTED]]);
- if (!DBA::isResult($item)) {
- return 0;
+ $parent_post = Post::selectFirstPost(['gravity', 'signed_text', 'author-link', 'thr-parent-id'], ['uri-id' => $parent_id]);
+ if (empty($parent_post['thr-parent-id'])) {
+ Logger::warning('Parent post does not exist.', ['parent-id' => $parent_id]);
+ return false;
}
- if (strpos($item['body'], '[/share]') !== false) {
- $pos = strpos($item['body'], '[share');
- $post = substr($item['body'], $pos);
- } else {
- $post = BBCode::getShareOpeningTag($item['author-name'], $item['author-link'], $item['author-avatar'], $item['plink'], $item['created'], $item['guid']);
+ if (empty(FContact::getByURL($parent_post['author-link'], false))) {
+ Logger::info('Parent author is no Diaspora contact.', ['parent-id' => $parent_id]);
+ return false;
+ }
- if (!empty($item['title'])) {
- $post .= '[h3]' . $item['title'] . "[/h3]\n";
- }
+ if (($parent_post['gravity'] == Item::GRAVITY_COMMENT) && empty($parent_post['signed_text'])) {
+ Logger::info('Parent comment has got no Diaspora signature.', ['parent-id' => $parent_id]);
+ return false;
+ }
- $post .= $item['body'];
- $post .= '[/share]';
+ if ($parent_post['gravity'] == Item::GRAVITY_COMMENT) {
+ return self::parentSupportDiaspora($parent_post['thr-parent-id']);
}
+ return true;
+ }
+
+ public static function performReshare(int $UriId, int $uid): int
+ {
$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'])) {