3 * @file src/Protocol/ActivityPub/Transmitter.php
5 namespace Friendica\Protocol\ActivityPub;
7 use Friendica\Database\DBA;
8 use Friendica\Core\System;
9 use Friendica\Util\HTTPSignature;
10 use Friendica\Core\Protocol;
11 use Friendica\Model\Conversation;
12 use Friendica\Model\Contact;
13 use Friendica\Model\APContact;
14 use Friendica\Model\Item;
15 use Friendica\Model\Term;
16 use Friendica\Model\User;
17 use Friendica\Util\DateTimeFormat;
18 use Friendica\Content\Text\BBCode;
19 use Friendica\Util\JsonLD;
20 use Friendica\Util\LDSignature;
21 use Friendica\Model\Profile;
22 use Friendica\Core\Config;
23 use Friendica\Object\Image;
24 use Friendica\Protocol\ActivityPub;
27 * @brief ActivityPub Transmitter Protocol class
37 * - Queueing unsucessful deliveries
42 * @brief collects the lost of followers of the given owner
44 * @param array $owner Owner array
45 * @param integer $page Page number
47 * @return array of owners
49 public static function getFollowers($owner, $page = null)
51 $condition = ['rel' => [Contact::FOLLOWER, Contact::FRIEND], 'network' => Protocol::NATIVE_SUPPORT, 'uid' => $owner['uid'],
52 'self' => false, 'hidden' => false, 'archive' => false, 'pending' => false];
53 $count = DBA::count('contact', $condition);
55 $data = ['@context' => ActivityPub::CONTEXT];
56 $data['id'] = System::baseUrl() . '/followers/' . $owner['nickname'];
57 $data['type'] = 'OrderedCollection';
58 $data['totalItems'] = $count;
60 // When we hide our friends we will only show the pure number but don't allow more.
61 $profile = Profile::getByUID($owner['uid']);
62 if (!empty($profile['hide-friends'])) {
67 $data['first'] = System::baseUrl() . '/followers/' . $owner['nickname'] . '?page=1';
71 $contacts = DBA::select('contact', ['url'], $condition, ['limit' => [($page - 1) * 100, 100]]);
72 while ($contact = DBA::fetch($contacts)) {
73 $list[] = $contact['url'];
77 $data['next'] = System::baseUrl() . '/followers/' . $owner['nickname'] . '?page=' . ($page + 1);
80 $data['partOf'] = System::baseUrl() . '/followers/' . $owner['nickname'];
82 $data['orderedItems'] = $list;
89 * @brief Create list of following contacts
91 * @param array $owner Owner array
92 * @param integer $page Page numbe
94 * @return array of following contacts
96 public static function getFollowing($owner, $page = null)
98 $condition = ['rel' => [Contact::SHARING, Contact::FRIEND], 'network' => Protocol::NATIVE_SUPPORT, 'uid' => $owner['uid'],
99 'self' => false, 'hidden' => false, 'archive' => false, 'pending' => false];
100 $count = DBA::count('contact', $condition);
102 $data = ['@context' => ActivityPub::CONTEXT];
103 $data['id'] = System::baseUrl() . '/following/' . $owner['nickname'];
104 $data['type'] = 'OrderedCollection';
105 $data['totalItems'] = $count;
107 // When we hide our friends we will only show the pure number but don't allow more.
108 $profile = Profile::getByUID($owner['uid']);
109 if (!empty($profile['hide-friends'])) {
114 $data['first'] = System::baseUrl() . '/following/' . $owner['nickname'] . '?page=1';
118 $contacts = DBA::select('contact', ['url'], $condition, ['limit' => [($page - 1) * 100, 100]]);
119 while ($contact = DBA::fetch($contacts)) {
120 $list[] = $contact['url'];
124 $data['next'] = System::baseUrl() . '/following/' . $owner['nickname'] . '?page=' . ($page + 1);
127 $data['partOf'] = System::baseUrl() . '/following/' . $owner['nickname'];
129 $data['orderedItems'] = $list;
136 * @brief Public posts for the given owner
138 * @param array $owner Owner array
139 * @param integer $page Page numbe
141 * @return array of posts
143 public static function getOutbox($owner, $page = null)
145 $public_contact = Contact::getIdForURL($owner['url'], 0, true);
147 $condition = ['uid' => $owner['uid'], 'contact-id' => $owner['id'], 'author-id' => $public_contact,
148 'wall' => true, 'private' => false, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT],
149 'deleted' => false, 'visible' => true];
150 $count = DBA::count('item', $condition);
152 $data = ['@context' => ActivityPub::CONTEXT];
153 $data['id'] = System::baseUrl() . '/outbox/' . $owner['nickname'];
154 $data['type'] = 'OrderedCollection';
155 $data['totalItems'] = $count;
158 $data['first'] = System::baseUrl() . '/outbox/' . $owner['nickname'] . '?page=1';
162 $condition['parent-network'] = Protocol::NATIVE_SUPPORT;
164 $items = Item::select(['id'], $condition, ['limit' => [($page - 1) * 20, 20], 'order' => ['created' => true]]);
165 while ($item = Item::fetch($items)) {
166 $object = self::createObjectFromItemID($item['id']);
167 unset($object['@context']);
172 $data['next'] = System::baseUrl() . '/outbox/' . $owner['nickname'] . '?page=' . ($page + 1);
175 $data['partOf'] = System::baseUrl() . '/outbox/' . $owner['nickname'];
177 $data['orderedItems'] = $list;
184 * Return the ActivityPub profile of the given user
186 * @param integer $uid User ID
187 * @return profile array
189 public static function getProfile($uid)
191 $condition = ['uid' => $uid, 'blocked' => false, 'account_expired' => false,
192 'account_removed' => false, 'verified' => true];
193 $fields = ['guid', 'nickname', 'pubkey', 'account-type', 'page-flags'];
194 $user = DBA::selectFirst('user', $fields, $condition);
195 if (!DBA::isResult($user)) {
199 $fields = ['locality', 'region', 'country-name'];
200 $profile = DBA::selectFirst('profile', $fields, ['uid' => $uid, 'is-default' => true]);
201 if (!DBA::isResult($profile)) {
205 $fields = ['name', 'url', 'location', 'about', 'avatar'];
206 $contact = DBA::selectFirst('contact', $fields, ['uid' => $uid, 'self' => true]);
207 if (!DBA::isResult($contact)) {
211 $data = ['@context' => ActivityPub::CONTEXT];
212 $data['id'] = $contact['url'];
213 $data['diaspora:guid'] = $user['guid'];
214 $data['type'] = ActivityPub::ACCOUNT_TYPES[$user['account-type']];
215 $data['following'] = System::baseUrl() . '/following/' . $user['nickname'];
216 $data['followers'] = System::baseUrl() . '/followers/' . $user['nickname'];
217 $data['inbox'] = System::baseUrl() . '/inbox/' . $user['nickname'];
218 $data['outbox'] = System::baseUrl() . '/outbox/' . $user['nickname'];
219 $data['preferredUsername'] = $user['nickname'];
220 $data['name'] = $contact['name'];
221 $data['vcard:hasAddress'] = ['@type' => 'vcard:Home', 'vcard:country-name' => $profile['country-name'],
222 'vcard:region' => $profile['region'], 'vcard:locality' => $profile['locality']];
223 $data['summary'] = $contact['about'];
224 $data['url'] = $contact['url'];
225 $data['manuallyApprovesFollowers'] = in_array($user['page-flags'], [Contact::PAGE_NORMAL, Contact::PAGE_PRVGROUP]);
226 $data['publicKey'] = ['id' => $contact['url'] . '#main-key',
227 'owner' => $contact['url'],
228 'publicKeyPem' => $user['pubkey']];
229 $data['endpoints'] = ['sharedInbox' => System::baseUrl() . '/inbox'];
230 $data['icon'] = ['type' => 'Image',
231 'url' => $contact['avatar']];
233 // tags: https://kitty.town/@inmysocks/100656097926961126.json
238 * @brief Returns an array with permissions of a given item array
242 * @return array with permissions
244 private static function fetchPermissionBlockFromConversation($item)
246 if (empty($item['thr-parent'])) {
250 $condition = ['item-uri' => $item['thr-parent'], 'protocol' => Conversation::PARCEL_ACTIVITYPUB];
251 $conversation = DBA::selectFirst('conversation', ['source'], $condition);
252 if (!DBA::isResult($conversation)) {
256 $activity = json_decode($conversation['source'], true);
258 $actor = JsonLD::fetchElement($activity, 'actor', 'id');
259 $profile = APContact::getByURL($actor);
261 $item_profile = APContact::getByURL($item['author-link']);
262 $exclude[] = $item['author-link'];
264 if ($item['gravity'] == GRAVITY_PARENT) {
265 $exclude[] = $item['owner-link'];
268 $permissions['to'][] = $actor;
270 foreach (['to', 'cc', 'bto', 'bcc'] as $element) {
271 if (empty($activity[$element])) {
274 if (is_string($activity[$element])) {
275 $activity[$element] = [$activity[$element]];
278 foreach ($activity[$element] as $receiver) {
279 if ($receiver == $profile['followers'] && !empty($item_profile['followers'])) {
280 $receiver = $item_profile['followers'];
282 if (!in_array($receiver, $exclude)) {
283 $permissions[$element][] = $receiver;
291 * @brief Creates an array of permissions from an item thread
295 * @return permission array
297 private static function createPermissionBlockForItem($item)
299 $data = ['to' => [], 'cc' => []];
301 $data = array_merge($data, self::fetchPermissionBlockFromConversation($item));
303 $actor_profile = APContact::getByURL($item['author-link']);
305 $terms = Term::tagArrayFromItemId($item['id'], TERM_MENTION);
307 $contacts[$item['author-link']] = $item['author-link'];
309 if (!$item['private']) {
310 $data['to'][] = ActivityPub::PUBLIC_COLLECTION;
311 if (!empty($actor_profile['followers'])) {
312 $data['cc'][] = $actor_profile['followers'];
315 foreach ($terms as $term) {
316 $profile = APContact::getByURL($term['url'], false);
317 if (!empty($profile) && empty($contacts[$profile['url']])) {
318 $data['cc'][] = $profile['url'];
319 $contacts[$profile['url']] = $profile['url'];
323 $receiver_list = Item::enumeratePermissions($item);
327 foreach ($terms as $term) {
328 $cid = Contact::getIdForURL($term['url'], $item['uid']);
329 if (!empty($cid) && in_array($cid, $receiver_list)) {
330 $contact = DBA::selectFirst('contact', ['url'], ['id' => $cid, 'network' => Protocol::ACTIVITYPUB]);
331 $data['to'][] = $contact['url'];
332 $contacts[$contact['url']] = $contact['url'];
336 foreach ($receiver_list as $receiver) {
337 $contact = DBA::selectFirst('contact', ['url'], ['id' => $receiver, 'network' => Protocol::ACTIVITYPUB]);
338 if (empty($contacts[$contact['url']])) {
339 $data['cc'][] = $contact['url'];
340 $contacts[$contact['url']] = $contact['url'];
345 $parents = Item::select(['id', 'author-link', 'owner-link', 'gravity'], ['parent' => $item['parent']]);
346 while ($parent = Item::fetch($parents)) {
347 // Don't include data from future posts
348 if ($parent['id'] >= $item['id']) {
352 $profile = APContact::getByURL($parent['author-link'], false);
353 if (!empty($profile) && empty($contacts[$profile['url']])) {
354 $data['cc'][] = $profile['url'];
355 $contacts[$profile['url']] = $profile['url'];
358 if ($item['gravity'] != GRAVITY_PARENT) {
362 $profile = APContact::getByURL($parent['owner-link'], false);
363 if (!empty($profile) && empty($contacts[$profile['url']])) {
364 $data['cc'][] = $profile['url'];
365 $contacts[$profile['url']] = $profile['url'];
368 DBA::close($parents);
370 if (empty($data['to'])) {
371 $data['to'] = $data['cc'];
379 * @brief Fetches a list of inboxes of followers of a given user
381 * @param integer $uid User ID
383 * @return array of follower inboxes
385 public static function fetchTargetInboxesforUser($uid)
389 $condition = ['uid' => $uid, 'network' => Protocol::ACTIVITYPUB, 'archive' => false, 'pending' => false];
392 $condition['rel'] = [Contact::FOLLOWER, Contact::FRIEND];
395 $contacts = DBA::select('contact', ['notify', 'batch'], $condition);
396 while ($contact = DBA::fetch($contacts)) {
397 $contact = defaults($contact, 'batch', $contact['notify']);
398 $inboxes[$contact] = $contact;
400 DBA::close($contacts);
406 * @brief Fetches an array of inboxes for the given item and user
409 * @param integer $uid User ID
411 * @return array with inboxes
413 public static function fetchTargetInboxes($item, $uid)
415 $permissions = self::createPermissionBlockForItem($item);
416 if (empty($permissions)) {
422 if ($item['gravity'] == GRAVITY_ACTIVITY) {
423 $item_profile = APContact::getByURL($item['author-link']);
425 $item_profile = APContact::getByURL($item['owner-link']);
428 foreach (['to', 'cc', 'bto', 'bcc'] as $element) {
429 if (empty($permissions[$element])) {
433 foreach ($permissions[$element] as $receiver) {
434 if ($receiver == $item_profile['followers']) {
435 $inboxes = self::fetchTargetInboxesforUser($uid);
437 $profile = APContact::getByURL($receiver);
438 if (!empty($profile)) {
439 $target = defaults($profile, 'sharedinbox', $profile['inbox']);
440 $inboxes[$target] = $target;
450 * @brief Returns the activity type of a given item
454 * @return activity type
456 private static function getTypeOfItem($item)
458 if ($item['verb'] == ACTIVITY_POST) {
459 if ($item['created'] == $item['edited']) {
464 } elseif ($item['verb'] == ACTIVITY_LIKE) {
466 } elseif ($item['verb'] == ACTIVITY_DISLIKE) {
468 } elseif ($item['verb'] == ACTIVITY_ATTEND) {
470 } elseif ($item['verb'] == ACTIVITY_ATTENDNO) {
472 } elseif ($item['verb'] == ACTIVITY_ATTENDMAYBE) {
473 $type = 'TentativeAccept';
482 * @brief Creates an activity array for a given item id
484 * @param integer $item_id
485 * @param boolean $object_mode Is the activity item is used inside another object?
487 * @return array of activity
489 public static function createActivityFromItem($item_id, $object_mode = false)
491 $item = Item::selectFirst([], ['id' => $item_id, 'parent-network' => Protocol::NATIVE_SUPPORT]);
493 if (!DBA::isResult($item)) {
497 $condition = ['item-uri' => $item['uri'], 'protocol' => Conversation::PARCEL_ACTIVITYPUB];
498 $conversation = DBA::selectFirst('conversation', ['source'], $condition);
499 if (DBA::isResult($conversation)) {
500 $data = json_decode($conversation['source']);
506 $type = self::getTypeOfItem($item);
509 $data = ['@context' => ActivityPub::CONTEXT];
511 if ($item['deleted'] && ($item['gravity'] == GRAVITY_ACTIVITY)) {
513 } elseif ($item['deleted']) {
520 $data['id'] = $item['uri'] . '#' . $type;
521 $data['type'] = $type;
522 $data['actor'] = $item['author-link'];
524 $data['published'] = DateTimeFormat::utc($item["created"]."+00:00", DateTimeFormat::ATOM);
526 if ($item["created"] != $item["edited"]) {
527 $data['updated'] = DateTimeFormat::utc($item["edited"]."+00:00", DateTimeFormat::ATOM);
530 $data['context'] = self::fetchContextURLForItem($item);
532 $data = array_merge($data, self::createPermissionBlockForItem($item));
534 if (in_array($data['type'], ['Create', 'Update', 'Announce', 'Delete'])) {
535 $data['object'] = self::createNote($item);
536 } elseif ($data['type'] == 'Undo') {
537 $data['object'] = self::createActivityFromItem($item_id, true);
539 $data['object'] = $item['thr-parent'];
542 $owner = User::getOwnerDataById($item['uid']);
545 return LDSignature::sign($data, $owner);
552 * @brief Creates an object array for a given item id
554 * @param integer $item_id
556 * @return object array
558 public static function createObjectFromItemID($item_id)
560 $item = Item::selectFirst([], ['id' => $item_id, 'parent-network' => Protocol::NATIVE_SUPPORT]);
562 if (!DBA::isResult($item)) {
566 $data = ['@context' => ActivityPub::CONTEXT];
567 $data = array_merge($data, self::createNote($item));
573 * @brief Returns a tag array for a given item array
577 * @return array of tags
579 private static function createTagList($item)
583 $terms = Term::tagArrayFromItemId($item['id']);
584 foreach ($terms as $term) {
585 if ($term['type'] == TERM_HASHTAG) {
586 $tags[] = ['type' => 'Hashtag', 'href' => $term['url'], 'name' => '#' . $term['term']];
587 } elseif ($term['type'] == TERM_MENTION) {
588 $contact = Contact::getDetailsByURL($term['url']);
589 if (!empty($contact['addr'])) {
590 $mention = '@' . $contact['addr'];
592 $mention = '@' . $term['url'];
595 $tags[] = ['type' => 'Mention', 'href' => $term['url'], 'name' => $mention];
602 * @brief Adds attachment data to the JSON document
604 * @param array $item Data of the item that is to be posted
605 * @return attachment array
608 private static function createAttachmentList($item)
612 $siteinfo = BBCode::getAttachedData($item['body']);
614 switch ($siteinfo['type']) {
616 if (!empty($siteinfo['image'])) {
617 $imgdata = Image::getInfoFromURL($siteinfo['image']);
619 $attachments[] = ['type' => 'Document',
620 'mediaType' => $imgdata['mime'],
621 'url' => $siteinfo['image'],
627 $attachments[] = ['type' => 'Document',
628 'mediaType' => 'text/html; charset=UTF-8',
629 'url' => $siteinfo['url'],
630 'name' => defaults($siteinfo, 'title', $siteinfo['url'])];
636 if (!Config::get('system', 'ostatus_not_attach_preview') && ($siteinfo['type'] != 'photo') && isset($siteinfo['image'])) {
637 $imgdata = Image::getInfoFromURL($siteinfo['image']);
639 $attachments[] = ['type' => 'Document',
640 'mediaType' => $imgdata['mime'],
641 'url' => $siteinfo['image'],
646 $arr = explode('[/attach],', $item['attach']);
648 foreach ($arr as $r) {
650 $cnt = preg_match('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"|', $r, $matches);
652 $attributes = ['type' => 'Document',
653 'mediaType' => $matches[3],
654 'url' => $matches[1],
657 if (trim($matches[4]) != '') {
658 $attributes['name'] = trim($matches[4]);
661 $attachments[] = $attributes;
670 * @brief Fetches the "context" value for a givem item array from the "conversation" table
674 * @return string with context url
676 private static function fetchContextURLForItem($item)
678 $conversation = DBA::selectFirst('conversation', ['conversation-href', 'conversation-uri'], ['item-uri' => $item['parent-uri']]);
679 if (DBA::isResult($conversation) && !empty($conversation['conversation-href'])) {
680 $context_uri = $conversation['conversation-href'];
681 } elseif (DBA::isResult($conversation) && !empty($conversation['conversation-uri'])) {
682 $context_uri = $conversation['conversation-uri'];
684 $context_uri = str_replace('/objects/', '/context/', $item['parent-uri']);
689 private static function fetchSensitive($item_id)
691 $condition = ['otype' => TERM_OBJ_POST, 'oid' => $item_id, 'type' => TERM_HASHTAG, 'term' => 'nsfw'];
692 return DBA::exists('term', $condition);
696 * @brief Creates a note/article object array
700 * @return object array
702 public static function createNote($item)
704 if (!empty($item['title'])) {
710 if ($item['deleted']) {
715 $data['id'] = $item['uri'];
716 $data['type'] = $type;
718 if ($item['deleted']) {
722 $data['summary'] = null; // Ignore by now
724 if ($item['uri'] != $item['thr-parent']) {
725 $data['inReplyTo'] = $item['thr-parent'];
727 $data['inReplyTo'] = null;
730 $data['diaspora:guid'] = $item['guid'];
731 $data['published'] = DateTimeFormat::utc($item["created"]."+00:00", DateTimeFormat::ATOM);
733 if ($item["created"] != $item["edited"]) {
734 $data['updated'] = DateTimeFormat::utc($item["edited"]."+00:00", DateTimeFormat::ATOM);
737 $data['url'] = $item['plink'];
738 $data['attributedTo'] = $item['author-link'];
739 $data['actor'] = $item['author-link'];
740 $data['sensitive'] = self::fetchSensitive($item['id']);
741 $data['context'] = self::fetchContextURLForItem($item);
743 if (!empty($item['title'])) {
744 $data['name'] = BBCode::convert($item['title'], false, 7);
747 $data['content'] = BBCode::convert($item['body'], false, 7);
748 $data['source'] = ['content' => $item['body'], 'mediaType' => "text/bbcode"];
750 if (!empty($item['signed_text']) && ($item['uri'] != $item['thr-parent'])) {
751 $data['diaspora:comment'] = $item['signed_text'];
754 $data['attachment'] = self::createAttachmentList($item);
755 $data['tag'] = self::createTagList($item);
756 $data = array_merge($data, self::createPermissionBlockForItem($item));
762 * @brief Transmits a profile deletion to a given inbox
764 * @param integer $uid User ID
765 * @param string $inbox Target inbox
767 public static function sendProfileDeletion($uid, $inbox)
769 $owner = User::getOwnerDataById($uid);
770 $profile = APContact::getByURL($owner['url']);
772 $data = ['@context' => 'https://www.w3.org/ns/activitystreams',
773 'id' => System::baseUrl() . '/activity/' . System::createGUID(),
775 'actor' => $owner['url'],
776 'object' => $owner['url'],
777 'published' => DateTimeFormat::utcNow(DateTimeFormat::ATOM),
778 'to' => [ActivityPub::PUBLIC_COLLECTION],
781 $signed = LDSignature::sign($data, $owner);
783 logger('Deliver profile deletion for user ' . $uid . ' to ' . $inbox .' via ActivityPub', LOGGER_DEBUG);
784 HTTPSignature::transmit($signed, $inbox, $uid);
788 * @brief Transmits a profile change to a given inbox
790 * @param integer $uid User ID
791 * @param string $inbox Target inbox
793 public static function sendProfileUpdate($uid, $inbox)
795 $owner = User::getOwnerDataById($uid);
796 $profile = APContact::getByURL($owner['url']);
798 $data = ['@context' => 'https://www.w3.org/ns/activitystreams',
799 'id' => System::baseUrl() . '/activity/' . System::createGUID(),
801 'actor' => $owner['url'],
802 'object' => self::getProfile($uid),
803 'published' => DateTimeFormat::utcNow(DateTimeFormat::ATOM),
804 'to' => [$profile['followers']],
807 $signed = LDSignature::sign($data, $owner);
809 logger('Deliver profile update for user ' . $uid . ' to ' . $inbox .' via ActivityPub', LOGGER_DEBUG);
810 HTTPSignature::transmit($signed, $inbox, $uid);
814 * @brief Transmits a given activity to a target
816 * @param array $activity
817 * @param string $target Target profile
818 * @param integer $uid User ID
820 public static function sendActivity($activity, $target, $uid)
822 $profile = APContact::getByURL($target);
824 $owner = User::getOwnerDataById($uid);
826 $data = ['@context' => 'https://www.w3.org/ns/activitystreams',
827 'id' => System::baseUrl() . '/activity/' . System::createGUID(),
829 'actor' => $owner['url'],
830 'object' => $profile['url'],
831 'to' => $profile['url']];
833 logger('Sending activity ' . $activity . ' to ' . $target . ' for user ' . $uid, LOGGER_DEBUG);
835 $signed = LDSignature::sign($data, $owner);
836 HTTPSignature::transmit($signed, $profile['inbox'], $uid);
840 * @brief Transmit a message that the contact request had been accepted
842 * @param string $target Target profile
844 * @param integer $uid User ID
846 public static function sendContactAccept($target, $id, $uid)
848 $profile = APContact::getByURL($target);
850 $owner = User::getOwnerDataById($uid);
851 $data = ['@context' => 'https://www.w3.org/ns/activitystreams',
852 'id' => System::baseUrl() . '/activity/' . System::createGUID(),
854 'actor' => $owner['url'],
855 'object' => ['id' => $id, 'type' => 'Follow',
856 'actor' => $profile['url'],
857 'object' => $owner['url']],
858 'to' => $profile['url']];
860 logger('Sending accept to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG);
862 $signed = LDSignature::sign($data, $owner);
863 HTTPSignature::transmit($signed, $profile['inbox'], $uid);
869 * @param string $target Target profile
871 * @param integer $uid User ID
873 public static function sendContactReject($target, $id, $uid)
875 $profile = APContact::getByURL($target);
877 $owner = User::getOwnerDataById($uid);
878 $data = ['@context' => 'https://www.w3.org/ns/activitystreams',
879 'id' => System::baseUrl() . '/activity/' . System::createGUID(),
881 'actor' => $owner['url'],
882 'object' => ['id' => $id, 'type' => 'Follow',
883 'actor' => $profile['url'],
884 'object' => $owner['url']],
885 'to' => $profile['url']];
887 logger('Sending reject to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG);
889 $signed = LDSignature::sign($data, $owner);
890 HTTPSignature::transmit($signed, $profile['inbox'], $uid);
896 * @param string $target Target profile
897 * @param integer $uid User ID
899 public static function sendContactUndo($target, $uid)
901 $profile = APContact::getByURL($target);
903 $id = System::baseUrl() . '/activity/' . System::createGUID();
905 $owner = User::getOwnerDataById($uid);
906 $data = ['@context' => 'https://www.w3.org/ns/activitystreams',
909 'actor' => $owner['url'],
910 'object' => ['id' => $id, 'type' => 'Follow',
911 'actor' => $owner['url'],
912 'object' => $profile['url']],
913 'to' => $profile['url']];
915 logger('Sending undo to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG);
917 $signed = LDSignature::sign($data, $owner);
918 HTTPSignature::transmit($signed, $profile['inbox'], $uid);