]> git.mxchange.org Git - friendica.git/blob - src/Protocol/ActivityPub/Receiver.php
AP fixes: LD-signature, wrong owner for completed thres, account removal
[friendica.git] / src / Protocol / ActivityPub / Receiver.php
1 <?php
2 /**
3  * @file src/Protocol/ActivityPub/Receiver.php
4  */
5 namespace Friendica\Protocol\ActivityPub;
6
7 use Friendica\Database\DBA;
8 use Friendica\Util\HTTPSignature;
9 use Friendica\Core\Protocol;
10 use Friendica\Model\Contact;
11 use Friendica\Model\APContact;
12 use Friendica\Model\Item;
13 use Friendica\Model\User;
14 use Friendica\Util\JsonLD;
15 use Friendica\Util\LDSignature;
16 use Friendica\Protocol\ActivityPub;
17
18 /**
19  * @brief ActivityPub Receiver Protocol class
20  *
21  * To-Do:
22  * - Update (Image, Video, Article, Note)
23  * - Event
24  * - Undo Announce
25  *
26  * Check what this is meant to do:
27  * - Add
28  * - Block
29  * - Flag
30  * - Remove
31  * - Undo Block
32  * - Undo Accept (Problem: This could invert a contact accept or an event accept)
33  */
34 class Receiver
35 {
36         const PUBLIC_COLLECTION = 'as:Public';
37         const ACCOUNT_TYPES = ['as:Person', 'as:Organization', 'as:Service', 'as:Group', 'as:Application'];
38         const CONTENT_TYPES = ['as:Note', 'as:Article', 'as:Video', 'as:Image'];
39         const ACTIVITY_TYPES = ['as:Like', 'as:Dislike', 'as:Accept', 'as:Reject', 'as:TentativeAccept'];
40
41         /**
42          * Checks if the web request is done for the AP protocol
43          *
44          * @return is it AP?
45          */
46         public static function isRequest()
47         {
48                 return stristr(defaults($_SERVER, 'HTTP_ACCEPT', ''), 'application/activity+json') ||
49                         stristr(defaults($_SERVER, 'HTTP_ACCEPT', ''), 'application/ld+json');
50         }
51
52         /**
53          * Checks incoming message from the inbox
54          *
55          * @param $body
56          * @param $header
57          * @param integer $uid User ID
58          */
59         public static function processInbox($body, $header, $uid)
60         {
61                 $http_signer = HTTPSignature::getSigner($body, $header);
62                 if (empty($http_signer)) {
63                         logger('Invalid HTTP signature, message will be discarded.', LOGGER_DEBUG);
64                         return;
65                 } else {
66                         logger('HTTP signature is signed by ' . $http_signer, LOGGER_DEBUG);
67                 }
68
69                 $activity = json_decode($body, true);
70
71                 if (empty($activity)) {
72                         logger('Invalid body.', LOGGER_DEBUG);
73                         return;
74                 }
75
76                 $ldactivity = JsonLD::compact($activity);
77
78                 $actor = JsonLD::fetchElement($ldactivity, 'as:actor');
79
80                 logger('Message for user ' . $uid . ' is from actor ' . $actor, LOGGER_DEBUG);
81
82                 if (LDSignature::isSigned($activity)) {
83                         $ld_signer = LDSignature::getSigner($activity);
84                         if (empty($ld_signer)) {
85                                 logger('Invalid JSON-LD signature from ' . $actor, LOGGER_DEBUG);
86                         }
87                         if (!empty($ld_signer && ($actor == $http_signer))) {
88                                 logger('The HTTP and the JSON-LD signature belong to ' . $ld_signer, LOGGER_DEBUG);
89                                 $trust_source = true;
90                         } elseif (!empty($ld_signer)) {
91                                 logger('JSON-LD signature is signed by ' . $ld_signer, LOGGER_DEBUG);
92                                 $trust_source = true;
93                         } elseif ($actor == $http_signer) {
94                                 logger('Bad JSON-LD signature, but HTTP signer fits the actor.', LOGGER_DEBUG);
95                                 $trust_source = true;
96                         } else {
97                                 logger('Invalid JSON-LD signature and the HTTP signer is different.', LOGGER_DEBUG);
98                                 $trust_source = false;
99                         }
100                 } elseif ($actor == $http_signer) {
101                         logger('Trusting post without JSON-LD signature, The actor fits the HTTP signer.', LOGGER_DEBUG);
102                         $trust_source = true;
103                 } else {
104                         logger('No JSON-LD signature, different actor.', LOGGER_DEBUG);
105                         $trust_source = false;
106                 }
107
108                 self::processActivity($ldactivity, $body, $uid, $trust_source);
109         }
110
111         /**
112          * Fetches the object type for a given object id
113          *
114          * @param array  $activity
115          * @param string $object_id Object ID of the the provided object
116          *
117          * @return string with object type
118          */
119         private static function fetchObjectType($activity, $object_id)
120         {
121
122                 $object_type = JsonLD::fetchElement($activity['as:object'], '@type');
123                 if (!empty($object_type)) {
124                         return $object_type;
125                 }
126
127                 if (Item::exists(['uri' => $object_id, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT]])) {
128                         // We just assume "note" since it doesn't make a difference for the further processing
129                         return 'as:Note';
130                 }
131
132                 $profile = APContact::getByURL($object_id);
133                 if (!empty($profile['type'])) {
134                         return 'as:' . $profile['type'];
135                 }
136
137                 $data = ActivityPub::fetchContent($object_id);
138                 if (!empty($data)) {
139                         $object = JsonLD::compact($data);
140                         $type = JsonLD::fetchElement($object, '@type');
141                         if (!empty($type)) {
142                                 return $type;
143                         }
144                 }
145
146                 return null;
147         }
148
149         /**
150          * Prepare the object array
151          *
152          * @param array $activity
153          * @param integer $uid User ID
154          * @param $trust_source
155          *
156          * @return array with object data
157          */
158         private static function prepareObjectData($activity, $uid, &$trust_source)
159         {
160                 $actor = JsonLD::fetchElement($activity, 'as:actor');
161                 if (empty($actor)) {
162                         logger('Empty actor', LOGGER_DEBUG);
163                         return [];
164                 }
165
166                 $type = JsonLD::fetchElement($activity, '@type');
167
168                 // Fetch all receivers from to, cc, bto and bcc
169                 $receivers = self::getReceivers($activity, $actor);
170
171                 // When it is a delivery to a personal inbox we add that user to the receivers
172                 if (!empty($uid)) {
173                         $owner = User::getOwnerDataById($uid);
174                         $additional = ['uid:' . $uid => $uid];
175                         $receivers = array_merge($receivers, $additional);
176                 }
177
178                 logger('Receivers: ' . json_encode($receivers), LOGGER_DEBUG);
179
180                 $object_id = JsonLD::fetchElement($activity, 'as:object');
181                 if (empty($object_id)) {
182                         logger('No object found', LOGGER_DEBUG);
183                         return [];
184                 }
185
186                 $object_type = self::fetchObjectType($activity, $object_id);
187
188                 // Fetch the content only on activities where this matters
189                 if (in_array($type, ['as:Create', 'as:Announce'])) {
190                         if ($type == 'as:Announce') {
191                                 $trust_source = false;
192                         }
193                         $object_data = self::fetchObject($object_id, $activity['as:object'], $trust_source);
194                         if (empty($object_data)) {
195                                 logger("Object data couldn't be processed", LOGGER_DEBUG);
196                                 return [];
197                         }
198                         // We had been able to retrieve the object data - so we can trust the source
199                         $trust_source = true;
200                 } elseif (in_array($type, ['as:Like', 'as:Dislike'])) {
201                         // Create a mostly empty array out of the activity data (instead of the object).
202                         // This way we later don't have to check for the existence of ech individual array element.
203                         $object_data = self::processObject($activity);
204                         $object_data['name'] = $type;
205                         $object_data['author'] = JsonLD::fetchElement($activity, 'as:actor');
206                         $object_data['object_id'] = $object_id;
207                         $object_data['object_type'] = ''; // Since we don't fetch the object, we don't know the type
208                 } else {
209                         $object_data = [];
210                         $object_data['id'] = JsonLD::fetchElement($activity, '@id');
211                         $object_data['object_id'] = JsonLD::fetchElement($activity, 'as:object');
212                         $object_data['object_actor'] = JsonLD::fetchElement($activity['as:object'], 'as:actor');
213                         $object_data['object_object'] = JsonLD::fetchElement($activity['as:object'], 'as:object');
214                         $object_data['object_type'] = JsonLD::fetchElement($activity['as:object'], '@type');
215                 }
216
217                 $object_data = self::addActivityFields($object_data, $activity);
218
219                 if (empty($object_data['object_type'])) {
220                         $object_data['object_type'] = $object_type;
221                 }
222
223                 $object_data['type'] = $type;
224                 $object_data['actor'] = $actor;
225                 $object_data['receiver'] = array_merge(defaults($object_data, 'receiver', []), $receivers);
226
227                 logger('Processing ' . $object_data['type'] . ' ' . $object_data['object_type'] . ' ' . $object_data['id'], LOGGER_DEBUG);
228
229                 return $object_data;
230         }
231
232         /**
233          * Processes the activity object
234          *
235          * @param array   $activity     Array with activity data
236          * @param string  $body
237          * @param integer $uid          User ID
238          * @param boolean $trust_source Do we trust the source?
239          */
240         public static function processActivity($activity, $body = '', $uid = null, $trust_source = false)
241         {
242                 $type = JsonLD::fetchElement($activity, '@type');
243                 if (!$type) {
244                         logger('Empty type', LOGGER_DEBUG);
245                         return;
246                 }
247
248                 if (!JsonLD::fetchElement($activity, 'as:object')) {
249                         logger('Empty object', LOGGER_DEBUG);
250                         return;
251                 }
252
253                 if (!JsonLD::fetchElement($activity, 'as:actor')) {
254                         logger('Empty actor', LOGGER_DEBUG);
255                         return;
256
257                 }
258
259                 // $trust_source is called by reference and is set to true if the content was retrieved successfully
260                 $object_data = self::prepareObjectData($activity, $uid, $trust_source);
261                 if (empty($object_data)) {
262                         logger('No object data found', LOGGER_DEBUG);
263                         return;
264                 }
265
266                 if (!$trust_source) {
267                         logger('No trust for activity type "' . $type . '", so we quit now.', LOGGER_DEBUG);
268                         return;
269                 }
270
271                 // Internal flag for thread completion. See Processor.php
272                 if (!empty($activity['thread-completion'])) {
273                         $object_data['thread-completion'] = $activity['thread-completion'];
274                 }
275
276                 switch ($type) {
277                         case 'as:Create':
278                         case 'as:Announce':
279                                 ActivityPub\Processor::createItem($object_data, $body);
280                                 break;
281
282                         case 'as:Like':
283                                 ActivityPub\Processor::likeItem($object_data, $body);
284                                 break;
285
286                         case 'as:Dislike':
287                                 ActivityPub\Processor::dislikeItem($object_data, $body);
288                                 break;
289
290                         case 'as:Update':
291                                 if (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
292                                         /// @todo
293                                 } elseif (in_array($object_data['object_type'], self::ACCOUNT_TYPES)) {
294                                         ActivityPub\Processor::updatePerson($object_data, $body);
295                                 }
296                                 break;
297
298                         case 'as:Delete':
299                                 if ($object_data['object_type'] == 'as:Tombstone') {
300                                         ActivityPub\Processor::deleteItem($object_data, $body);
301                                 } elseif (in_array($object_data['object_type'], self::ACCOUNT_TYPES)) {
302                                         ActivityPub\Processor::deletePerson($object_data, $body);
303                                 }
304                                 break;
305
306                         case 'as:Follow':
307                                 ActivityPub\Processor::followUser($object_data);
308                                 break;
309
310                         case 'as:Accept':
311                                 if ($object_data['object_type'] == 'as:Follow') {
312                                         ActivityPub\Processor::acceptFollowUser($object_data);
313                                 }
314                                 break;
315
316                         case 'as:Reject':
317                                 if ($object_data['object_type'] == 'as:Follow') {
318                                         ActivityPub\Processor::rejectFollowUser($object_data);
319                                 }
320                                 break;
321
322                         case 'as:Undo':
323                                 if ($object_data['object_type'] == 'as:Follow') {
324                                         ActivityPub\Processor::undoFollowUser($object_data);
325                                 } elseif (in_array($object_data['object_type'], self::ACTIVITY_TYPES)) {
326                                         ActivityPub\Processor::undoActivity($object_data);
327                                 }
328                                 break;
329
330                         default:
331                                 logger('Unknown activity: ' . $type, LOGGER_DEBUG);
332                                 break;
333                 }
334         }
335
336         /**
337          * Fetch the receiver list from an activity array
338          *
339          * @param array $activity
340          * @param string $actor
341          *
342          * @return array with receivers (user id)
343          */
344         private static function getReceivers($activity, $actor)
345         {
346                 $receivers = [];
347
348                 // When it is an answer, we inherite the receivers from the parent
349                 $replyto = JsonLD::fetchElement($activity, 'as:inReplyTo');
350                 if (!empty($replyto)) {
351                         $parents = Item::select(['uid'], ['uri' => $replyto]);
352                         while ($parent = Item::fetch($parents)) {
353                                 $receivers['uid:' . $parent['uid']] = $parent['uid'];
354                         }
355                 }
356
357                 if (!empty($actor)) {
358                         $profile = APContact::getByURL($actor);
359                         $followers = defaults($profile, 'followers', '');
360
361                         logger('Actor: ' . $actor . ' - Followers: ' . $followers, LOGGER_DEBUG);
362                 } else {
363                         logger('Empty actor', LOGGER_DEBUG);
364                         $followers = '';
365                 }
366
367                 foreach (['as:to', 'as:cc', 'as:bto', 'as:bcc'] as $element) {
368                         $receiver_list = JsonLD::fetchElementArray($activity, $element);
369                         if (empty($receiver_list)) {
370                                 continue;
371                         }
372
373                         foreach ($receiver_list as $receiver) {
374                                 if ($receiver == self::PUBLIC_COLLECTION) {
375                                         $receivers['uid:0'] = 0;
376                                 }
377
378                                 if (($receiver == self::PUBLIC_COLLECTION) && !empty($actor)) {
379                                         // This will most likely catch all OStatus connections to Mastodon
380                                         $condition = ['alias' => [$actor, normalise_link($actor)], 'rel' => [Contact::SHARING, Contact::FRIEND]
381                                                 , 'archive' => false, 'pending' => false];
382                                         $contacts = DBA::select('contact', ['uid'], $condition);
383                                         while ($contact = DBA::fetch($contacts)) {
384                                                 if ($contact['uid'] != 0) {
385                                                         $receivers['uid:' . $contact['uid']] = $contact['uid'];
386                                                 }
387                                         }
388                                         DBA::close($contacts);
389                                 }
390
391                                 if (in_array($receiver, [$followers, self::PUBLIC_COLLECTION]) && !empty($actor)) {
392                                         $condition = ['nurl' => normalise_link($actor), 'rel' => [Contact::SHARING, Contact::FRIEND],
393                                                 'network' => Protocol::ACTIVITYPUB, 'archive' => false, 'pending' => false];
394                                         $contacts = DBA::select('contact', ['uid'], $condition);
395                                         while ($contact = DBA::fetch($contacts)) {
396                                                 if ($contact['uid'] != 0) {
397                                                         $receivers['uid:' . $contact['uid']] = $contact['uid'];
398                                                 }
399                                         }
400                                         DBA::close($contacts);
401                                         continue;
402                                 }
403
404                                 $condition = ['self' => true, 'nurl' => normalise_link($receiver)];
405                                 $contact = DBA::selectFirst('contact', ['uid'], $condition);
406                                 if (!DBA::isResult($contact)) {
407                                         continue;
408                                 }
409                                 $receivers['uid:' . $contact['uid']] = $contact['uid'];
410                         }
411                 }
412
413                 self::switchContacts($receivers, $actor);
414
415                 return $receivers;
416         }
417
418         /**
419          * Switches existing contacts to ActivityPub
420          *
421          * @param integer $cid Contact ID
422          * @param integer $uid User ID
423          * @param string $url Profile URL
424          */
425         private static function switchContact($cid, $uid, $url)
426         {
427                 $profile = ActivityPub::probeProfile($url);
428                 if (empty($profile)) {
429                         return;
430                 }
431
432                 logger('Switch contact ' . $cid . ' (' . $profile['url'] . ') for user ' . $uid . ' to ActivityPub');
433
434                 $photo = $profile['photo'];
435                 unset($profile['photo']);
436                 unset($profile['baseurl']);
437
438                 $profile['nurl'] = normalise_link($profile['url']);
439                 DBA::update('contact', $profile, ['id' => $cid]);
440
441                 Contact::updateAvatar($photo, $uid, $cid);
442
443                 // Send a new follow request to be sure that the connection still exists
444                 if (($uid != 0) && DBA::exists('contact', ['id' => $cid, 'rel' => [Contact::SHARING, Contact::FRIEND]])) {
445                         ActivityPub\Transmitter::sendActivity('Follow', $profile['url'], $uid);
446                         logger('Send a new follow request to ' . $profile['url'] . ' for user ' . $uid, LOGGER_DEBUG);
447                 }
448         }
449
450         /**
451          * 
452          *
453          * @param $receivers
454          * @param $actor
455          */
456         private static function switchContacts($receivers, $actor)
457         {
458                 if (empty($actor)) {
459                         return;
460                 }
461
462                 foreach ($receivers as $receiver) {
463                         $contact = DBA::selectFirst('contact', ['id'], ['uid' => $receiver, 'network' => Protocol::OSTATUS, 'nurl' => normalise_link($actor)]);
464                         if (DBA::isResult($contact)) {
465                                 self::switchContact($contact['id'], $receiver, $actor);
466                         }
467
468                         $contact = DBA::selectFirst('contact', ['id'], ['uid' => $receiver, 'network' => Protocol::OSTATUS, 'alias' => [normalise_link($actor), $actor]]);
469                         if (DBA::isResult($contact)) {
470                                 self::switchContact($contact['id'], $receiver, $actor);
471                         }
472                 }
473         }
474
475         /**
476          * 
477          *
478          * @param $object_data
479          * @param array $activity
480          *
481          * @return 
482          */
483         private static function addActivityFields($object_data, $activity)
484         {
485                 if (!empty($activity['published']) && empty($object_data['published'])) {
486                         $object_data['published'] = JsonLD::fetchElement($activity, 'published', '@value');
487                 }
488
489                 if (!empty($activity['updated']) && empty($object_data['updated'])) {
490                         $object_data['updated'] = JsonLD::fetchElement($activity, 'updated', '@value');
491                 }
492
493                 if (!empty($activity['diaspora:guid']) && empty($object_data['diaspora:guid'])) {
494                         $object_data['diaspora:guid'] = JsonLD::fetchElement($activity, 'diaspora:guid');
495                 }
496
497                 if (!empty($activity['inReplyTo']) && empty($object_data['parent-uri'])) {
498                         $object_data['parent-uri'] = JsonLD::fetchElement($activity, 'inReplyTo');
499                 }
500
501                 if (!empty($activity['instrument'])) {
502                         $object_data['service'] = JsonLD::fetchElement($activity, 'instrument', 'name', 'type', 'Service');
503                 }
504                 return $object_data;
505         }
506
507         /**
508          * Fetches the object data from external ressources if needed
509          *
510          * @param string  $object_id    Object ID of the the provided object
511          * @param array   $object       The provided object array
512          * @param boolean $trust_source Do we trust the provided object?
513          *
514          * @return array with trusted and valid object data
515          */
516         private static function fetchObject($object_id, $object = [], $trust_source = false)
517         {
518                 // By fetching the type we check if the object is complete.
519                 $type = JsonLD::fetchElement($object, '@type');
520
521                 if (!$trust_source || empty($type)) {
522                         $data = ActivityPub::fetchContent($object_id);
523                         if (!empty($data)) {
524                                 $object = JsonLD::compact($data);
525                                 logger('Fetched content for ' . $object_id, LOGGER_DEBUG);
526                         } else {
527                                 logger('Empty content for ' . $object_id . ', check if content is available locally.', LOGGER_DEBUG);
528
529                                 $item = Item::selectFirst([], ['uri' => $object_id]);
530                                 if (!DBA::isResult($item)) {
531                                         logger('Object with url ' . $object_id . ' was not found locally.', LOGGER_DEBUG);
532                                         return false;
533                                 }
534                                 logger('Using already stored item for url ' . $object_id, LOGGER_DEBUG);
535                                 $data = ActivityPub\Transmitter::createNote($item);
536                                 $object = JsonLD::compact($data);
537                         }
538                 } else {
539                         logger('Using original object for url ' . $object_id, LOGGER_DEBUG);
540                 }
541
542                 $type = JsonLD::fetchElement($object, '@type');
543
544                 if (empty($type)) {
545                         logger('Empty type', LOGGER_DEBUG);
546                         return false;
547                 }
548
549                 if (in_array($type, self::CONTENT_TYPES)) {
550                         return self::processObject($object);
551                 }
552
553                 if ($type == 'as:Announce') {
554                         $object_id = JsonLD::fetchElement($object, 'object');
555                         if (empty($object_id)) {
556                                 return false;
557                         }
558                         return self::fetchObject($object_id);
559                 }
560
561                 logger('Unhandled object type: ' . $type, LOGGER_DEBUG);
562         }
563
564         /**
565          * Convert tags from JSON-LD format into a simplified format
566          *
567          * @param array $tags Tags in JSON-LD format
568          *
569          * @return array with tags in a simplified format
570          */
571         private static function processTags($tags)
572         {
573                 $taglist = [];
574
575                 if (empty($tags)) {
576                         return [];
577                 }
578
579                 foreach ($tags as $tag) {
580                         if (empty($tag)) {
581                                 continue;
582                         }
583
584                         $taglist[] = ['type' => str_replace('as:', '', JsonLD::fetchElement($tag, '@type')),
585                                 'href' => JsonLD::fetchElement($tag, 'as:href'),
586                                 'name' => JsonLD::fetchElement($tag, 'as:name')];
587                 }
588                 return $taglist;
589         }
590
591         /**
592          * Convert attachments from JSON-LD format into a simplified format
593          *
594          * @param array $attachments Attachments in JSON-LD format
595          *
596          * @return array with attachmants in a simplified format
597          */
598         private static function processAttachments($attachments)
599         {
600                 $attachlist = [];
601
602                 if (empty($attachments)) {
603                         return [];
604                 }
605
606                 foreach ($attachments as $attachment) {
607                         if (empty($attachment)) {
608                                 continue;
609                         }
610
611                         $attachlist[] = ['type' => str_replace('as:', '', JsonLD::fetchElement($attachment, '@type')),
612                                 'mediaType' => JsonLD::fetchElement($attachment, 'as:mediaType'),
613                                 'name' => JsonLD::fetchElement($attachment, 'as:name'),
614                                 'url' => JsonLD::fetchElement($attachment, 'as:url')];
615                 }
616                 return $attachlist;
617         }
618
619         /**
620          * Fetches data from the object part of an activity
621          *
622          * @param array $object
623          *
624          * @return array
625          */
626         private static function processObject($object)
627         {
628                 if (!JsonLD::fetchElement($object, '@id')) {
629                         return false;
630                 }
631
632                 $object_data = [];
633                 $object_data['object_type'] = JsonLD::fetchElement($object, '@type');
634                 $object_data['id'] = JsonLD::fetchElement($object, '@id');
635
636                 $object_data['reply-to-id'] = JsonLD::fetchElement($object, 'as:inReplyTo');
637
638                 if (empty($object_data['reply-to-id'])) {
639                         $object_data['reply-to-id'] = $object_data['id'];
640                 }
641
642                 $object_data['published'] = JsonLD::fetchElement($object, 'as:published', '@value');
643                 $object_data['updated'] = JsonLD::fetchElement($object, 'as:updated', '@value');
644
645                 if (empty($object_data['updated'])) {
646                         $object_data['updated'] = $object_data['published'];
647                 }
648
649                 if (empty($object_data['published']) && !empty($object_data['updated'])) {
650                         $object_data['published'] = $object_data['updated'];
651                 }
652
653                 $actor = JsonLD::fetchElement($object, 'as:attributedTo');
654                 if (empty($actor)) {
655                         $actor = JsonLD::fetchElement($object, 'as:actor');
656                 }
657
658                 $object_data['diaspora:guid'] = JsonLD::fetchElement($object, 'diaspora:guid');
659                 $object_data['diaspora:comment'] = JsonLD::fetchElement($object, 'diaspora:comment');
660                 $object_data['actor'] = $object_data['author'] = $actor;
661                 $object_data['context'] = JsonLD::fetchElement($object, 'as:context');
662                 $object_data['conversation'] = JsonLD::fetchElement($object, 'ostatus:conversation');
663                 $object_data['sensitive'] = JsonLD::fetchElement($object, 'as:sensitive');
664                 $object_data['name'] = JsonLD::fetchElement($object, 'as:name');
665                 $object_data['summary'] = JsonLD::fetchElement($object, 'as:summary');
666                 $object_data['content'] = JsonLD::fetchElement($object, 'as:content');
667                 $object_data['source'] = JsonLD::fetchElement($object, 'as:source', 'as:content', 'as:mediaType', 'text/bbcode');
668                 $object_data['location'] = JsonLD::fetchElement($object, 'as:location', 'as:name', '@type', 'as:Place');
669                 $object_data['attachments'] = self::processAttachments(JsonLD::fetchElementArray($object, 'as:attachment'));
670                 $object_data['tags'] = self::processTags(JsonLD::fetchElementArray($object, 'as:tag'));
671 //              $object_data['service'] = JsonLD::fetchElement($object, 'instrument', 'name', 'type', 'Service'); // todo
672                 $object_data['service'] = null;
673                 $object_data['alternate-url'] = JsonLD::fetchElement($object, 'as:url');
674
675                 // Special treatment for Hubzilla links
676                 if (is_array($object_data['alternate-url'])) {
677                         if (!empty($object['as:url'])) {
678                                 $object_data['alternate-url'] = JsonLD::fetchElement($object['as:url'], 'as:href');
679                         } else {
680                                 $object_data['alternate-url'] = null;
681                         }
682                 }
683
684                 $object_data['receiver'] = self::getReceivers($object, $object_data['actor']);
685
686                 // Common object data:
687
688                 // Unhandled
689                 // @context, type, actor, signature, mediaType, duration, replies, icon
690
691                 // Also missing: (Defined in the standard, but currently unused)
692                 // audience, preview, endTime, startTime, generator, image
693
694                 // Data in Notes:
695
696                 // Unhandled
697                 // contentMap, announcement_count, announcements, context_id, likes, like_count
698                 // inReplyToStatusId, shares, quoteUrl, statusnetConversationId
699
700                 // Data in video:
701
702                 // To-Do?
703                 // category, licence, language, commentsEnabled
704
705                 // Unhandled
706                 // views, waitTranscoding, state, support, subtitleLanguage
707                 // likes, dislikes, shares, comments
708
709                 return $object_data;
710         }
711 }