3 * @copyright Copyright (C) 2010-2022, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Protocol\ActivityPub;
24 use Friendica\Content\Text\BBCode;
25 use Friendica\Database\DBA;
26 use Friendica\Content\Text\HTML;
27 use Friendica\Content\Text\Markdown;
28 use Friendica\Core\Logger;
29 use Friendica\Core\Protocol;
30 use Friendica\Model\Contact;
31 use Friendica\Model\APContact;
32 use Friendica\Model\Item;
33 use Friendica\Model\Post;
34 use Friendica\Model\User;
35 use Friendica\Protocol\Activity;
36 use Friendica\Protocol\ActivityPub;
37 use Friendica\Util\HTTPSignature;
38 use Friendica\Util\JsonLD;
39 use Friendica\Util\LDSignature;
40 use Friendica\Util\Strings;
43 * ActivityPub Receiver Protocol class
48 * Check what this is meant to do:
57 const PUBLIC_COLLECTION = 'as:Public';
58 const ACCOUNT_TYPES = ['as:Person', 'as:Organization', 'as:Service', 'as:Group', 'as:Application'];
59 const CONTENT_TYPES = ['as:Note', 'as:Article', 'as:Video', 'as:Image', 'as:Event', 'as:Audio', 'as:Page'];
60 const ACTIVITY_TYPES = ['as:Like', 'as:Dislike', 'as:Accept', 'as:Reject', 'as:TentativeAccept'];
62 const TARGET_UNKNOWN = 0;
67 const TARGET_FOLLOWER = 5;
68 const TARGET_ANSWER = 6;
69 const TARGET_GLOBAL = 7;
72 * Checks incoming message from the inbox
76 * @param integer $uid User ID
79 public static function processInbox($body, $header, $uid)
81 $activity = json_decode($body, true);
82 if (empty($activity)) {
83 Logger::warning('Invalid body.');
87 $ldactivity = JsonLD::compact($activity);
89 $actor = JsonLD::fetchElement($ldactivity, 'as:actor', '@id');
91 $apcontact = APContact::getByURL($actor);
92 if (empty($apcontact)) {
93 Logger::notice('Unable to retrieve AP contact for actor - message is discarded', ['actor' => $actor]);
95 } elseif ($apcontact['type'] == 'Application' && $apcontact['nick'] == 'relay') {
96 self::processRelayPost($ldactivity, $actor);
99 APContact::unmarkForArchival($apcontact);
102 $http_signer = HTTPSignature::getSigner($body, $header);
103 if ($http_signer === false) {
104 Logger::warning('Invalid HTTP signature, message will be discarded.');
106 } elseif (empty($http_signer)) {
107 Logger::info('Signer is a tombstone. The message will be discarded, the signer account is deleted.');
110 Logger::info('Valid HTTP signature', ['signer' => $http_signer]);
113 $signer = [$http_signer];
115 Logger::info('Message for user ' . $uid . ' is from actor ' . $actor);
117 if (LDSignature::isSigned($activity)) {
118 $ld_signer = LDSignature::getSigner($activity);
119 if (empty($ld_signer)) {
120 Logger::info('Invalid JSON-LD signature from ' . $actor);
121 } elseif ($ld_signer != $http_signer) {
122 $signer[] = $ld_signer;
124 if (!empty($ld_signer && ($actor == $http_signer))) {
125 Logger::info('The HTTP and the JSON-LD signature belong to ' . $ld_signer);
126 $trust_source = true;
127 } elseif (!empty($ld_signer)) {
128 Logger::info('JSON-LD signature is signed by ' . $ld_signer);
129 $trust_source = true;
130 } elseif ($actor == $http_signer) {
131 Logger::info('Bad JSON-LD signature, but HTTP signer fits the actor.');
132 $trust_source = true;
134 Logger::info('Invalid JSON-LD signature and the HTTP signer is different.');
135 $trust_source = false;
137 } elseif ($actor == $http_signer) {
138 Logger::info('Trusting post without JSON-LD signature, The actor fits the HTTP signer.');
139 $trust_source = true;
141 Logger::info('No JSON-LD signature, different actor.');
142 $trust_source = false;
145 self::processActivity($ldactivity, $body, $uid, $trust_source, true, $signer);
149 * Process incoming posts from relays
151 * @param array $activity
152 * @param string $actor
155 private static function processRelayPost(array $activity, string $actor)
157 $type = JsonLD::fetchElement($activity, '@type');
159 Logger::info('Empty type', ['activity' => $activity]);
163 if ($type != 'as:Announce') {
164 Logger::info('Not an announcement', ['activity' => $activity]);
168 $object_id = JsonLD::fetchElement($activity, 'as:object', '@id');
169 if (empty($object_id)) {
170 Logger::info('No object id found', ['activity' => $activity]);
174 $contact = Contact::getByURL($actor);
175 if (empty($contact)) {
176 Logger::info('Relay contact not found', ['actor' => $actor]);
180 if (!in_array($contact['rel'], [Contact::SHARING, Contact::FRIEND])) {
181 Logger::notice('Relay is no sharer', ['actor' => $actor]);
185 Logger::info('Got relayed message id', ['id' => $object_id]);
187 $item_id = Item::searchByLink($object_id);
189 Logger::info('Relayed message already exists', ['id' => $object_id, 'item' => $item_id]);
193 $id = Processor::fetchMissingActivity($object_id, [], $actor);
195 Logger::notice('Relayed message had not been fetched', ['id' => $object_id]);
199 $item_id = Item::searchByLink($object_id);
201 Logger::info('Relayed message had been fetched and stored', ['id' => $object_id, 'item' => $item_id]);
203 Logger::notice('Relayed message had not been stored', ['id' => $object_id]);
208 * Fetches the object type for a given object id
210 * @param array $activity
211 * @param string $object_id Object ID of the the provided object
212 * @param integer $uid User ID
214 * @return string with object type
215 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
216 * @throws \ImagickException
218 private static function fetchObjectType($activity, $object_id, $uid = 0)
220 if (!empty($activity['as:object'])) {
221 $object_type = JsonLD::fetchElement($activity['as:object'], '@type');
222 if (!empty($object_type)) {
227 if (Post::exists(['uri' => $object_id, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT]])) {
228 // We just assume "note" since it doesn't make a difference for the further processing
232 $profile = APContact::getByURL($object_id);
233 if (!empty($profile['type'])) {
234 APContact::unmarkForArchival($profile);
235 return 'as:' . $profile['type'];
238 $data = ActivityPub::fetchContent($object_id, $uid);
240 $object = JsonLD::compact($data);
241 $type = JsonLD::fetchElement($object, '@type');
251 * Prepare the object array
253 * @param array $activity Array with activity data
254 * @param integer $uid User ID
255 * @param boolean $push Message had been pushed to our system
256 * @param boolean $trust_source Do we trust the source?
258 * @return array with object data
259 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
260 * @throws \ImagickException
262 public static function prepareObjectData($activity, $uid, $push, &$trust_source)
264 $id = JsonLD::fetchElement($activity, '@id');
265 if (!empty($id) && !$trust_source) {
266 $fetched_activity = ActivityPub::fetchContent($id, $uid ?? 0);
267 if (!empty($fetched_activity)) {
268 $object = JsonLD::compact($fetched_activity);
269 $fetched_id = JsonLD::fetchElement($object, '@id');
270 if ($fetched_id == $id) {
271 Logger::info('Activity had been fetched successfully', ['id' => $id]);
272 $trust_source = true;
275 Logger::info('Activity id is not equal', ['id' => $id, 'fetched' => $fetched_id]);
278 Logger::info('Activity could not been fetched', ['id' => $id]);
282 $actor = JsonLD::fetchElement($activity, 'as:actor', '@id');
284 Logger::info('Empty actor', ['activity' => $activity]);
288 $type = JsonLD::fetchElement($activity, '@type');
290 // Fetch all receivers from to, cc, bto and bcc
291 $receiverdata = self::getReceivers($activity, $actor);
292 $receivers = $reception_types = [];
293 foreach ($receiverdata as $key => $data) {
294 $receivers[$key] = $data['uid'];
295 $reception_types[$data['uid']] = $data['type'] ?? self::TARGET_UNKNOWN;
298 // When it is a delivery to a personal inbox we add that user to the receivers
300 $additional = [$uid => $uid];
301 $receivers = array_replace($receivers, $additional);
302 if (empty($activity['thread-completion']) && (empty($reception_types[$uid]) || in_array($reception_types[$uid], [self::TARGET_UNKNOWN, self::TARGET_FOLLOWER, self::TARGET_ANSWER, self::TARGET_GLOBAL]))) {
303 $reception_types[$uid] = self::TARGET_BCC;
306 // We possibly need some user to fetch private content,
307 // so we fetch the first out ot the list.
308 $uid = self::getFirstUserFromReceivers($receivers);
311 $object_id = JsonLD::fetchElement($activity, 'as:object', '@id');
312 if (empty($object_id)) {
313 Logger::info('No object found');
317 if (!is_string($object_id)) {
318 Logger::info('Invalid object id', ['object' => $object_id]);
322 $object_type = self::fetchObjectType($activity, $object_id, $uid);
324 // Fetch the activity on Lemmy "Announce" messages (announces of activities)
325 if (($type == 'as:Announce') && in_array($object_type, self::ACTIVITY_TYPES)) {
326 $data = ActivityPub::fetchContent($object_id, $uid);
328 $type = $object_type;
329 $activity = JsonLD::compact($data);
331 // Some variables need to be refetched since the activity changed
332 $actor = JsonLD::fetchElement($activity, 'as:actor', '@id');
333 $object_id = JsonLD::fetchElement($activity, 'as:object', '@id');
334 $object_type = self::fetchObjectType($activity, $object_id, $uid);
338 // Fetch the content only on activities where this matters
339 // We can receive "#emojiReaction" when fetching content from Hubzilla systems
340 if (in_array($type, ['as:Create', 'as:Update', 'as:Announce']) || strpos($type, '#emojiReaction')) {
341 // Always fetch on "Announce"
342 $object_data = self::fetchObject($object_id, $activity['as:object'], $trust_source && ($type != 'as:Announce'), $uid);
343 if (empty($object_data)) {
344 Logger::info("Object data couldn't be processed");
348 $object_data['object_id'] = $object_id;
350 if ($type == 'as:Announce') {
351 $object_data['push'] = false;
353 $object_data['push'] = $push;
356 // Test if it is an answer to a mail
357 if (DBA::exists('mail', ['uri' => $object_data['reply-to-id']])) {
358 $object_data['directmessage'] = true;
360 $object_data['directmessage'] = JsonLD::fetchElement($activity, 'litepub:directMessage');
362 } elseif (in_array($type, array_merge(self::ACTIVITY_TYPES, ['as:Follow'])) && in_array($object_type, self::CONTENT_TYPES)) {
363 // Create a mostly empty array out of the activity data (instead of the object).
364 // This way we later don't have to check for the existence of ech individual array element.
365 $object_data = self::processObject($activity);
366 $object_data['name'] = $type;
367 $object_data['author'] = JsonLD::fetchElement($activity, 'as:actor', '@id');
368 $object_data['object_id'] = $object_id;
369 $object_data['object_type'] = ''; // Since we don't fetch the object, we don't know the type
370 $object_data['push'] = $push;
371 } elseif (in_array($type, ['as:Add'])) {
373 $object_data['id'] = JsonLD::fetchElement($activity, '@id');
374 $object_data['target_id'] = JsonLD::fetchElement($activity, 'as:target', '@id');
375 $object_data['object_id'] = JsonLD::fetchElement($activity, 'as:object', '@id');
376 $object_data['object_type'] = JsonLD::fetchElement($activity['as:object'], '@type');
377 $object_data['object_content'] = JsonLD::fetchElement($activity['as:object'], 'as:content', '@type');
378 $object_data['push'] = $push;
381 $object_data['id'] = JsonLD::fetchElement($activity, '@id');
382 $object_data['object_id'] = JsonLD::fetchElement($activity, 'as:object', '@id');
383 $object_data['object_actor'] = JsonLD::fetchElement($activity['as:object'], 'as:actor', '@id');
384 $object_data['object_object'] = JsonLD::fetchElement($activity['as:object'], 'as:object');
385 $object_data['object_type'] = JsonLD::fetchElement($activity['as:object'], '@type');
386 $object_data['push'] = $push;
388 // An Undo is done on the object of an object, so we need that type as well
389 if (($type == 'as:Undo') && !empty($object_data['object_object'])) {
390 $object_data['object_object_type'] = self::fetchObjectType([], $object_data['object_object'], $uid);
394 $object_data = self::addActivityFields($object_data, $activity);
396 if (empty($object_data['object_type'])) {
397 $object_data['object_type'] = $object_type;
400 $object_data['type'] = $type;
401 $object_data['actor'] = $actor;
402 $object_data['item_receiver'] = $receivers;
403 $object_data['receiver'] = array_replace($object_data['receiver'] ?? [], $receivers);
404 $object_data['reception_type'] = array_replace($object_data['reception_type'] ?? [], $reception_types);
406 $author = $object_data['author'] ?? $actor;
407 if (!empty($author) && !empty($object_data['id'])) {
408 $author_host = parse_url($author, PHP_URL_HOST);
409 $id_host = parse_url($object_data['id'], PHP_URL_HOST);
410 if ($author_host == $id_host) {
411 Logger::info('Valid hosts', ['type' => $type, 'host' => $id_host]);
413 Logger::notice('Differing hosts on author and id', ['type' => $type, 'author' => $author_host, 'id' => $id_host]);
414 $trust_source = false;
418 Logger::info('Processing ' . $object_data['type'] . ' ' . $object_data['object_type'] . ' ' . $object_data['id']);
424 * Fetches the first user id from the receiver array
426 * @param array $receivers Array with receivers
427 * @return integer user id;
429 public static function getFirstUserFromReceivers($receivers)
431 foreach ($receivers as $receiver) {
432 if (!empty($receiver)) {
440 * Processes the activity object
442 * @param array $activity Array with activity data
443 * @param string $body
444 * @param integer $uid User ID
445 * @param boolean $trust_source Do we trust the source?
446 * @param boolean $push Message had been pushed to our system
449 public static function processActivity($activity, string $body = '', int $uid = null, bool $trust_source = false, bool $push = false, array $signer = [])
451 $type = JsonLD::fetchElement($activity, '@type');
453 Logger::info('Empty type', ['activity' => $activity]);
457 if (!JsonLD::fetchElement($activity, 'as:object', '@id')) {
458 Logger::info('Empty object', ['activity' => $activity]);
462 $actor = JsonLD::fetchElement($activity, 'as:actor', '@id');
464 Logger::info('Empty actor', ['activity' => $activity]);
468 if (is_array($activity['as:object'])) {
469 $attributed_to = JsonLD::fetchElement($activity['as:object'], 'as:attributedTo', '@id');
474 // Test the provided signatures against the actor and "attributedTo"
476 if (!empty($attributed_to) && !empty($actor)) {
477 $trust_source = (in_array($actor, $signer) && in_array($attributed_to, $signer));
479 $trust_source = in_array($actor, $signer);
483 // $trust_source is called by reference and is set to true if the content was retrieved successfully
484 $object_data = self::prepareObjectData($activity, $uid, $push, $trust_source);
485 if (empty($object_data)) {
486 Logger::info('No object data found', ['activity' => $activity]);
490 // Lemmy is announcing activities.
491 // We are changing the announces into regular activities.
492 if (($type == 'as:Announce') && in_array($object_data['type'] ?? '', self::ACTIVITY_TYPES)) {
493 $type = $object_data['type'];
496 if (!$trust_source) {
497 Logger::info('Activity trust could not be achieved.', ['id' => $object_data['object_id'], 'type' => $type, 'signer' => $signer, 'actor' => $actor, 'attributedTo' => $attributed_to]);
501 if (!empty($body) && empty($object_data['raw'])) {
502 $object_data['raw'] = $body;
505 // Internal flag for thread completion. See Processor.php
506 if (!empty($activity['thread-completion'])) {
507 $object_data['thread-completion'] = $activity['thread-completion'];
510 // Internal flag for posts that arrived via relay
511 if (!empty($activity['from-relay'])) {
512 $object_data['from-relay'] = $activity['from-relay'];
517 if (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
518 $item = ActivityPub\Processor::createItem($object_data);
519 ActivityPub\Processor::postItem($object_data, $item);
524 if ($object_data['object_type'] == 'as:tag') {
525 ActivityPub\Processor::addTag($object_data);
530 if (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
531 $object_data['thread-completion'] = Contact::getIdForURL($actor);
533 $item = ActivityPub\Processor::createItem($object_data);
538 $item['post-reason'] = Item::PR_ANNOUNCEMENT;
539 ActivityPub\Processor::postItem($object_data, $item);
541 $announce_object_data = self::processObject($activity);
542 $announce_object_data['name'] = $type;
543 $announce_object_data['author'] = JsonLD::fetchElement($activity, 'as:actor', '@id');
544 $announce_object_data['object_id'] = $object_data['object_id'];
545 $announce_object_data['object_type'] = $object_data['object_type'];
546 $announce_object_data['push'] = $push;
549 $announce_object_data['raw'] = $body;
552 ActivityPub\Processor::createActivity($announce_object_data, Activity::ANNOUNCE);
557 if (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
558 ActivityPub\Processor::createActivity($object_data, Activity::LIKE);
563 if (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
564 ActivityPub\Processor::createActivity($object_data, Activity::DISLIKE);
568 case 'as:TentativeAccept':
569 if (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
570 ActivityPub\Processor::createActivity($object_data, Activity::ATTENDMAYBE);
575 if (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
576 ActivityPub\Processor::updateItem($object_data);
577 } elseif (in_array($object_data['object_type'], self::ACCOUNT_TYPES)) {
578 ActivityPub\Processor::updatePerson($object_data);
583 if ($object_data['object_type'] == 'as:Tombstone') {
584 ActivityPub\Processor::deleteItem($object_data);
585 } elseif (in_array($object_data['object_type'], self::ACCOUNT_TYPES)) {
586 ActivityPub\Processor::deletePerson($object_data);
591 if (in_array($object_data['object_type'], self::ACCOUNT_TYPES)) {
592 ActivityPub\Processor::followUser($object_data);
593 } elseif (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
594 $object_data['reply-to-id'] = $object_data['object_id'];
595 ActivityPub\Processor::createActivity($object_data, Activity::FOLLOW);
600 if ($object_data['object_type'] == 'as:Follow') {
601 ActivityPub\Processor::acceptFollowUser($object_data);
602 } elseif (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
603 ActivityPub\Processor::createActivity($object_data, Activity::ATTEND);
608 if ($object_data['object_type'] == 'as:Follow') {
609 ActivityPub\Processor::rejectFollowUser($object_data);
610 } elseif (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
611 ActivityPub\Processor::createActivity($object_data, Activity::ATTENDNO);
616 if (($object_data['object_type'] == 'as:Follow') &&
617 in_array($object_data['object_object_type'], self::ACCOUNT_TYPES)) {
618 ActivityPub\Processor::undoFollowUser($object_data);
619 } elseif (($object_data['object_type'] == 'as:Accept') &&
620 in_array($object_data['object_object_type'], self::ACCOUNT_TYPES)) {
621 ActivityPub\Processor::rejectFollowUser($object_data);
622 } elseif (in_array($object_data['object_type'], self::ACTIVITY_TYPES) &&
623 in_array($object_data['object_object_type'], self::CONTENT_TYPES)) {
624 ActivityPub\Processor::undoActivity($object_data);
629 Logger::info('Unknown activity: ' . $type . ' ' . $object_data['object_type']);
635 * Fetch the receiver list from an activity array
637 * @param array $activity
638 * @param string $actor
640 * @param boolean $fetch_unlisted
642 * @return array with receivers (user id)
645 private static function getReceivers($activity, $actor, $tags = [], $fetch_unlisted = false)
647 $reply = $receivers = [];
649 // When it is an answer, we inherite the receivers from the parent
650 $replyto = JsonLD::fetchElement($activity, 'as:inReplyTo', '@id');
651 if (!empty($replyto)) {
654 // Fix possibly wrong item URI (could be an answer to a plink uri)
655 $fixedReplyTo = Item::getURIByLink($replyto);
656 if (!empty($fixedReplyTo)) {
657 $reply[] = $fixedReplyTo;
661 // Fetch all posts that refer to the object id
662 $object_id = JsonLD::fetchElement($activity, 'as:object', '@id');
663 if (!empty($object_id)) {
664 $reply[] = $object_id;
667 if (!empty($reply)) {
668 $parents = Post::select(['uid'], ['uri' => $reply]);
669 while ($parent = Post::fetch($parents)) {
670 $receivers[$parent['uid']] = ['uid' => $parent['uid'], 'type' => self::TARGET_ANSWER];
672 DBA::close($parents);
675 if (!empty($actor)) {
676 $profile = APContact::getByURL($actor);
677 $followers = $profile['followers'] ?? '';
678 $is_forum = ($actor['type'] ?? '') == 'Group';
679 Logger::info('Got actor and followers', ['actor' => $actor, 'followers' => $followers]);
681 Logger::info('Empty actor', ['activity' => $activity]);
686 // We have to prevent false follower assumptions upon thread completions
687 $follower_target = empty($activity['thread-completion']) ? self::TARGET_FOLLOWER : self::TARGET_UNKNOWN;
689 foreach (['as:to', 'as:cc', 'as:bto', 'as:bcc'] as $element) {
690 $receiver_list = JsonLD::fetchElementArray($activity, $element, '@id');
691 if (empty($receiver_list)) {
695 foreach ($receiver_list as $receiver) {
696 if ($receiver == self::PUBLIC_COLLECTION) {
697 $receivers[0] = ['uid' => 0, 'type' => self::TARGET_GLOBAL];
700 // Add receiver "-1" for unlisted posts
701 if ($fetch_unlisted && ($receiver == self::PUBLIC_COLLECTION) && ($element == 'as:cc')) {
702 $receivers[-1] = ['uid' => -1, 'type' => self::TARGET_GLOBAL];
705 // Fetch the receivers for the public and the followers collection
706 if ((($receiver == $followers) || (($receiver == self::PUBLIC_COLLECTION) && !$is_forum)) && !empty($actor)) {
707 $receivers = self::getReceiverForActor($actor, $tags, $receivers, $follower_target);
711 // Fetching all directly addressed receivers
712 $condition = ['self' => true, 'nurl' => Strings::normaliseLink($receiver)];
713 $contact = DBA::selectFirst('contact', ['uid', 'contact-type'], $condition);
714 if (!DBA::isResult($contact)) {
718 // Check if the potential receiver is following the actor
719 // Exception: The receiver is targetted via "to" or this is a comment
720 if ((($element != 'as:to') && empty($replyto)) || ($contact['contact-type'] == Contact::TYPE_COMMUNITY)) {
721 $networks = Protocol::FEDERATED;
722 $condition = ['nurl' => Strings::normaliseLink($actor), 'rel' => [Contact::SHARING, Contact::FRIEND],
723 'network' => $networks, 'archive' => false, 'pending' => false, 'uid' => $contact['uid']];
725 // Forum posts are only accepted from forum contacts
726 if ($contact['contact-type'] == Contact::TYPE_COMMUNITY) {
727 $condition['rel'] = [Contact::SHARING, Contact::FRIEND, Contact::FOLLOWER];
730 if (!DBA::exists('contact', $condition)) {
735 $type = $receivers[$contact['uid']]['type'] ?? self::TARGET_UNKNOWN;
736 if (in_array($type, [self::TARGET_UNKNOWN, self::TARGET_FOLLOWER, self::TARGET_ANSWER, self::TARGET_GLOBAL])) {
739 $type = self::TARGET_TO;
742 $type = self::TARGET_CC;
745 $type = self::TARGET_BTO;
748 $type = self::TARGET_BCC;
752 $receivers[$contact['uid']] = ['uid' => $contact['uid'], 'type' => $type];
757 self::switchContacts($receivers, $actor);
763 * Fetch the receiver list of a given actor
765 * @param string $actor
767 * @param array $receivers
768 * @param integer $target_type
770 * @return array with receivers (user id)
773 private static function getReceiverForActor($actor, $tags, $receivers, $target_type)
775 $basecondition = ['rel' => [Contact::SHARING, Contact::FRIEND, Contact::FOLLOWER],
776 'network' => Protocol::FEDERATED, 'archive' => false, 'pending' => false];
778 $condition = DBA::mergeConditions($basecondition, ["`nurl` = ? AND `uid` != ?", Strings::normaliseLink($actor), 0]);
779 $contacts = DBA::select('contact', ['uid', 'rel'], $condition);
780 while ($contact = DBA::fetch($contacts)) {
781 if (empty($receivers[$contact['uid']]) && self::isValidReceiverForActor($contact, $tags)) {
782 $receivers[$contact['uid']] = ['uid' => $contact['uid'], 'type' => $target_type];
785 DBA::close($contacts);
787 // The queries are split because of performance issues
788 $condition = DBA::mergeConditions($basecondition, ["`alias` IN (?, ?) AND `uid` != ?", Strings::normaliseLink($actor), $actor, 0]);
789 $contacts = DBA::select('contact', ['uid', 'rel'], $condition);
790 while ($contact = DBA::fetch($contacts)) {
791 if (empty($receivers[$contact['uid']]) && self::isValidReceiverForActor($contact, $tags)) {
792 $receivers[$contact['uid']] = ['uid' => $contact['uid'], 'type' => $target_type];
795 DBA::close($contacts);
800 * Tests if the contact is a valid receiver for this actor
802 * @param array $contact
803 * @param string $actor
806 * @return bool with receivers (user id)
809 private static function isValidReceiverForActor($contact, $tags)
811 // Are we following the contact? Then this is a valid receiver
812 if (in_array($contact['rel'], [Contact::SHARING, Contact::FRIEND])) {
816 // When the possible receiver isn't a community, then it is no valid receiver
817 $owner = User::getOwnerDataById($contact['uid']);
818 if (empty($owner) || ($owner['contact-type'] != Contact::TYPE_COMMUNITY)) {
822 // Is the community account tagged?
823 foreach ($tags as $tag) {
824 if ($tag['type'] != 'Mention') {
828 if (Strings::compareLink($tag['href'], $owner['url'])) {
837 * Switches existing contacts to ActivityPub
839 * @param integer $cid Contact ID
840 * @param integer $uid User ID
841 * @param string $url Profile URL
842 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
843 * @throws \ImagickException
845 public static function switchContact($cid, $uid, $url)
847 if (DBA::exists('contact', ['id' => $cid, 'network' => Protocol::ACTIVITYPUB])) {
848 Logger::info('Contact is already ActivityPub', ['id' => $cid, 'uid' => $uid, 'url' => $url]);
852 if (Contact::updateFromProbe($cid)) {
853 Logger::info('Update was successful', ['id' => $cid, 'uid' => $uid, 'url' => $url]);
856 // Send a new follow request to be sure that the connection still exists
857 if (($uid != 0) && DBA::exists('contact', ['id' => $cid, 'rel' => [Contact::SHARING, Contact::FRIEND], 'network' => Protocol::ACTIVITYPUB])) {
858 Logger::info('Contact had been switched to ActivityPub. Sending a new follow request.', ['uid' => $uid, 'url' => $url]);
859 ActivityPub\Transmitter::sendActivity('Follow', $url, $uid);
868 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
869 * @throws \ImagickException
871 private static function switchContacts($receivers, $actor)
877 foreach ($receivers as $receiver) {
878 $contact = DBA::selectFirst('contact', ['id'], ['uid' => $receiver['uid'], 'network' => Protocol::OSTATUS, 'nurl' => Strings::normaliseLink($actor)]);
879 if (DBA::isResult($contact)) {
880 self::switchContact($contact['id'], $receiver['uid'], $actor);
883 $contact = DBA::selectFirst('contact', ['id'], ['uid' => $receiver['uid'], 'network' => Protocol::OSTATUS, 'alias' => [Strings::normaliseLink($actor), $actor]]);
884 if (DBA::isResult($contact)) {
885 self::switchContact($contact['id'], $receiver['uid'], $actor);
893 * @param $object_data
894 * @param array $activity
898 private static function addActivityFields($object_data, $activity)
900 if (!empty($activity['published']) && empty($object_data['published'])) {
901 $object_data['published'] = JsonLD::fetchElement($activity, 'as:published', '@value');
904 if (!empty($activity['diaspora:guid']) && empty($object_data['diaspora:guid'])) {
905 $object_data['diaspora:guid'] = JsonLD::fetchElement($activity, 'diaspora:guid', '@value');
908 $object_data['service'] = JsonLD::fetchElement($activity, 'as:instrument', 'as:name', '@type', 'as:Service');
909 $object_data['service'] = JsonLD::fetchElement($object_data, 'service', '@value');
911 if (!empty($object_data['object_id'])) {
912 // Some systems (e.g. GNU Social) don't reply to the "id" field but the "uri" field.
913 $objectId = Item::getURIByLink($object_data['object_id']);
914 if (!empty($objectId) && ($object_data['object_id'] != $objectId)) {
915 Logger::notice('Fix wrong object-id', ['received' => $object_data['object_id'], 'correct' => $objectId]);
916 $object_data['object_id'] = $objectId;
924 * Fetches the object data from external ressources if needed
926 * @param string $object_id Object ID of the the provided object
927 * @param array $object The provided object array
928 * @param boolean $trust_source Do we trust the provided object?
929 * @param integer $uid User ID for the signature that we use to fetch data
931 * @return array|false with trusted and valid object data
932 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
933 * @throws \ImagickException
935 private static function fetchObject(string $object_id, array $object = [], bool $trust_source = false, int $uid = 0)
937 // By fetching the type we check if the object is complete.
938 $type = JsonLD::fetchElement($object, '@type');
940 if (!$trust_source || empty($type)) {
941 $data = ActivityPub::fetchContent($object_id, $uid);
943 $object = JsonLD::compact($data);
944 Logger::info('Fetched content for ' . $object_id);
946 Logger::info('Empty content for ' . $object_id . ', check if content is available locally.');
948 $item = Post::selectFirst(Item::DELIVER_FIELDLIST, ['uri' => $object_id]);
949 if (!DBA::isResult($item)) {
950 Logger::info('Object with url ' . $object_id . ' was not found locally.');
953 Logger::info('Using already stored item for url ' . $object_id);
954 $data = ActivityPub\Transmitter::createNote($item);
955 $object = JsonLD::compact($data);
958 $id = JsonLD::fetchElement($object, '@id');
960 Logger::info('Empty id');
964 if ($id != $object_id) {
965 Logger::info('Fetched id differs from provided id', ['provided' => $object_id, 'fetched' => $id]);
969 Logger::info('Using original object for url ' . $object_id);
972 $type = JsonLD::fetchElement($object, '@type');
974 Logger::info('Empty type');
978 // Lemmy is resharing "create" activities instead of content
979 // We fetch the content from the activity.
980 if (in_array($type, ['as:Create'])) {
981 $object = $object['as:object'];
982 $type = JsonLD::fetchElement($object, '@type');
984 Logger::info('Empty type');
987 $object_data = self::processObject($object);
990 // We currently don't handle 'pt:CacheFile', but with this step we avoid logging
991 if (in_array($type, self::CONTENT_TYPES) || ($type == 'pt:CacheFile')) {
992 $object_data = self::processObject($object);
995 $object_data['raw'] = json_encode($data);
1000 if ($type == 'as:Announce') {
1001 $object_id = JsonLD::fetchElement($object, 'object', '@id');
1002 if (empty($object_id) || !is_string($object_id)) {
1005 return self::fetchObject($object_id, [], false, $uid);
1008 Logger::info('Unhandled object type: ' . $type);
1013 * Converts the language element (Used by Peertube)
1015 * @param array $languages
1016 * @return array Languages
1018 public static function processLanguages(array $languages)
1020 if (empty($languages)) {
1024 $language_list = [];
1026 foreach ($languages as $language) {
1027 if (!empty($language['_:identifier']) && !empty($language['as:name'])) {
1028 $language_list[$language['_:identifier']] = $language['as:name'];
1031 return $language_list;
1035 * Convert tags from JSON-LD format into a simplified format
1037 * @param array $tags Tags in JSON-LD format
1039 * @return array with tags in a simplified format
1041 public static function processTags(array $tags)
1045 foreach ($tags as $tag) {
1050 $element = ['type' => str_replace('as:', '', JsonLD::fetchElement($tag, '@type')),
1051 'href' => JsonLD::fetchElement($tag, 'as:href', '@id'),
1052 'name' => JsonLD::fetchElement($tag, 'as:name', '@value')];
1054 if (empty($element['type'])) {
1058 if (empty($element['href'])) {
1059 $element['href'] = $element['name'];
1062 $taglist[] = $element;
1068 * Convert emojis from JSON-LD format into a simplified format
1070 * @param array $emojis
1071 * @return array with emojis in a simplified format
1073 private static function processEmojis(array $emojis)
1077 foreach ($emojis as $emoji) {
1078 if (empty($emoji) || (JsonLD::fetchElement($emoji, '@type') != 'toot:Emoji') || empty($emoji['as:icon'])) {
1082 $url = JsonLD::fetchElement($emoji['as:icon'], 'as:url', '@id');
1083 $element = ['name' => JsonLD::fetchElement($emoji, 'as:name', '@value'),
1086 $emojilist[] = $element;
1093 * Convert attachments from JSON-LD format into a simplified format
1095 * @param array $attachments Attachments in JSON-LD format
1097 * @return array Attachments in a simplified format
1099 private static function processAttachments(array $attachments)
1103 // Removes empty values
1104 $attachments = array_filter($attachments);
1106 foreach ($attachments as $attachment) {
1107 switch (JsonLD::fetchElement($attachment, '@type')) {
1112 $urls = JsonLD::fetchElementArray($attachment, 'as:url');
1113 foreach ($urls as $url) {
1114 // Single scalar URL case
1115 if (is_string($url)) {
1120 $href = JsonLD::fetchElement($url, 'as:href', '@id');
1121 $mediaType = JsonLD::fetchElement($url, 'as:mediaType', '@value');
1122 if (Strings::startsWith($mediaType, 'image')) {
1131 'title' => JsonLD::fetchElement($attachment, 'as:name', '@value'),
1132 'desc' => JsonLD::fetchElement($attachment, 'as:summary', '@value'),
1134 'image' => $pageImage,
1138 $mediaType = JsonLD::fetchElement($attachment, 'as:mediaType', '@value');
1139 $imageFullUrl = JsonLD::fetchElement($attachment, 'as:url', '@id');
1140 $imagePreviewUrl = null;
1142 if (!$imageFullUrl && ($urls = JsonLD::fetchElementArray($attachment, 'as:url'))) {
1143 $imageVariants = [];
1144 $previewVariants = [];
1145 foreach ($urls as $url) {
1146 // Scalar URL, no discrimination possible
1147 if (is_string($url)) {
1148 $imageFullUrl = $url;
1152 // Not sure what to do with a different Link media type than the base Image, we skip
1153 if ($mediaType != JsonLD::fetchElement($url, 'as:mediaType', '@value')) {
1157 $href = JsonLD::fetchElement($url, 'as:href', '@id');
1159 // Default URL choice if no discriminating width is provided
1160 $imageFullUrl = $href ?? $imageFullUrl;
1162 $width = intval(JsonLD::fetchElement($url, 'as:width', '@value') ?? 1);
1164 if ($href && $width) {
1165 $imageVariants[$width] = $href;
1166 // 632 is the ideal width for full screen frio posts, we compute the absolute distance to it
1167 $previewVariants[abs(632 - $width)] = $href;
1171 if ($imageVariants) {
1172 // Taking the maximum size image
1173 ksort($imageVariants);
1174 $imageFullUrl = array_pop($imageVariants);
1176 // Taking the minimum number distance to the target distance
1177 ksort($previewVariants);
1178 $imagePreviewUrl = array_shift($previewVariants);
1181 unset($imageVariants);
1182 unset($previewVariants);
1186 'type' => str_replace('as:', '', JsonLD::fetchElement($attachment, '@type')),
1187 'mediaType' => $mediaType,
1188 'name' => JsonLD::fetchElement($attachment, 'as:name', '@value'),
1189 'url' => $imageFullUrl,
1190 'image' => $imagePreviewUrl !== $imageFullUrl ? $imagePreviewUrl : null,
1195 'type' => str_replace('as:', '', JsonLD::fetchElement($attachment, '@type')),
1196 'mediaType' => JsonLD::fetchElement($attachment, 'as:mediaType', '@value'),
1197 'name' => JsonLD::fetchElement($attachment, 'as:name', '@value'),
1198 'url' => JsonLD::fetchElement($attachment, 'as:url', '@id'),
1199 'height' => JsonLD::fetchElement($attachment, 'as:height', '@value'),
1200 'width' => JsonLD::fetchElement($attachment, 'as:width', '@value'),
1201 'image' => JsonLD::fetchElement($attachment, 'as:image', '@id')
1210 * Fetch the original source or content with the "language" Markdown or HTML
1212 * @param array $object
1213 * @param array $object_data
1216 * @throws \Exception
1218 private static function getSource($object, $object_data)
1220 $object_data['source'] = JsonLD::fetchElement($object, 'as:source', 'as:content', 'as:mediaType', 'text/bbcode');
1221 $object_data['source'] = JsonLD::fetchElement($object_data, 'source', '@value');
1222 if (!empty($object_data['source'])) {
1223 return $object_data;
1226 $object_data['source'] = JsonLD::fetchElement($object, 'as:source', 'as:content', 'as:mediaType', 'text/markdown');
1227 $object_data['source'] = JsonLD::fetchElement($object_data, 'source', '@value');
1228 if (!empty($object_data['source'])) {
1229 $object_data['source'] = Markdown::toBBCode($object_data['source']);
1230 return $object_data;
1233 $object_data['source'] = JsonLD::fetchElement($object, 'as:source', 'as:content', 'as:mediaType', 'text/html');
1234 $object_data['source'] = JsonLD::fetchElement($object_data, 'source', '@value');
1235 if (!empty($object_data['source'])) {
1236 $object_data['source'] = HTML::toBBCode($object_data['source']);
1237 return $object_data;
1240 return $object_data;
1244 * Extracts a potential alternate URL from a list of additional URL elements
1246 * @param array $urls
1249 private static function extractAlternateUrl(array $urls): string
1252 foreach ($urls as $key => $url) {
1253 // Not a list but a single URL element
1254 if (!is_numeric($key)) {
1258 if (empty($url['@type']) || ($url['@type'] != 'as:Link')) {
1262 $href = JsonLD::fetchElement($url, 'as:href', '@id');
1267 $mediatype = JsonLD::fetchElement($url, 'as:mediaType');
1268 if (empty($mediatype)) {
1272 if ($mediatype == 'text/html') {
1273 $alternateUrl = $href;
1277 return $alternateUrl;
1281 * Check if the "as:url" element is an array with multiple links
1282 * This is the case with audio and video posts.
1283 * Then the links are added as attachments
1285 * @param array $urls The object URL list
1286 * @return array an array of attachments
1288 private static function processAttachmentUrls(array $urls): array
1291 foreach ($urls as $key => $url) {
1292 // Not a list but a single URL element
1293 if (!is_numeric($key)) {
1297 if (empty($url['@type']) || ($url['@type'] != 'as:Link')) {
1301 $href = JsonLD::fetchElement($url, 'as:href', '@id');
1306 $mediatype = JsonLD::fetchElement($url, 'as:mediaType');
1307 if (empty($mediatype)) {
1311 $filetype = strtolower(substr($mediatype, 0, strpos($mediatype, '/')));
1313 if ($filetype == 'audio') {
1314 $attachments[] = ['type' => $filetype, 'mediaType' => $mediatype, 'url' => $href, 'height' => null, 'size' => null, 'name' => ''];
1315 } elseif ($filetype == 'video') {
1316 $height = (int)JsonLD::fetchElement($url, 'as:height', '@value');
1317 // PeerTube audio-only track
1318 if ($height === 0) {
1322 $size = (int)JsonLD::fetchElement($url, 'pt:size', '@value');
1323 $attachments[] = ['type' => $filetype, 'mediaType' => $mediatype, 'url' => $href, 'height' => $height, 'size' => $size, 'name' => ''];
1324 } elseif (in_array($mediatype, ['application/x-bittorrent', 'application/x-bittorrent;x-scheme-handler/magnet'])) {
1325 $height = (int)JsonLD::fetchElement($url, 'as:height', '@value');
1327 // For Torrent links we always store the highest resolution
1328 if (!empty($attachments[$mediatype]['height']) && ($height < $attachments[$mediatype]['height'])) {
1332 $attachments[$mediatype] = ['type' => $mediatype, 'mediaType' => $mediatype, 'url' => $href, 'height' => $height, 'size' => null, 'name' => ''];
1333 } elseif ($mediatype == 'application/x-mpegURL') {
1334 // PeerTube exception, actual video link is in the tags of this URL element
1335 $attachments = array_merge($attachments, self::processAttachmentUrls($url['as:tag']));
1339 return array_values($attachments);
1343 * Fetches data from the object part of an activity
1345 * @param array $object
1348 * @throws \Exception
1350 private static function processObject($object)
1352 if (!JsonLD::fetchElement($object, '@id')) {
1357 $object_data['object_type'] = JsonLD::fetchElement($object, '@type');
1358 $object_data['id'] = JsonLD::fetchElement($object, '@id');
1359 $object_data['reply-to-id'] = JsonLD::fetchElement($object, 'as:inReplyTo', '@id');
1361 // An empty "id" field is translated to "./" by the compactor, so we have to check for this content
1362 if (empty($object_data['reply-to-id']) || ($object_data['reply-to-id'] == './')) {
1363 $object_data['reply-to-id'] = $object_data['id'];
1365 // On activities the "reply to" is the id of the object it refers to
1366 if (in_array($object_data['object_type'], self::ACTIVITY_TYPES)) {
1367 $object_id = JsonLD::fetchElement($object, 'as:object', '@id');
1368 if (!empty($object_id)) {
1369 $object_data['reply-to-id'] = $object_id;
1373 // Some systems (e.g. GNU Social) don't reply to the "id" field but the "uri" field.
1374 $replyToId = Item::getURIByLink($object_data['reply-to-id']);
1375 if (!empty($replyToId) && ($object_data['reply-to-id'] != $replyToId)) {
1376 Logger::notice('Fix wrong reply-to', ['received' => $object_data['reply-to-id'], 'correct' => $replyToId]);
1377 $object_data['reply-to-id'] = $replyToId;
1381 $object_data['published'] = JsonLD::fetchElement($object, 'as:published', '@value');
1382 $object_data['updated'] = JsonLD::fetchElement($object, 'as:updated', '@value');
1384 if (empty($object_data['updated'])) {
1385 $object_data['updated'] = $object_data['published'];
1388 if (empty($object_data['published']) && !empty($object_data['updated'])) {
1389 $object_data['published'] = $object_data['updated'];
1392 $actor = JsonLD::fetchElement($object, 'as:attributedTo', '@id');
1393 if (empty($actor)) {
1394 $actor = JsonLD::fetchElement($object, 'as:actor', '@id');
1397 $location = JsonLD::fetchElement($object, 'as:location', 'as:name', '@type', 'as:Place');
1398 $location = JsonLD::fetchElement($location, 'location', '@value');
1400 // Some AP software allow formatted text in post location, so we run all the text converters we have to boil
1401 // down to HTML and then finally format to plaintext.
1402 $location = Markdown::convert($location);
1403 $location = BBCode::toPlaintext($location);
1406 $object_data['sc:identifier'] = JsonLD::fetchElement($object, 'sc:identifier', '@value');
1407 $object_data['diaspora:guid'] = JsonLD::fetchElement($object, 'diaspora:guid', '@value');
1408 $object_data['diaspora:comment'] = JsonLD::fetchElement($object, 'diaspora:comment', '@value');
1409 $object_data['diaspora:like'] = JsonLD::fetchElement($object, 'diaspora:like', '@value');
1410 $object_data['actor'] = $object_data['author'] = $actor;
1411 $object_data['context'] = JsonLD::fetchElement($object, 'as:context', '@id');
1412 $object_data['conversation'] = JsonLD::fetchElement($object, 'ostatus:conversation', '@id');
1413 $object_data['sensitive'] = JsonLD::fetchElement($object, 'as:sensitive');
1414 $object_data['name'] = JsonLD::fetchElement($object, 'as:name', '@value');
1415 $object_data['summary'] = JsonLD::fetchElement($object, 'as:summary', '@value');
1416 $object_data['content'] = JsonLD::fetchElement($object, 'as:content', '@value');
1417 $object_data['mediatype'] = JsonLD::fetchElement($object, 'as:mediaType', '@value');
1418 $object_data = self::getSource($object, $object_data);
1419 $object_data['start-time'] = JsonLD::fetchElement($object, 'as:startTime', '@value');
1420 $object_data['end-time'] = JsonLD::fetchElement($object, 'as:endTime', '@value');
1421 $object_data['location'] = $location;
1422 $object_data['latitude'] = JsonLD::fetchElement($object, 'as:location', 'as:latitude', '@type', 'as:Place');
1423 $object_data['latitude'] = JsonLD::fetchElement($object_data, 'latitude', '@value');
1424 $object_data['longitude'] = JsonLD::fetchElement($object, 'as:location', 'as:longitude', '@type', 'as:Place');
1425 $object_data['longitude'] = JsonLD::fetchElement($object_data, 'longitude', '@value');
1426 $object_data['attachments'] = self::processAttachments(JsonLD::fetchElementArray($object, 'as:attachment') ?? []);
1427 $object_data['tags'] = self::processTags(JsonLD::fetchElementArray($object, 'as:tag') ?? []);
1428 $object_data['emojis'] = self::processEmojis(JsonLD::fetchElementArray($object, 'as:tag', null, '@type', 'toot:Emoji') ?? []);
1429 $object_data['languages'] = self::processLanguages(JsonLD::fetchElementArray($object, 'sc:inLanguage') ?? []);
1430 $object_data['generator'] = JsonLD::fetchElement($object, 'as:generator', 'as:name', '@type', 'as:Application');
1431 $object_data['generator'] = JsonLD::fetchElement($object_data, 'generator', '@value');
1432 $object_data['alternate-url'] = JsonLD::fetchElement($object, 'as:url', '@id');
1434 // Special treatment for Hubzilla links
1435 if (is_array($object_data['alternate-url'])) {
1436 $object_data['alternate-url'] = JsonLD::fetchElement($object_data['alternate-url'], 'as:href', '@id');
1438 if (!is_string($object_data['alternate-url'])) {
1439 $object_data['alternate-url'] = JsonLD::fetchElement($object['as:url'], 'as:href', '@id');
1443 if (in_array($object_data['object_type'], ['as:Audio', 'as:Video'])) {
1444 $object_data['alternate-url'] = self::extractAlternateUrl($object['as:url'] ?? []) ?: $object_data['alternate-url'];
1445 $object_data['attachments'] = array_merge($object_data['attachments'], self::processAttachmentUrls($object['as:url'] ?? []));
1448 $receiverdata = self::getReceivers($object, $object_data['actor'], $object_data['tags'], true);
1449 $receivers = $reception_types = [];
1450 foreach ($receiverdata as $key => $data) {
1451 $receivers[$key] = $data['uid'];
1452 $reception_types[$data['uid']] = $data['type'] ?? 0;
1455 $object_data['receiver'] = $receivers;
1456 $object_data['reception_type'] = $reception_types;
1458 $object_data['unlisted'] = in_array(-1, $object_data['receiver']);
1459 unset($object_data['receiver'][-1]);
1460 unset($object_data['reception_type'][-1]);
1462 // Common object data:
1465 // @context, type, actor, signature, mediaType, duration, replies, icon
1467 // Also missing: (Defined in the standard, but currently unused)
1468 // audience, preview, endTime, startTime, image
1473 // contentMap, announcement_count, announcements, context_id, likes, like_count
1474 // inReplyToStatusId, shares, quoteUrl, statusnetConversationId
1479 // category, licence, language, commentsEnabled
1482 // views, waitTranscoding, state, support, subtitleLanguage
1483 // likes, dislikes, shares, comments
1485 return $object_data;