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
38 * - Type "note": Remove inline images and add them as attachments
39 * - Type "article": Leave imaged embedded and don't add them as attachments
44 * @brief collects the lost of followers of the given owner
46 * @param array $owner Owner array
47 * @param integer $page Page number
49 * @return array of owners
51 public static function getFollowers($owner, $page = null)
53 $condition = ['rel' => [Contact::FOLLOWER, Contact::FRIEND], 'network' => Protocol::NATIVE_SUPPORT, 'uid' => $owner['uid'],
54 'self' => false, 'hidden' => false, 'archive' => false, 'pending' => false];
55 $count = DBA::count('contact', $condition);
57 $data = ['@context' => ActivityPub::CONTEXT];
58 $data['id'] = System::baseUrl() . '/followers/' . $owner['nickname'];
59 $data['type'] = 'OrderedCollection';
60 $data['totalItems'] = $count;
62 // When we hide our friends we will only show the pure number but don't allow more.
63 $profile = Profile::getByUID($owner['uid']);
64 if (!empty($profile['hide-friends'])) {
69 $data['first'] = System::baseUrl() . '/followers/' . $owner['nickname'] . '?page=1';
73 $contacts = DBA::select('contact', ['url'], $condition, ['limit' => [($page - 1) * 100, 100]]);
74 while ($contact = DBA::fetch($contacts)) {
75 $list[] = $contact['url'];
79 $data['next'] = System::baseUrl() . '/followers/' . $owner['nickname'] . '?page=' . ($page + 1);
82 $data['partOf'] = System::baseUrl() . '/followers/' . $owner['nickname'];
84 $data['orderedItems'] = $list;
91 * @brief Create list of following contacts
93 * @param array $owner Owner array
94 * @param integer $page Page numbe
96 * @return array of following contacts
98 public static function getFollowing($owner, $page = null)
100 $condition = ['rel' => [Contact::SHARING, Contact::FRIEND], 'network' => Protocol::NATIVE_SUPPORT, 'uid' => $owner['uid'],
101 'self' => false, 'hidden' => false, 'archive' => false, 'pending' => false];
102 $count = DBA::count('contact', $condition);
104 $data = ['@context' => ActivityPub::CONTEXT];
105 $data['id'] = System::baseUrl() . '/following/' . $owner['nickname'];
106 $data['type'] = 'OrderedCollection';
107 $data['totalItems'] = $count;
109 // When we hide our friends we will only show the pure number but don't allow more.
110 $profile = Profile::getByUID($owner['uid']);
111 if (!empty($profile['hide-friends'])) {
116 $data['first'] = System::baseUrl() . '/following/' . $owner['nickname'] . '?page=1';
120 $contacts = DBA::select('contact', ['url'], $condition, ['limit' => [($page - 1) * 100, 100]]);
121 while ($contact = DBA::fetch($contacts)) {
122 $list[] = $contact['url'];
126 $data['next'] = System::baseUrl() . '/following/' . $owner['nickname'] . '?page=' . ($page + 1);
129 $data['partOf'] = System::baseUrl() . '/following/' . $owner['nickname'];
131 $data['orderedItems'] = $list;
138 * @brief Public posts for the given owner
140 * @param array $owner Owner array
141 * @param integer $page Page numbe
143 * @return array of posts
145 public static function getOutbox($owner, $page = null)
147 $public_contact = Contact::getIdForURL($owner['url'], 0, true);
149 $condition = ['uid' => $owner['uid'], 'contact-id' => $owner['id'], 'author-id' => $public_contact,
150 'wall' => true, 'private' => false, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT],
151 'deleted' => false, 'visible' => true];
152 $count = DBA::count('item', $condition);
154 $data = ['@context' => ActivityPub::CONTEXT];
155 $data['id'] = System::baseUrl() . '/outbox/' . $owner['nickname'];
156 $data['type'] = 'OrderedCollection';
157 $data['totalItems'] = $count;
160 $data['first'] = System::baseUrl() . '/outbox/' . $owner['nickname'] . '?page=1';
164 $condition['parent-network'] = Protocol::NATIVE_SUPPORT;
166 $items = Item::select(['id'], $condition, ['limit' => [($page - 1) * 20, 20], 'order' => ['created' => true]]);
167 while ($item = Item::fetch($items)) {
168 $object = self::createObjectFromItemID($item['id']);
169 unset($object['@context']);
174 $data['next'] = System::baseUrl() . '/outbox/' . $owner['nickname'] . '?page=' . ($page + 1);
177 $data['partOf'] = System::baseUrl() . '/outbox/' . $owner['nickname'];
179 $data['orderedItems'] = $list;
186 * Return the ActivityPub profile of the given user
188 * @param integer $uid User ID
189 * @return profile array
191 public static function getProfile($uid)
193 $condition = ['uid' => $uid, 'blocked' => false, 'account_expired' => false,
194 'account_removed' => false, 'verified' => true];
195 $fields = ['guid', 'nickname', 'pubkey', 'account-type', 'page-flags'];
196 $user = DBA::selectFirst('user', $fields, $condition);
197 if (!DBA::isResult($user)) {
201 $fields = ['locality', 'region', 'country-name'];
202 $profile = DBA::selectFirst('profile', $fields, ['uid' => $uid, 'is-default' => true]);
203 if (!DBA::isResult($profile)) {
207 $fields = ['name', 'url', 'location', 'about', 'avatar'];
208 $contact = DBA::selectFirst('contact', $fields, ['uid' => $uid, 'self' => true]);
209 if (!DBA::isResult($contact)) {
213 $data = ['@context' => ActivityPub::CONTEXT];
214 $data['id'] = $contact['url'];
215 $data['diaspora:guid'] = $user['guid'];
216 $data['type'] = ActivityPub::ACCOUNT_TYPES[$user['account-type']];
217 $data['following'] = System::baseUrl() . '/following/' . $user['nickname'];
218 $data['followers'] = System::baseUrl() . '/followers/' . $user['nickname'];
219 $data['inbox'] = System::baseUrl() . '/inbox/' . $user['nickname'];
220 $data['outbox'] = System::baseUrl() . '/outbox/' . $user['nickname'];
221 $data['preferredUsername'] = $user['nickname'];
222 $data['name'] = $contact['name'];
223 $data['vcard:hasAddress'] = ['@type' => 'vcard:Home', 'vcard:country-name' => $profile['country-name'],
224 'vcard:region' => $profile['region'], 'vcard:locality' => $profile['locality']];
225 $data['summary'] = $contact['about'];
226 $data['url'] = $contact['url'];
227 $data['manuallyApprovesFollowers'] = in_array($user['page-flags'], [Contact::PAGE_NORMAL, Contact::PAGE_PRVGROUP]);
228 $data['publicKey'] = ['id' => $contact['url'] . '#main-key',
229 'owner' => $contact['url'],
230 'publicKeyPem' => $user['pubkey']];
231 $data['endpoints'] = ['sharedInbox' => System::baseUrl() . '/inbox'];
232 $data['icon'] = ['type' => 'Image',
233 'url' => $contact['avatar']];
235 // tags: https://kitty.town/@inmysocks/100656097926961126.json
240 * @brief Returns an array with permissions of a given item array
244 * @return array with permissions
246 private static function fetchPermissionBlockFromConversation($item)
248 if (empty($item['thr-parent'])) {
252 $condition = ['item-uri' => $item['thr-parent'], 'protocol' => Conversation::PARCEL_ACTIVITYPUB];
253 $conversation = DBA::selectFirst('conversation', ['source'], $condition);
254 if (!DBA::isResult($conversation)) {
258 $activity = json_decode($conversation['source'], true);
260 $actor = JsonLD::fetchElement($activity, 'actor', 'id');
261 $profile = APContact::getByURL($actor);
263 $item_profile = APContact::getByURL($item['author-link']);
264 $exclude[] = $item['author-link'];
266 if ($item['gravity'] == GRAVITY_PARENT) {
267 $exclude[] = $item['owner-link'];
270 $permissions['to'][] = $actor;
272 foreach (['to', 'cc', 'bto', 'bcc'] as $element) {
273 if (empty($activity[$element])) {
276 if (is_string($activity[$element])) {
277 $activity[$element] = [$activity[$element]];
280 foreach ($activity[$element] as $receiver) {
281 if ($receiver == $profile['followers'] && !empty($item_profile['followers'])) {
282 $receiver = $item_profile['followers'];
284 if (!in_array($receiver, $exclude)) {
285 $permissions[$element][] = $receiver;
293 * @brief Creates an array of permissions from an item thread
297 * @return permission array
299 private static function createPermissionBlockForItem($item)
301 $data = ['to' => [], 'cc' => []];
303 $data = array_merge($data, self::fetchPermissionBlockFromConversation($item));
305 $actor_profile = APContact::getByURL($item['author-link']);
307 $terms = Term::tagArrayFromItemId($item['id'], TERM_MENTION);
309 $contacts[$item['author-link']] = $item['author-link'];
311 if (!$item['private']) {
312 $data['to'][] = ActivityPub::PUBLIC_COLLECTION;
313 if (!empty($actor_profile['followers'])) {
314 $data['cc'][] = $actor_profile['followers'];
317 foreach ($terms as $term) {
318 $profile = APContact::getByURL($term['url'], false);
319 if (!empty($profile) && empty($contacts[$profile['url']])) {
320 $data['cc'][] = $profile['url'];
321 $contacts[$profile['url']] = $profile['url'];
325 $receiver_list = Item::enumeratePermissions($item);
329 foreach ($terms as $term) {
330 $cid = Contact::getIdForURL($term['url'], $item['uid']);
331 if (!empty($cid) && in_array($cid, $receiver_list)) {
332 $contact = DBA::selectFirst('contact', ['url'], ['id' => $cid, 'network' => Protocol::ACTIVITYPUB]);
333 $data['to'][] = $contact['url'];
334 $contacts[$contact['url']] = $contact['url'];
338 foreach ($receiver_list as $receiver) {
339 $contact = DBA::selectFirst('contact', ['url'], ['id' => $receiver, 'network' => Protocol::ACTIVITYPUB]);
340 if (empty($contacts[$contact['url']])) {
341 $data['cc'][] = $contact['url'];
342 $contacts[$contact['url']] = $contact['url'];
347 $parents = Item::select(['id', 'author-link', 'owner-link', 'gravity'], ['parent' => $item['parent']]);
348 while ($parent = Item::fetch($parents)) {
349 // Don't include data from future posts
350 if ($parent['id'] >= $item['id']) {
354 $profile = APContact::getByURL($parent['author-link'], false);
355 if (!empty($profile) && empty($contacts[$profile['url']])) {
356 $data['cc'][] = $profile['url'];
357 $contacts[$profile['url']] = $profile['url'];
360 if ($item['gravity'] != GRAVITY_PARENT) {
364 $profile = APContact::getByURL($parent['owner-link'], false);
365 if (!empty($profile) && empty($contacts[$profile['url']])) {
366 $data['cc'][] = $profile['url'];
367 $contacts[$profile['url']] = $profile['url'];
370 DBA::close($parents);
372 if (empty($data['to'])) {
373 $data['to'] = $data['cc'];
381 * @brief Fetches a list of inboxes of followers of a given user
383 * @param integer $uid User ID
385 * @return array of follower inboxes
387 public static function fetchTargetInboxesforUser($uid)
391 $condition = ['uid' => $uid, 'network' => Protocol::ACTIVITYPUB, 'archive' => false, 'pending' => false];
394 $condition['rel'] = [Contact::FOLLOWER, Contact::FRIEND];
397 $contacts = DBA::select('contact', ['notify', 'batch'], $condition);
398 while ($contact = DBA::fetch($contacts)) {
399 $contact = defaults($contact, 'batch', $contact['notify']);
400 $inboxes[$contact] = $contact;
402 DBA::close($contacts);
408 * @brief Fetches an array of inboxes for the given item and user
411 * @param integer $uid User ID
413 * @return array with inboxes
415 public static function fetchTargetInboxes($item, $uid)
417 $permissions = self::createPermissionBlockForItem($item);
418 if (empty($permissions)) {
424 if ($item['gravity'] == GRAVITY_ACTIVITY) {
425 $item_profile = APContact::getByURL($item['author-link']);
427 $item_profile = APContact::getByURL($item['owner-link']);
430 foreach (['to', 'cc', 'bto', 'bcc'] as $element) {
431 if (empty($permissions[$element])) {
435 foreach ($permissions[$element] as $receiver) {
436 if ($receiver == $item_profile['followers']) {
437 $inboxes = self::fetchTargetInboxesforUser($uid);
439 $profile = APContact::getByURL($receiver);
440 if (!empty($profile)) {
441 $target = defaults($profile, 'sharedinbox', $profile['inbox']);
442 $inboxes[$target] = $target;
452 * @brief Returns the activity type of a given item
456 * @return activity type
458 private static function getTypeOfItem($item)
460 if ($item['verb'] == ACTIVITY_POST) {
461 if ($item['created'] == $item['edited']) {
466 } elseif ($item['verb'] == ACTIVITY_LIKE) {
468 } elseif ($item['verb'] == ACTIVITY_DISLIKE) {
470 } elseif ($item['verb'] == ACTIVITY_ATTEND) {
472 } elseif ($item['verb'] == ACTIVITY_ATTENDNO) {
474 } elseif ($item['verb'] == ACTIVITY_ATTENDMAYBE) {
475 $type = 'TentativeAccept';
484 * @brief Creates an activity array for a given item id
486 * @param integer $item_id
487 * @param boolean $object_mode Is the activity item is used inside another object?
489 * @return array of activity
491 public static function createActivityFromItem($item_id, $object_mode = false)
493 $item = Item::selectFirst([], ['id' => $item_id, 'parent-network' => Protocol::NATIVE_SUPPORT]);
495 if (!DBA::isResult($item)) {
499 $condition = ['item-uri' => $item['uri'], 'protocol' => Conversation::PARCEL_ACTIVITYPUB];
500 $conversation = DBA::selectFirst('conversation', ['source'], $condition);
501 if (DBA::isResult($conversation)) {
502 $data = json_decode($conversation['source']);
508 $type = self::getTypeOfItem($item);
511 $data = ['@context' => ActivityPub::CONTEXT];
513 if ($item['deleted'] && ($item['gravity'] == GRAVITY_ACTIVITY)) {
515 } elseif ($item['deleted']) {
522 $data['id'] = $item['uri'] . '#' . $type;
523 $data['type'] = $type;
524 $data['actor'] = $item['author-link'];
526 $data['published'] = DateTimeFormat::utc($item["created"]."+00:00", DateTimeFormat::ATOM);
528 if ($item["created"] != $item["edited"]) {
529 $data['updated'] = DateTimeFormat::utc($item["edited"]."+00:00", DateTimeFormat::ATOM);
532 $data['context'] = self::fetchContextURLForItem($item);
534 $data = array_merge($data, self::createPermissionBlockForItem($item));
536 if (in_array($data['type'], ['Create', 'Update', 'Announce', 'Delete'])) {
537 $data['object'] = self::createNote($item);
538 } elseif ($data['type'] == 'Undo') {
539 $data['object'] = self::createActivityFromItem($item_id, true);
541 $data['object'] = $item['thr-parent'];
544 $owner = User::getOwnerDataById($item['uid']);
547 return LDSignature::sign($data, $owner);
554 * @brief Creates an object array for a given item id
556 * @param integer $item_id
558 * @return object array
560 public static function createObjectFromItemID($item_id)
562 $item = Item::selectFirst([], ['id' => $item_id, 'parent-network' => Protocol::NATIVE_SUPPORT]);
564 if (!DBA::isResult($item)) {
568 $data = ['@context' => ActivityPub::CONTEXT];
569 $data = array_merge($data, self::createNote($item));
575 * @brief Returns a tag array for a given item array
579 * @return array of tags
581 private static function createTagList($item)
585 $terms = Term::tagArrayFromItemId($item['id']);
586 foreach ($terms as $term) {
587 if ($term['type'] == TERM_HASHTAG) {
588 $tags[] = ['type' => 'Hashtag', 'href' => $term['url'], 'name' => '#' . $term['term']];
589 } elseif ($term['type'] == TERM_MENTION) {
590 $contact = Contact::getDetailsByURL($term['url']);
591 if (!empty($contact['addr'])) {
592 $mention = '@' . $contact['addr'];
594 $mention = '@' . $term['url'];
597 $tags[] = ['type' => 'Mention', 'href' => $term['url'], 'name' => $mention];
604 * @brief Adds attachment data to the JSON document
606 * @param array $item Data of the item that is to be posted
607 * @param text $type Object type
608 * @return attachment array
611 private static function createAttachmentList($item, $type)
615 $arr = explode('[/attach],', $item['attach']);
617 foreach ($arr as $r) {
619 $cnt = preg_match('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"|', $r, $matches);
621 $attributes = ['type' => 'Document',
622 'mediaType' => $matches[3],
623 'url' => $matches[1],
626 if (trim($matches[4]) != '') {
627 $attributes['name'] = trim($matches[4]);
630 $attachments[] = $attributes;
635 if ($type != 'Note') {
639 /// @todo Replace this with a function that takes all pictures from the post
640 $siteinfo = BBCode::getAttachedData($item['body']);
642 if (!empty($siteinfo['image']) &&
643 (($siteinfo['type'] == 'photo') ||
644 !Config::get('system', 'ostatus_not_attach_preview'))) {
645 $imgdata = Image::getInfoFromURL($siteinfo['image']);
647 $attachments[] = ['type' => 'Document',
648 'mediaType' => $imgdata['mime'],
649 'url' => $siteinfo['image'],
658 * @brief Fetches the "context" value for a givem item array from the "conversation" table
662 * @return string with context url
664 private static function fetchContextURLForItem($item)
666 $conversation = DBA::selectFirst('conversation', ['conversation-href', 'conversation-uri'], ['item-uri' => $item['parent-uri']]);
667 if (DBA::isResult($conversation) && !empty($conversation['conversation-href'])) {
668 $context_uri = $conversation['conversation-href'];
669 } elseif (DBA::isResult($conversation) && !empty($conversation['conversation-uri'])) {
670 $context_uri = $conversation['conversation-uri'];
672 $context_uri = str_replace('/objects/', '/context/', $item['parent-uri']);
677 private static function fetchSensitive($item_id)
679 $condition = ['otype' => TERM_OBJ_POST, 'oid' => $item_id, 'type' => TERM_HASHTAG, 'term' => 'nsfw'];
680 return DBA::exists('term', $condition);
684 * @brief Creates a note/article object array
688 * @return object array
690 public static function createNote($item)
692 if (!empty($item['title'])) {
698 if ($item['deleted']) {
703 $data['id'] = $item['uri'];
704 $data['type'] = $type;
706 if ($item['deleted']) {
710 $data['summary'] = null; // Ignore by now
712 if ($item['uri'] != $item['thr-parent']) {
713 $data['inReplyTo'] = $item['thr-parent'];
715 $data['inReplyTo'] = null;
718 $data['diaspora:guid'] = $item['guid'];
719 $data['published'] = DateTimeFormat::utc($item["created"]."+00:00", DateTimeFormat::ATOM);
721 if ($item["created"] != $item["edited"]) {
722 $data['updated'] = DateTimeFormat::utc($item["edited"]."+00:00", DateTimeFormat::ATOM);
725 $data['url'] = $item['plink'];
726 $data['attributedTo'] = $item['author-link'];
727 $data['actor'] = $item['author-link'];
728 $data['sensitive'] = self::fetchSensitive($item['id']);
729 $data['context'] = self::fetchContextURLForItem($item);
731 if (!empty($item['title'])) {
732 $data['name'] = BBCode::convert($item['title'], false, 7);
735 $data['content'] = BBCode::convert($item['body'], false, 7);
736 $data['source'] = ['content' => $item['body'], 'mediaType' => "text/bbcode"];
738 if (!empty($item['signed_text']) && ($item['uri'] != $item['thr-parent'])) {
739 $data['diaspora:comment'] = $item['signed_text'];
742 $data['attachment'] = self::createAttachmentList($item, $type);
743 $data['tag'] = self::createTagList($item);
744 $data = array_merge($data, self::createPermissionBlockForItem($item));
750 * @brief Transmits a profile deletion to a given inbox
752 * @param integer $uid User ID
753 * @param string $inbox Target inbox
755 public static function sendProfileDeletion($uid, $inbox)
757 $owner = User::getOwnerDataById($uid);
758 $profile = APContact::getByURL($owner['url']);
760 $data = ['@context' => 'https://www.w3.org/ns/activitystreams',
761 'id' => System::baseUrl() . '/activity/' . System::createGUID(),
763 'actor' => $owner['url'],
764 'object' => $owner['url'],
765 'published' => DateTimeFormat::utcNow(DateTimeFormat::ATOM),
766 'to' => [ActivityPub::PUBLIC_COLLECTION],
769 $signed = LDSignature::sign($data, $owner);
771 logger('Deliver profile deletion for user ' . $uid . ' to ' . $inbox .' via ActivityPub', LOGGER_DEBUG);
772 HTTPSignature::transmit($signed, $inbox, $uid);
776 * @brief Transmits a profile change to a given inbox
778 * @param integer $uid User ID
779 * @param string $inbox Target inbox
781 public static function sendProfileUpdate($uid, $inbox)
783 $owner = User::getOwnerDataById($uid);
784 $profile = APContact::getByURL($owner['url']);
786 $data = ['@context' => 'https://www.w3.org/ns/activitystreams',
787 'id' => System::baseUrl() . '/activity/' . System::createGUID(),
789 'actor' => $owner['url'],
790 'object' => self::getProfile($uid),
791 'published' => DateTimeFormat::utcNow(DateTimeFormat::ATOM),
792 'to' => [$profile['followers']],
795 $signed = LDSignature::sign($data, $owner);
797 logger('Deliver profile update for user ' . $uid . ' to ' . $inbox .' via ActivityPub', LOGGER_DEBUG);
798 HTTPSignature::transmit($signed, $inbox, $uid);
802 * @brief Transmits a given activity to a target
804 * @param array $activity
805 * @param string $target Target profile
806 * @param integer $uid User ID
808 public static function sendActivity($activity, $target, $uid)
810 $profile = APContact::getByURL($target);
812 $owner = User::getOwnerDataById($uid);
814 $data = ['@context' => 'https://www.w3.org/ns/activitystreams',
815 'id' => System::baseUrl() . '/activity/' . System::createGUID(),
817 'actor' => $owner['url'],
818 'object' => $profile['url'],
819 'to' => $profile['url']];
821 logger('Sending activity ' . $activity . ' to ' . $target . ' for user ' . $uid, LOGGER_DEBUG);
823 $signed = LDSignature::sign($data, $owner);
824 HTTPSignature::transmit($signed, $profile['inbox'], $uid);
828 * @brief Transmit a message that the contact request had been accepted
830 * @param string $target Target profile
832 * @param integer $uid User ID
834 public static function sendContactAccept($target, $id, $uid)
836 $profile = APContact::getByURL($target);
838 $owner = User::getOwnerDataById($uid);
839 $data = ['@context' => 'https://www.w3.org/ns/activitystreams',
840 'id' => System::baseUrl() . '/activity/' . System::createGUID(),
842 'actor' => $owner['url'],
843 'object' => ['id' => $id, 'type' => 'Follow',
844 'actor' => $profile['url'],
845 'object' => $owner['url']],
846 'to' => $profile['url']];
848 logger('Sending accept to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG);
850 $signed = LDSignature::sign($data, $owner);
851 HTTPSignature::transmit($signed, $profile['inbox'], $uid);
857 * @param string $target Target profile
859 * @param integer $uid User ID
861 public static function sendContactReject($target, $id, $uid)
863 $profile = APContact::getByURL($target);
865 $owner = User::getOwnerDataById($uid);
866 $data = ['@context' => 'https://www.w3.org/ns/activitystreams',
867 'id' => System::baseUrl() . '/activity/' . System::createGUID(),
869 'actor' => $owner['url'],
870 'object' => ['id' => $id, 'type' => 'Follow',
871 'actor' => $profile['url'],
872 'object' => $owner['url']],
873 'to' => $profile['url']];
875 logger('Sending reject to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG);
877 $signed = LDSignature::sign($data, $owner);
878 HTTPSignature::transmit($signed, $profile['inbox'], $uid);
884 * @param string $target Target profile
885 * @param integer $uid User ID
887 public static function sendContactUndo($target, $uid)
889 $profile = APContact::getByURL($target);
891 $id = System::baseUrl() . '/activity/' . System::createGUID();
893 $owner = User::getOwnerDataById($uid);
894 $data = ['@context' => 'https://www.w3.org/ns/activitystreams',
897 'actor' => $owner['url'],
898 'object' => ['id' => $id, 'type' => 'Follow',
899 'actor' => $owner['url'],
900 'object' => $profile['url']],
901 'to' => $profile['url']];
903 logger('Sending undo to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG);
905 $signed = LDSignature::sign($data, $owner);
906 HTTPSignature::transmit($signed, $profile['inbox'], $uid);