3 * @file src/Protocol/ActivityPub.php
5 namespace Friendica\Protocol;
7 use Friendica\Database\DBA;
8 use Friendica\Core\System;
9 use Friendica\BaseObject;
10 use Friendica\Util\Network;
11 use Friendica\Util\HTTPSignature;
12 use Friendica\Core\Protocol;
13 use Friendica\Model\Conversation;
14 use Friendica\Model\Contact;
15 use Friendica\Model\Item;
16 use Friendica\Model\User;
17 use Friendica\Util\DateTimeFormat;
18 use Friendica\Util\Crypto;
19 use Friendica\Content\Text\BBCode;
20 use Friendica\Content\Text\HTML;
21 use Friendica\Network\Probe;
24 * @brief ActivityPub Protocol class
25 * The ActivityPub Protocol is a message exchange protocol defined by the W3C.
26 * https://www.w3.org/TR/activitypub/
27 * https://www.w3.org/TR/activitystreams-core/
28 * https://www.w3.org/TR/activitystreams-vocabulary/
30 * https://blog.joinmastodon.org/2018/06/how-to-implement-a-basic-activitypub-server/
31 * https://blog.joinmastodon.org/2018/07/how-to-make-friends-and-verify-requests/
33 * Digest: https://tools.ietf.org/html/rfc5843
34 * https://tools.ietf.org/html/draft-cavage-http-signatures-10#ref-15
38 const PUBLIC = 'https://www.w3.org/ns/activitystreams#Public';
40 public static function transmit($content, $target, $uid)
42 $owner = User::getOwnerDataById($uid);
48 $host = parse_url($target, PHP_URL_HOST);
49 $path = parse_url($target, PHP_URL_PATH);
52 $headers = ['Host: ' . $host, 'Date: ' . $date];
54 $signed_data = "(request-target): post " . $path . "\nhost: " . $host . "\ndate: " . $date;
56 $signature = base64_encode(Crypto::rsaSign($signed_data, $owner['uprvkey'], 'sha256'));
58 $headers[] = 'Signature: keyId="' . $owner['url'] . '#main-key' . '",headers="(request-target) host date",signature="' . $signature . '"';
59 $headers[] = 'Content-Type: application/activity+json';
61 Network::post($target, $content, $headers);
62 $return_code = BaseObject::getApp()->get_curl_code();
64 echo $return_code."\n";
68 * Return the ActivityPub profile of the given user
70 * @param integer $uid User ID
73 public static function profile($uid)
75 $accounttype = ['Person', 'Organization', 'Service', 'Group', 'Application'];
77 $condition = ['uid' => $uid, 'blocked' => false, 'account_expired' => false,
78 'account_removed' => false, 'verified' => true];
79 $fields = ['guid', 'nickname', 'pubkey', 'account-type'];
80 $user = DBA::selectFirst('user', $fields, $condition);
81 if (!DBA::isResult($user)) {
85 $fields = ['locality', 'region', 'country-name'];
86 $profile = DBA::selectFirst('profile', $fields, ['uid' => $uid, 'is-default' => true]);
87 if (!DBA::isResult($profile)) {
91 $fields = ['name', 'url', 'location', 'about', 'avatar'];
92 $contact = DBA::selectFirst('contact', $fields, ['uid' => $uid, 'self' => true]);
93 if (!DBA::isResult($contact)) {
97 $data = ['@context' => ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1',
98 ['uuid' => 'http://schema.org/identifier', 'sensitive' => 'as:sensitive',
99 'vcard' => 'http://www.w3.org/2006/vcard/ns#']]];
101 $data['id'] = $contact['url'];
102 $data['uuid'] = $user['guid'];
103 $data['type'] = $accounttype[$user['account-type']];
104 $data['following'] = System::baseUrl() . '/following/' . $user['nickname'];
105 $data['followers'] = System::baseUrl() . '/followers/' . $user['nickname'];
106 $data['inbox'] = System::baseUrl() . '/inbox/' . $user['nickname'];
107 $data['outbox'] = System::baseUrl() . '/outbox/' . $user['nickname'];
108 $data['preferredUsername'] = $user['nickname'];
109 $data['name'] = $contact['name'];
110 $data['vcard:hasAddress'] = ['@type' => 'Home', 'vcard:country-name' => $profile['country-name'],
111 'vcard:region' => $profile['region'], 'vcard:locality' => $profile['locality']];
112 $data['summary'] = $contact['about'];
113 $data['url'] = $contact['url'];
114 $data['manuallyApprovesFollowers'] = false;
115 $data['publicKey'] = ['id' => $contact['url'] . '#main-key',
116 'owner' => $contact['url'],
117 'publicKeyPem' => $user['pubkey']];
118 $data['endpoints'] = ['sharedInbox' => System::baseUrl() . '/inbox'];
119 $data['icon'] = ['type' => 'Image',
120 'url' => $contact['avatar']];
122 // tags: https://kitty.town/@inmysocks/100656097926961126.json
126 public static function createActivityFromItem($item_id)
128 $item = Item::selectFirst([], ['id' => $item_id]);
130 $data = ['@context' => ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1',
131 ['Emoji' => 'toot:Emoji', 'Hashtag' => 'as:Hashtag', 'atomUri' => 'ostatus:atomUri',
132 'conversation' => 'ostatus:conversation', 'inReplyToAtomUri' => 'ostatus:inReplyToAtomUri',
133 'ostatus' => 'http://ostatus.org#', 'sensitive' => 'as:sensitive',
134 'toot' => 'http://joinmastodon.org/ns#']]];
136 $data['type'] = 'Create';
137 $data['id'] = $item['plink'];
138 $data['actor'] = $item['author-link'];
139 $data['to'] = 'https://www.w3.org/ns/activitystreams#Public';
140 $data['object'] = self::createNote($item);
146 public static function createNote($item)
149 $data['type'] = 'Note';
150 $data['id'] = $item['plink'];
151 //$data['context'] = $data['conversation'] = $item['parent-uri'];
152 $data['actor'] = $item['author-link'];
153 // if (!$item['private']) {
155 // $data['to'][] = '"https://pleroma.soykaf.com/users/heluecht"';
156 $data['to'] = 'https://www.w3.org/ns/activitystreams#Public';
157 // $data['cc'] = 'https://pleroma.soykaf.com/users/heluecht';
159 $data['published'] = DateTimeFormat::utc($item["created"]."+00:00", DateTimeFormat::ATOM);
160 $data['updated'] = DateTimeFormat::utc($item["edited"]."+00:00", DateTimeFormat::ATOM);
161 $data['attributedTo'] = $item['author-link'];
162 $data['name'] = BBCode::convert($item['title'], false, 7);
163 $data['content'] = BBCode::convert($item['body'], false, 7);
164 //$data['summary'] = '';
165 //$data['sensitive'] = false;
166 //$data['emoji'] = [];
168 //$data['attachment'] = [];
173 * Fetches ActivityPub content from the given url
175 * @param string $url content url
178 public static function fetchContent($url)
180 $ret = Network::curl($url, false, $redirects, ['accept_content' => 'application/activity+json']);
182 if (!$ret['success'] || empty($ret['body'])) {
186 return json_decode($ret['body'], true);
190 * Resolves the profile url from the address by using webfinger
192 * @param string $addr profile address (user@domain.tld)
195 private static function addrToUrl($addr)
197 $addr_parts = explode('@', $addr);
198 if (count($addr_parts) != 2) {
202 $webfinger = 'https://' . $addr_parts[1] . '/.well-known/webfinger?resource=acct:' . urlencode($addr);
204 $ret = Network::curl($webfinger, false, $redirects, ['accept_content' => 'application/jrd+json,application/json']);
205 if (!$ret['success'] || empty($ret['body'])) {
209 $data = json_decode($ret['body'], true);
211 if (empty($data['links'])) {
215 foreach ($data['links'] as $link) {
216 if (empty($link['href']) || empty($link['rel']) || empty($link['type'])) {
220 if (($link['rel'] == 'self') && ($link['type'] == 'application/activity+json')) {
221 return $link['href'];
228 public static function verifySignature($content, $http_headers)
230 $object = json_decode($content, true);
232 if (empty($object)) {
236 $actor = self::processElement($object, 'actor', 'id');
239 $headers['(request-target)'] = strtolower($http_headers['REQUEST_METHOD']) . ' ' . $http_headers['REQUEST_URI'];
241 // First take every header
242 foreach ($http_headers as $k => $v) {
243 $field = str_replace('_', '-', strtolower($k));
244 $headers[$field] = $v;
247 // Now add every http header
248 foreach ($http_headers as $k => $v) {
249 if (strpos($k, 'HTTP_') === 0) {
250 $field = str_replace('_', '-', strtolower(substr($k, 5)));
251 $headers[$field] = $v;
255 $sig_block = ActivityPub::parseSigHeader($http_headers['HTTP_SIGNATURE']);
257 if (empty($sig_block) || empty($sig_block['headers']) || empty($sig_block['keyId'])) {
262 foreach ($sig_block['headers'] as $h) {
263 if (array_key_exists($h, $headers)) {
264 $signed_data .= $h . ': ' . $headers[$h] . "\n";
267 $signed_data = rtrim($signed_data, "\n");
269 if (empty($signed_data)) {
275 if ($sig_block['algorithm'] === 'rsa-sha256') {
276 $algorithm = 'sha256';
279 if ($sig_block['algorithm'] === 'rsa-sha512') {
280 $algorithm = 'sha512';
283 if (empty($algorithm)) {
287 $key = self::fetchKey($sig_block['keyId'], $actor);
293 if (!Crypto::rsaVerify($signed_data, $sig_block['signature'], $key, $algorithm)) {
297 // Check the digest if it was part of the signed data
298 if (in_array('digest', $sig_block['headers'])) {
299 $digest = explode('=', $headers['digest'], 2);
300 if ($digest[0] === 'SHA-256') {
303 if ($digest[0] === 'SHA-512') {
307 /// @todo addd all hashes from the rfc
309 if (!empty($hashalg) && base64_encode(hash($hashalg, $content, true)) != $digest[1]) {
314 // Check the content-length if it was part of the signed data
315 if (in_array('content-length', $sig_block['headers'])) {
316 if (strlen($content) != $headers['content-length']) {
325 private static function fetchKey($id, $actor)
327 $url = (strpos($id, '#') ? substr($id, 0, strpos($id, '#')) : $id);
329 $profile = Probe::uri($url, Protocol::ACTIVITYPUB);
330 if (!empty($profile)) {
331 return $profile['pubkey'];
332 } elseif ($url != $actor) {
333 $profile = Probe::uri($actor, Protocol::ACTIVITYPUB);
334 if (!empty($profile)) {
335 return $profile['pubkey'];
345 * @param string $header
346 * @return array associate array with
347 * - \e string \b keyID
348 * - \e string \b algorithm
349 * - \e array \b headers
350 * - \e string \b signature
352 private static function parseSigHeader($header)
357 if (preg_match('/keyId="(.*?)"/ism',$header,$matches)) {
358 $ret['keyId'] = $matches[1];
361 if (preg_match('/algorithm="(.*?)"/ism',$header,$matches)) {
362 $ret['algorithm'] = $matches[1];
365 if (preg_match('/headers="(.*?)"/ism',$header,$matches)) {
366 $ret['headers'] = explode(' ', $matches[1]);
369 if (preg_match('/signature="(.*?)"/ism',$header,$matches)) {
370 $ret['signature'] = base64_decode(preg_replace('/\s+/','',$matches[1]));
377 * Fetches a profile from the given url
379 * @param string $url profile url
382 public static function fetchProfile($url)
384 if (empty(parse_url($url, PHP_URL_SCHEME))) {
385 $url = self::addrToUrl($url);
391 $data = self::fetchContent($url);
393 if (empty($data) || empty($data['id']) || empty($data['inbox'])) {
397 $profile = ['network' => Protocol::ACTIVITYPUB];
398 $profile['nick'] = $data['preferredUsername'];
399 $profile['name'] = defaults($data, 'name', $profile['nick']);
400 $profile['guid'] = defaults($data, 'uuid', null);
401 $profile['url'] = $data['id'];
403 $parts = parse_url($profile['url']);
404 unset($parts['scheme']);
405 unset($parts['path']);
406 $profile['addr'] = $profile['nick'] . '@' . str_replace('//', '', Network::unparseURL($parts));
407 $profile['alias'] = self::processElement($data, 'url', 'href');
408 $profile['photo'] = self::processElement($data, 'icon', 'url');
409 // $profile['community']
410 // $profile['keywords']
411 // $profile['location']
412 $profile['about'] = defaults($data, 'summary', '');
413 $profile['batch'] = self::processElement($data, 'endpoints', 'sharedInbox');
414 $profile['notify'] = $data['inbox'];
415 $profile['poll'] = $data['outbox'];
416 $profile['pubkey'] = self::processElement($data, 'publicKey', 'publicKeyPem');
418 // Check if the address is resolvable
419 if (self::addrToUrl($profile['addr']) == $profile['url']) {
420 $parts = parse_url($profile['url']);
421 unset($parts['path']);
422 $profile['baseurl'] = Network::unparseURL($parts);
424 unset($profile['addr']);
427 if ($profile['url'] == $profile['alias']) {
428 unset($profile['alias']);
431 // Remove all "null" fields
432 foreach ($profile as $field => $content) {
433 if (is_null($content)) {
434 unset($profile[$field]);
440 unset($data['inbox']);
441 unset($data['outbox']);
442 unset($data['preferredUsername']);
443 unset($data['name']);
444 unset($data['summary']);
446 unset($data['publicKey']);
447 unset($data['endpoints']);
448 unset($data['icon']);
449 unset($data['uuid']);
452 unset($data['type']);
453 unset($data['manuallyApprovesFollowers']);
456 unset($data['@context']);
458 unset($data['attachment']);
459 unset($data['image']);
460 unset($data['nomadicLocations']);
461 unset($data['signature']);
462 unset($data['following']);
463 unset($data['followers']);
464 unset($data['featured']);
465 unset($data['movedTo']);
466 unset($data['liked']);
467 unset($data['sharedInbox']); // Misskey
468 unset($data['isCat']); // Misskey
469 unset($data['kroeg:blocks']); // Kroeg
470 unset($data['updated']); // Kroeg
472 /* if (!empty($data)) {
480 public static function processInbox($body, $header)
482 logger('Incoming message', LOGGER_DEBUG);
484 if (!self::verifySignature($body, $header)) {
485 logger('Invalid signature, message will be discarded.', LOGGER_DEBUG);
489 $activity = json_decode($body, true);
491 if (!is_array($activity)) {
492 logger('Invalid body.', LOGGER_DEBUG);
496 self::processActivity($activity, $body);
499 public static function fetchOutbox($url)
501 $data = self::fetchContent($url);
506 if (!empty($data['orderedItems'])) {
507 $items = $data['orderedItems'];
508 } elseif (!empty($data['first']['orderedItems'])) {
509 $items = $data['first']['orderedItems'];
510 } elseif (!empty($data['first'])) {
511 self::fetchOutbox($data['first']);
517 foreach ($items as $activity) {
518 self::processActivity($activity);
522 function processActivity($activity, $body = '')
524 if (empty($activity['type'])) {
525 logger('Empty type', LOGGER_DEBUG);
529 if (empty($activity['object'])) {
530 logger('Empty object', LOGGER_DEBUG);
534 if (empty($activity['actor'])) {
535 logger('Empty actor', LOGGER_DEBUG);
540 $actor = self::processElement($activity, 'actor', 'id');
542 logger('Empty actor - 2', LOGGER_DEBUG);
546 if (is_string($activity['object'])) {
547 $object_url = $activity['object'];
548 } elseif (!empty($activity['object']['id'])) {
549 $object_url = $activity['object']['id'];
551 logger('No object found', LOGGER_DEBUG);
555 $receivers = self::getReceivers($activity);
556 if (empty($receivers)) {
557 logger('No receivers found', LOGGER_DEBUG);
561 // ----------------------------------
563 unset($activity['@context']);
564 unset($activity['id']);
567 unset($activity['title']);
568 unset($activity['atomUri']);
569 unset($activity['context_id']);
570 unset($activity['statusnetConversationId']);
572 $structure = $activity;
575 unset($activity['context']);
576 unset($activity['location']);
577 unset($activity['signature']);
580 unset($activity['to']);
581 unset($activity['cc']);
582 unset($activity['bto']);
583 unset($activity['bcc']);
584 unset($activity['type']);
585 unset($activity['actor']);
586 unset($activity['object']);
587 unset($activity['published']);
588 unset($activity['updated']);
589 unset($activity['instrument']);
590 unset($activity['inReplyTo']);
593 if (!empty($activity)) {
599 $activity = $structure;
600 // ----------------------------------
602 $item = self::fetchObject($object_url, $activity['object']);
604 logger("Object data couldn't be processed", LOGGER_DEBUG);
608 $item = self::addActivityFields($item, $activity);
610 $item['owner'] = $actor;
612 $item['receiver'] = array_merge($item['receiver'], $receivers);
614 logger('Processing activity: ' . $activity['type'], LOGGER_DEBUG);
616 switch ($activity['type']) {
619 self::createItem($item, $body);
623 self::announceItem($item, $body);
628 self::activityItem($item, $body);
635 logger('Unknown activity: ' . $activity['type'], LOGGER_DEBUG);
636 /* echo "Unknown activity: ".$activity['type']."\n";
644 private static function getReceivers($activity)
648 $elements = ['to', 'cc', 'bto', 'bcc'];
649 foreach ($elements as $element) {
650 if (empty($activity[$element])) {
654 // The receiver can be an arror or a string
655 if (is_string($activity[$element])) {
656 $activity[$element] = [$activity[$element]];
659 foreach ($activity[$element] as $receiver) {
660 if ($receiver == self::PUBLIC) {
661 $receivers[$receiver] = 0;
664 $condition = ['self' => true, 'nurl' => normalise_link($receiver)];
665 $contact = DBA::selectFirst('contact', ['uid'], $condition);
666 if (!DBA::isResult($contact)) {
669 $receivers[$receiver] = $contact['uid'];
675 private static function addActivityFields($item, $activity)
677 if (!empty($activity['published']) && empty($item['published'])) {
678 $item['published'] = $activity['published'];
681 if (!empty($activity['updated']) && empty($item['updated'])) {
682 $item['updated'] = $activity['updated'];
685 if (!empty($activity['inReplyTo']) && empty($item['parent-uri'])) {
686 $item['parent-uri'] = self::processElement($activity, 'inReplyTo', 'id');
689 if (!empty($activity['instrument'])) {
690 $item['service'] = self::processElement($activity, 'instrument', 'name', 'Service');
693 // Remove all "null" fields
694 foreach ($item as $field => $content) {
695 if (is_null($content)) {
696 unset($item[$field]);
703 private static function fetchObject($object_url, $object = [])
705 $data = self::fetchContent($object_url);
709 logger('Empty content');
712 logger('Using provided object');
716 if (empty($data['type'])) {
717 logger('Empty type');
720 $type = $data['type'];
721 logger('Type ' . $type);
724 if (in_array($type, ['Note', 'Article', 'Video'])) {
725 $common = self::processCommonData($data);
730 return array_merge($common, self::processNote($data));
732 return array_merge($common, self::processArticle($data));
734 return array_merge($common, self::processVideo($data));
737 if (empty($data['object'])) {
740 return self::fetchObject($data['object']);
747 logger('Unknown object type: ' . $data['type'], LOGGER_DEBUG);
748 /* echo "Unknown object type: ".$data['type']."\n";
756 private static function processCommonData(&$object)
758 if (empty($object['id']) || empty($object['attributedTo'])) {
763 $item['type'] = $object['type'];
764 $item['uri'] = $object['id'];
766 if (!empty($object['inReplyTo'])) {
767 $item['reply-to-uri'] = self::processElement($object, 'inReplyTo', 'id');
769 $item['reply-to-uri'] = $item['uri'];
772 $item['published'] = defaults($object, 'published', null);
773 $item['updated'] = defaults($object, 'updated', $item['published']);
775 if (empty($item['published']) && !empty($item['updated'])) {
776 $item['published'] = $item['updated'];
779 $item['uuid'] = defaults($object, 'uuid', null);
780 $item['owner'] = $item['author'] = self::processElement($object, 'attributedTo', 'id');
781 $item['context'] = defaults($object, 'context', null);
782 $item['conversation'] = defaults($object, 'conversation', null);
783 $item['sensitive'] = defaults($object, 'sensitive', null);
784 $item['name'] = defaults($object, 'title', null);
785 $item['name'] = defaults($object, 'name', $item['name']);
786 $item['summary'] = defaults($object, 'summary', null);
787 $item['content'] = defaults($object, 'content', null);
788 $item['location'] = self::processElement($object, 'location', 'name', 'Place');
789 $item['attachments'] = defaults($object, 'attachment', null);
790 $item['tags'] = defaults($object, 'tag', null);
791 $item['service'] = self::processElement($object, 'instrument', 'name', 'Service');
792 $item['alternate-url'] = self::processElement($object, 'url', 'href');
793 $item['receiver'] = self::getReceivers($object);
796 unset($object['id']);
797 unset($object['inReplyTo']);
798 unset($object['published']);
799 unset($object['updated']);
800 unset($object['uuid']);
801 unset($object['attributedTo']);
802 unset($object['context']);
803 unset($object['conversation']);
804 unset($object['sensitive']);
805 unset($object['name']);
806 unset($object['title']);
807 unset($object['content']);
808 unset($object['summary']);
809 unset($object['location']);
810 unset($object['attachment']);
811 unset($object['tag']);
812 unset($object['instrument']);
813 unset($object['url']);
814 unset($object['to']);
815 unset($object['cc']);
816 unset($object['bto']);
817 unset($object['bcc']);
820 unset($object['source']);
823 unset($object['@context']);
824 unset($object['type']);
825 unset($object['actor']);
826 unset($object['signature']);
827 unset($object['mediaType']);
828 unset($object['duration']);
829 unset($object['replies']);
830 unset($object['icon']);
833 audience, preview, endTime, startTime, generator, image
839 private static function processNote($object)
844 unset($object['emoji']);
845 unset($object['atomUri']);
846 unset($object['inReplyToAtomUri']);
849 unset($object['contentMap']);
850 unset($object['announcement_count']);
851 unset($object['announcements']);
852 unset($object['context_id']);
853 unset($object['likes']);
854 unset($object['like_count']);
855 unset($object['inReplyToStatusId']);
856 unset($object['shares']);
857 unset($object['quoteUrl']);
858 unset($object['statusnetConversationId']);
860 // if (empty($object))
863 echo "Unknown Note\n";
871 private static function processArticle($object)
875 // if (empty($object))
878 echo "Unknown Article\n";
886 private static function processVideo($object)
891 unset($object['category']);
892 unset($object['licence']);
893 unset($object['language']);
894 unset($object['commentsEnabled']);
897 unset($object['views']);
898 unset($object['waitTranscoding']);
899 unset($object['state']);
900 unset($object['support']);
901 unset($object['subtitleLanguage']);
902 unset($object['likes']);
903 unset($object['dislikes']);
904 unset($object['shares']);
905 unset($object['comments']);
907 // if (empty($object))
910 echo "Unknown Video\n";
918 private static function processElement($array, $element, $key, $type = null)
924 if (empty($array[$element])) {
928 if (is_string($array[$element])) {
929 return $array[$element];
932 if (is_null($type)) {
933 if (!empty($array[$element][$key])) {
934 return $array[$element][$key];
937 if (!empty($array[$element][0][$key])) {
938 return $array[$element][0][$key];
944 if (!empty($array[$element][$key]) && !empty($array[$element]['type']) && ($array[$element]['type'] == $type)) {
945 return $array[$element][$key];
948 /// @todo Add array search
953 private static function createItem($activity, $body)
955 // print_r($activity);
958 $item['network'] = Protocol::ACTIVITYPUB;
961 // $item['private'] = 0;
962 $item['gravity'] = GRAVITY_COMMENT;
963 $item['author-id'] = Contact::getIdForURL($activity['author'], 0, true);
964 $item['owner-id'] = Contact::getIdForURL($activity['owner'], 0, true);
965 $item['uri'] = $activity['uri'];
966 $item['parent-uri'] = $activity['reply-to-uri'];
967 $item['verb'] = ACTIVITY_POST; // Todo
968 $item['object-type'] = ACTIVITY_OBJ_NOTE; // Todo
969 $item['created'] = $activity['published'];
970 $item['edited'] = $activity['updated'];
971 $item['guid'] = $activity['uuid'];
972 $item['title'] = HTML::toBBCode($activity['name']);
973 $item['content-warning'] = HTML::toBBCode($activity['summary']);
974 $item['body'] = HTML::toBBCode($activity['content']);
975 $item['location'] = $activity['location'];
976 // $item['attach'] = $activity['attachments'];
977 // $item['tag'] = self::constructTagList($activity['tags'], $activity['sensitive']);
978 $item['app'] = $activity['service'];
979 $item['plink'] = $activity['alternate-url'];
981 $item['protocol'] = Conversation::PARCEL_ACTIVITYPUB;
982 $item['source'] = $body;
983 // $item[''] = $activity['context'];
984 $item['conversation-uri'] = $activity['conversation'];
986 foreach ($activity['receiver'] as $receiver) {
987 $item['uid'] = $receiver;
988 $item['contact-id'] = Contact::getIdForURL($activity['author'], $receiver, true);
990 if (($receiver != 0) && empty($item['contact-id'])) {
991 $item['contact-id'] = Contact::getIdForURL($activity['author'], 0, true);
994 $item_id = Item::insert($item);
995 logger('Storing for user ' . $item['uid'] . ': ' . $item_id);
996 if (!empty($item_id) && ($item['uid'] == 0)) {
997 Item::distribute($item_id);
1001 // $item[''] = $activity['receiver'];
1004 private static function announceItem($item)
1009 private static function activityItem($item)