X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FProtocol%2FActivityPub%2FProcessor.php;h=66aedf65b06d39f69a8e2e567026870ff3bc4fc8;hb=878a5b052bd41aad2cd1aad63f91f872a3e29794;hp=9e8ea2976e5ad3046c5f5c18e4acaddd11a0780b;hpb=68502daed09a69804650a6501baefc3a3fdf61b7;p=friendica.git diff --git a/src/Protocol/ActivityPub/Processor.php b/src/Protocol/ActivityPub/Processor.php index 9e8ea2976e..66aedf65b0 100644 --- a/src/Protocol/ActivityPub/Processor.php +++ b/src/Protocol/ActivityPub/Processor.php @@ -1,6 +1,6 @@ $activity['id']]); + $item = Post::selectFirst(['uri', 'uri-id', 'thr-parent', 'gravity', 'post-type'], ['uri' => $activity['id']]); if (!DBA::isResult($item)) { Logger::warning('No existing item, item will be created', ['uri' => $activity['id']]); $item = self::createItem($activity); @@ -301,6 +352,24 @@ class Processor $item['direction'] = Conversation::RELAY; } + if ($activity['object_type'] == 'as:Article') { + $item['post-type'] = Item::PT_ARTICLE; + } elseif ($activity['object_type'] == 'as:Audio') { + $item['post-type'] = Item::PT_AUDIO; + } elseif ($activity['object_type'] == 'as:Document') { + $item['post-type'] = Item::PT_DOCUMENT; + } elseif ($activity['object_type'] == 'as:Event') { + $item['post-type'] = Item::PT_EVENT; + } elseif ($activity['object_type'] == 'as:Image') { + $item['post-type'] = Item::PT_IMAGE; + } elseif ($activity['object_type'] == 'as:Page') { + $item['post-type'] = Item::PT_PAGE; + } elseif ($activity['object_type'] == 'as:Video') { + $item['post-type'] = Item::PT_VIDEO; + } else { + $item['post-type'] = Item::PT_NOTE; + } + $item['isForum'] = false; if (!empty($activity['thread-completion'])) { @@ -346,6 +415,19 @@ class Processor $item = self::constructAttachList($activity, $item); + // We received the post via AP, so we set the protocol of the server to AP + $contact = Contact::getById($item['author-id'], ['gsid']); + if (!empty($contact['gsid'])) { + GServer::setProtocol($contact['gsid'], Post\DeliveryData::ACTIVITYPUB); + } + + if ($item['author-id'] != $item['owner-id']) { + $contact = Contact::getById($item['owner-id'], ['gsid']); + if (!empty($contact['gsid'])) { + GServer::setProtocol($contact['gsid'], Post\DeliveryData::ACTIVITYPUB); + } + } + return $item; } @@ -378,7 +460,7 @@ class Processor } foreach ($activity['receiver'] as $receiver) { - $item = Post::selectFirst(['id', 'uri-id', 'tag', 'origin', 'author-link'], ['uri' => $activity['target_id'], 'uid' => $receiver]); + $item = Post::selectFirst(['id', 'uri-id', 'origin', 'author-link'], ['uri' => $activity['target_id'], 'uid' => $receiver]); if (!DBA::isResult($item)) { // We don't fetch missing content for this purpose continue; @@ -408,6 +490,7 @@ class Processor $item['verb'] = $verb; $item['thr-parent'] = $activity['object_id']; $item['gravity'] = GRAVITY_ACTIVITY; + unset($item['post-type']); $item['object-type'] = Activity\ObjectType::NOTE; $item['diaspora_signed_text'] = $activity['diaspora:like'] ?? ''; @@ -430,7 +513,7 @@ class Processor $event['finish'] = $activity['end-time']; $event['nofinish'] = empty($event['finish']); $event['location'] = $activity['location']; - $event['adjust'] = true; + $event['adjust'] = $activity['adjust'] ?? true; $event['cid'] = $item['contact-id']; $event['uid'] = $item['uid']; $event['uri'] = $item['uri']; @@ -463,9 +546,21 @@ class Processor */ private static function processContent($activity, $item) { - $item['title'] = HTML::toBBCode($activity['name']); + if (!empty($activity['mediatype']) && ($activity['mediatype'] == 'text/markdown')) { + $item['title'] = Markdown::toBBCode($activity['name']); + $content = Markdown::toBBCode($activity['content']); + } elseif (!empty($activity['mediatype']) && ($activity['mediatype'] == 'text/bbcode')) { + $item['title'] = $activity['name']; + $content = $activity['content']; + } else { + // By default assume "text/html" + $item['title'] = HTML::toBBCode($activity['name']); + $content = HTML::toBBCode($activity['content']); + } - $content = HTML::toBBCode($activity['content']); + if (!empty($activity['languages'])) { + $item['language'] = self::processLanguages($activity['languages']); + } if (!empty($activity['emojis'])) { $content = self::replaceEmojis($content, $activity['emojis']); @@ -569,34 +664,34 @@ class Processor $type = $activity['reception_type'][$receiver] ?? Receiver::TARGET_UNKNOWN; switch($type) { case Receiver::TARGET_TO: - $item['post-type'] = Item::PT_TO; + $item['post-reason'] = Item::PR_TO; break; case Receiver::TARGET_CC: - $item['post-type'] = Item::PT_CC; + $item['post-reason'] = Item::PR_CC; break; case Receiver::TARGET_BTO: - $item['post-type'] = Item::PT_BTO; + $item['post-reason'] = Item::PR_BTO; break; case Receiver::TARGET_BCC: - $item['post-type'] = Item::PT_BCC; + $item['post-reason'] = Item::PR_BCC; break; case Receiver::TARGET_FOLLOWER: - $item['post-type'] = Item::PT_FOLLOWER; + $item['post-reason'] = Item::PR_FOLLOWER; break; case Receiver::TARGET_ANSWER: - $item['post-type'] = Item::PT_COMMENT; + $item['post-reason'] = Item::PR_COMMENT; break; case Receiver::TARGET_GLOBAL: - $item['post-type'] = Item::PT_GLOBAL; + $item['post-reason'] = Item::PR_GLOBAL; break; default: - $item['post-type'] = Item::PT_ARTICLE; + $item['post-reason'] = Item::PR_NONE; } if (!empty($activity['from-relay'])) { - $item['post-type'] = Item::PT_RELAY; + $item['post-reason'] = Item::PR_RELAY; } elseif (!empty($activity['thread-completion'])) { - $item['post-type'] = Item::PT_FETCHED; + $item['post-reason'] = Item::PR_FETCHED; } if ($item['isForum'] ?? false) { @@ -868,8 +963,9 @@ class Processor } $replyto = JsonLD::fetchElement($activity['as:object'], 'as:inReplyTo', '@id'); - if (Post::exists(['uri' => $replyto])) { - Logger::info('Post is a reply to an existing post - accepted', ['id' => $id, 'replyto' => $replyto]); + $uriid = ItemURI::getIdByURI($replyto); + if (Post::exists(['uri-id' => $uriid])) { + Logger::info('Post is a reply to an existing post - accepted', ['id' => $id, 'uri-id' => $uriid, 'replyto' => $replyto]); return true; } @@ -1142,7 +1238,7 @@ class Processor $implicit_mentions = []; if (empty($parent_author['url'])) { - Logger::notice('Author public contact unknown.', ['author-link' => $parent['author-link'], 'item-id' => $parent['id']]); + Logger::notice('Author public contact unknown.', ['author-link' => $parent['author-link'], 'parent-id' => $parent['id']]); } else { $implicit_mentions[] = $parent_author['url']; $implicit_mentions[] = $parent_author['nurl'];