]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/ActivityPub/Transmitter.php
Log function
[friendica.git] / src / Protocol / ActivityPub / Transmitter.php
index bfbd9f9b4e05d28be5eb0de2564f0d08592f235a..d9535f0b62287182a87362437d26a17e3e18a5fd 100644 (file)
@@ -4,7 +4,9 @@
  */
 namespace Friendica\Protocol\ActivityPub;
 
+use Friendica\BaseObject;
 use Friendica\Database\DBA;
+use Friendica\Core\Logger;
 use Friendica\Core\System;
 use Friendica\Util\HTTPSignature;
 use Friendica\Core\Protocol;
@@ -22,26 +24,22 @@ use Friendica\Model\Profile;
 use Friendica\Core\Config;
 use Friendica\Object\Image;
 use Friendica\Protocol\ActivityPub;
+use Friendica\Protocol\Diaspora;
+use Friendica\Core\Cache;
+use Friendica\Util\Map;
+
+require_once 'include/api.php';
 
 /**
  * @brief ActivityPub Transmitter Protocol class
  *
  * To-Do:
- *
- * Missing object types:
- * - Event
- *
- * Complicated object types:
- * - Announce
  * - Undo Announce
- *
- * General:
- * - Queueing unsucessful deliveries
  */
 class Transmitter
 {
        /**
-        * @brief collects the lost of followers of the given owner
+        * collects the lost of followers of the given owner
         *
         * @param array $owner Owner array
         * @param integer $page Page number
@@ -88,7 +86,7 @@ class Transmitter
        }
 
        /**
-        * @brief Create list of following contacts
+        * Create list of following contacts
         *
         * @param array $owner Owner array
         * @param integer $page Page numbe
@@ -135,7 +133,7 @@ class Transmitter
        }
 
        /**
-        * @brief Public posts for the given owner
+        * Public posts for the given owner
         *
         * @param array $owner Owner array
         * @param integer $page Page numbe
@@ -146,8 +144,8 @@ class Transmitter
        {
                $public_contact = Contact::getIdForURL($owner['url'], 0, true);
 
-               $condition = ['uid' => $owner['uid'], 'contact-id' => $owner['id'], 'author-id' => $public_contact,
-                       'wall' => true, 'private' => false, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT],
+               $condition = ['uid' => 0, 'contact-id' => $public_contact, 'author-id' => $public_contact,
+                       'private' => false, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT],
                        'deleted' => false, 'visible' => true];
                $count = DBA::count('item', $condition);
 
@@ -204,12 +202,17 @@ class Transmitter
                        return [];
                }
 
-               $fields = ['name', 'url', 'location', 'about', 'avatar'];
+               $fields = ['name', 'url', 'location', 'about', 'avatar', 'photo'];
                $contact = DBA::selectFirst('contact', $fields, ['uid' => $uid, 'self' => true]);
                if (!DBA::isResult($contact)) {
                        return [];
                }
 
+               // On old installations and never changed contacts this might not be filled
+               if (empty($contact['avatar'])) {
+                       $contact['avatar'] = $contact['photo'];
+               }
+
                $data = ['@context' => ActivityPub::CONTEXT];
                $data['id'] = $contact['url'];
                $data['diaspora:guid'] = $user['guid'];
@@ -237,7 +240,7 @@ class Transmitter
        }
 
        /**
-        * @brief Returns an array with permissions of a given item array
+        * Returns an array with permissions of a given item array
         *
         * @param array $item
         *
@@ -279,9 +282,8 @@ class Transmitter
 
                        foreach ($activity[$element] as $receiver) {
                                if ($receiver == $profile['followers'] && !empty($item_profile['followers'])) {
-                                       $receiver = $item_profile['followers'];
-                               }
-                               if (!in_array($receiver, $exclude)) {
+                                       $permissions[$element][] = $item_profile['followers'];
+                               } elseif (!in_array($receiver, $exclude)) {
                                        $permissions[$element][] = $receiver;
                                }
                        }
@@ -290,25 +292,30 @@ class Transmitter
        }
 
        /**
-        * @brief Creates an array of permissions from an item thread
+        * Creates an array of permissions from an item thread
         *
         * @param array $item
+        * @param boolean $blindcopy
         *
         * @return array with permission data
         */
-       private static function createPermissionBlockForItem($item)
+       private static function createPermissionBlockForItem($item, $blindcopy)
        {
-               $data = ['to' => [], 'cc' => []];
+               // Will be activated in a later step
+               // $networks = [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS];
 
-               $data = array_merge($data, self::fetchPermissionBlockFromConversation($item));
+               // For now only send to these contacts:
+               $networks = [Protocol::ACTIVITYPUB, Protocol::OSTATUS];
+
+               $data = ['to' => [], 'cc' => [], 'bcc' => []];
 
                $actor_profile = APContact::getByURL($item['author-link']);
 
                $terms = Term::tagArrayFromItemId($item['id'], TERM_MENTION);
 
-               $contacts[$item['author-link']] = $item['author-link'];
-
                if (!$item['private']) {
+                       $data = array_merge($data, self::fetchPermissionBlockFromConversation($item));
+
                        $data['to'][] = ActivityPub::PUBLIC_COLLECTION;
                        if (!empty($actor_profile['followers'])) {
                                $data['cc'][] = $actor_profile['followers'];
@@ -316,9 +323,8 @@ class Transmitter
 
                        foreach ($terms as $term) {
                                $profile = APContact::getByURL($term['url'], false);
-                               if (!empty($profile) && empty($contacts[$profile['url']])) {
-                                       $data['cc'][] = $profile['url'];
-                                       $contacts[$profile['url']] = $profile['url'];
+                               if (!empty($profile)) {
+                                       $data['to'][] = $profile['url'];
                                }
                        }
                } else {
@@ -329,22 +335,24 @@ class Transmitter
                        foreach ($terms as $term) {
                                $cid = Contact::getIdForURL($term['url'], $item['uid']);
                                if (!empty($cid) && in_array($cid, $receiver_list)) {
-                                       $contact = DBA::selectFirst('contact', ['url'], ['id' => $cid, 'network' => Protocol::ACTIVITYPUB]);
-                                       $data['to'][] = $contact['url'];
-                                       $contacts[$contact['url']] = $contact['url'];
+                                       $contact = DBA::selectFirst('contact', ['url'], ['id' => $cid, 'network' => $networks]);
+                                       if (DBA::isResult($contact) && !empty($profile = APContact::getByURL($contact['url'], false))) {
+                                               $data['to'][] = $profile['url'];
+                                       }
                                }
                        }
 
                        foreach ($receiver_list as $receiver) {
-                               $contact = DBA::selectFirst('contact', ['url'], ['id' => $receiver, 'network' => Protocol::ACTIVITYPUB]);
-                               if (empty($contacts[$contact['url']])) {
-                                       $data['cc'][] = $contact['url'];
-                                       $contacts[$contact['url']] = $contact['url'];
+                               $contact = DBA::selectFirst('contact', ['url'], ['id' => $receiver, 'network' => $networks]);
+                               if (DBA::isResult($contact) && !empty($profile = APContact::getByURL($contact['url'], false))) {
+                                       // BCC is currently deactivated, due to Pleroma and Mastodon not reacting like expected
+                                       // $data['bcc'][] = $profile['url'];
+                                       $data['cc'][] = $profile['url'];
                                }
                        }
                }
 
-               $parents = Item::select(['id', 'author-link', 'owner-link', 'gravity'], ['parent' => $item['parent']]);
+               $parents = Item::select(['id', 'author-link', 'owner-link', 'gravity', 'uri'], ['parent' => $item['parent']]);
                while ($parent = Item::fetch($parents)) {
                        // Don't include data from future posts
                        if ($parent['id'] >= $item['id']) {
@@ -352,9 +360,12 @@ class Transmitter
                        }
 
                        $profile = APContact::getByURL($parent['author-link'], false);
-                       if (!empty($profile) && empty($contacts[$profile['url']])) {
-                               $data['cc'][] = $profile['url'];
-                               $contacts[$profile['url']] = $profile['url'];
+                       if (!empty($profile)) {
+                               if ($parent['uri'] == $item['thr-parent']) {
+                                       $data['to'][] = $profile['url'];
+                               } else {
+                                       $data['cc'][] = $profile['url'];
+                               }
                        }
 
                        if ($item['gravity'] != GRAVITY_PARENT) {
@@ -362,42 +373,88 @@ class Transmitter
                        }
 
                        $profile = APContact::getByURL($parent['owner-link'], false);
-                       if (!empty($profile) && empty($contacts[$profile['url']])) {
+                       if (!empty($profile)) {
                                $data['cc'][] = $profile['url'];
-                               $contacts[$profile['url']] = $profile['url'];
                        }
                }
                DBA::close($parents);
 
-               if (empty($data['to'])) {
-                       $data['to'] = $data['cc'];
-                       $data['cc'] = [];
+               $data['to'] = array_unique($data['to']);
+               $data['cc'] = array_unique($data['cc']);
+               $data['bcc'] = array_unique($data['bcc']);
+
+               if (($key = array_search($item['author-link'], $data['to'])) !== false) {
+                       unset($data['to'][$key]);
                }
 
-               return $data;
+               if (($key = array_search($item['author-link'], $data['cc'])) !== false) {
+                       unset($data['cc'][$key]);
+               }
+
+               if (($key = array_search($item['author-link'], $data['bcc'])) !== false) {
+                       unset($data['bcc'][$key]);
+               }
+
+               foreach ($data['to'] as $to) {
+                       if (($key = array_search($to, $data['cc'])) !== false) {
+                               unset($data['cc'][$key]);
+                       }
+
+                       if (($key = array_search($to, $data['bcc'])) !== false) {
+                               unset($data['bcc'][$key]);
+                       }
+               }
+
+               foreach ($data['cc'] as $cc) {
+                       if (($key = array_search($cc, $data['bcc'])) !== false) {
+                               unset($data['bcc'][$key]);
+                       }
+               }
+
+               $receivers = ['to' => array_values($data['to']), 'cc' => array_values($data['cc']), 'bcc' => array_values($data['bcc'])];
+
+               if (!$blindcopy) {
+                       unset($receivers['bcc']);
+               }
+
+               return $receivers;
        }
 
        /**
-        * @brief Fetches a list of inboxes of followers of a given user
+        * Fetches a list of inboxes of followers of a given user
         *
         * @param integer $uid User ID
+        * @param boolean $personal fetch personal inboxes
         *
         * @return array of follower inboxes
         */
-       public static function fetchTargetInboxesforUser($uid)
+       public static function fetchTargetInboxesforUser($uid, $personal = false)
        {
                $inboxes = [];
 
-               $condition = ['uid' => $uid, 'network' => Protocol::ACTIVITYPUB, 'archive' => false, 'pending' => false];
+               // Will be activated in a later step
+               // $networks = [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS];
+
+               // For now only send to these contacts:
+               $networks = [Protocol::ACTIVITYPUB, Protocol::OSTATUS];
+
+               $condition = ['uid' => $uid, 'network' => $networks, 'archive' => false, 'pending' => false];
 
                if (!empty($uid)) {
                        $condition['rel'] = [Contact::FOLLOWER, Contact::FRIEND];
                }
 
-               $contacts = DBA::select('contact', ['notify', 'batch'], $condition);
+               $contacts = DBA::select('contact', ['url'], $condition);
                while ($contact = DBA::fetch($contacts)) {
-                       $contact = defaults($contact, 'batch', $contact['notify']);
-                       $inboxes[$contact] = $contact;
+                       $profile = APContact::getByURL($contact['url'], false);
+                       if (!empty($profile)) {
+                               if (empty($profile['sharedinbox']) || $personal) {
+                                       $target = $profile['inbox'];
+                               } else {
+                                       $target = $profile['sharedinbox'];
+                               }
+                               $inboxes[$target] = $target;
+                       }
                }
                DBA::close($contacts);
 
@@ -405,16 +462,17 @@ class Transmitter
        }
 
        /**
-        * @brief Fetches an array of inboxes for the given item and user
+        * Fetches an array of inboxes for the given item and user
         *
         * @param array $item
         * @param integer $uid User ID
+        * @param boolean $personal fetch personal inboxes
         *
         * @return array with inboxes
         */
-       public static function fetchTargetInboxes($item, $uid)
+       public static function fetchTargetInboxes($item, $uid, $personal = false)
        {
-               $permissions = self::createPermissionBlockForItem($item);
+               $permissions = self::createPermissionBlockForItem($item, true);
                if (empty($permissions)) {
                        return [];
                }
@@ -422,9 +480,9 @@ class Transmitter
                $inboxes = [];
 
                if ($item['gravity'] == GRAVITY_ACTIVITY) {
-                       $item_profile = APContact::getByURL($item['author-link']);
+                       $item_profile = APContact::getByURL($item['author-link'], false);
                } else {
-                       $item_profile = APContact::getByURL($item['owner-link']);
+                       $item_profile = APContact::getByURL($item['owner-link'], false);
                }
 
                foreach (['to', 'cc', 'bto', 'bcc'] as $element) {
@@ -432,13 +490,19 @@ class Transmitter
                                continue;
                        }
 
+                       $blindcopy = in_array($element, ['bto', 'bcc']);
+
                        foreach ($permissions[$element] as $receiver) {
                                if ($receiver == $item_profile['followers']) {
-                                       $inboxes = self::fetchTargetInboxesforUser($uid);
+                                       $inboxes = array_merge($inboxes, self::fetchTargetInboxesforUser($uid, $personal));
                                } else {
-                                       $profile = APContact::getByURL($receiver);
+                                       $profile = APContact::getByURL($receiver, false);
                                        if (!empty($profile)) {
-                                               $target = defaults($profile, 'sharedinbox', $profile['inbox']);
+                                               if (empty($profile['sharedinbox']) || $personal || $blindcopy) {
+                                                       $target = $profile['inbox'];
+                                               } else {
+                                                       $target = $profile['sharedinbox'];
+                                               }
                                                $inboxes[$target] = $target;
                                        }
                                }
@@ -449,7 +513,7 @@ class Transmitter
        }
 
        /**
-        * @brief Returns the activity type of a given item
+        * Returns the activity type of a given item
         *
         * @param array $item
         *
@@ -457,7 +521,9 @@ class Transmitter
         */
        private static function getTypeOfItem($item)
        {
-               if ($item['verb'] == ACTIVITY_POST) {
+               if (!empty(Diaspora::isReshare($item['body'], false))) {
+                       $type = 'Announce';
+               } elseif ($item['verb'] == ACTIVITY_POST) {
                        if ($item['created'] == $item['edited']) {
                                $type = 'Create';
                        } else {
@@ -481,7 +547,32 @@ class Transmitter
        }
 
        /**
-        * @brief Creates an activity array for a given item id
+        * Creates the activity or fetches it from the cache
+        *
+        * @param integer $item_id
+        * @param boolean $force   Force new cache entry
+        *
+        * @return array with the activity
+        */
+       public static function createCachedActivityFromItem($item_id, $force = false)
+       {
+               $cachekey = 'APDelivery:createActivity:' . $item_id;
+
+               if (!$force) {
+                       $data = Cache::get($cachekey);
+                       if (!is_null($data)) {
+                               return $data;
+                       }
+               }
+
+               $data = ActivityPub\Transmitter::createActivityFromItem($item_id);
+
+               Cache::set($cachekey, $data, Cache::QUARTER_HOUR);
+               return $data;
+       }
+
+       /**
+        * Creates an activity array for a given item id
         *
         * @param integer $item_id
         * @param boolean $object_mode Is the activity item is used inside another object?
@@ -525,13 +616,21 @@ class Transmitter
 
                $data['published'] = DateTimeFormat::utc($item['created'] . '+00:00', DateTimeFormat::ATOM);
 
-               $data = array_merge($data, self::createPermissionBlockForItem($item));
+               $data['instrument'] = ['type' => 'Service', 'name' => BaseObject::getApp()->getUserAgent()];
+
+               $data = array_merge($data, self::createPermissionBlockForItem($item, false));
 
-               if (in_array($data['type'], ['Create', 'Update', 'Announce', 'Delete'])) {
+               if (in_array($data['type'], ['Create', 'Update', 'Delete'])) {
                        $data['object'] = self::createNote($item);
+               } elseif ($data['type'] == 'Announce') {
+                       $data['object'] = self::createAnnounce($item);
                } elseif ($data['type'] == 'Undo') {
                        $data['object'] = self::createActivityFromItem($item_id, true);
                } else {
+                       $data['diaspora:guid'] = $item['guid'];
+                       if (!empty($item['signed_text'])) {
+                               $data['diaspora:like'] = $item['signed_text'];
+                       }
                        $data['object'] = $item['thr-parent'];
                }
 
@@ -547,7 +646,7 @@ class Transmitter
        }
 
        /**
-        * @brief Creates an object array for a given item id
+        * Creates an object array for a given item id
         *
         * @param integer $item_id
         *
@@ -568,7 +667,41 @@ class Transmitter
        }
 
        /**
-        * @brief Returns a tag array for a given item array
+        * Creates a location entry for a given item array
+        *
+        * @param array $item
+        *
+        * @return array with location array
+        */
+       private static function createLocation($item)
+       {
+               $location = ['type' => 'Place'];
+
+               if (!empty($item['location'])) {
+                       $location['name'] = $item['location'];
+               }
+
+               $coord = [];
+
+               if (empty($item['coord'])) {
+                       $coord = Map::getCoordinates($item['location']);
+               } else {
+                       $coords = explode(' ', $item['coord']);
+                       if (count($coords) == 2) {
+                               $coord = ['lat' => $coords[0], 'lon' => $coords[1]];
+                       }
+               }
+
+               if (!empty($coord['lat']) && !empty($coord['lon'])) {
+                       $location['latitude'] = $coord['lat'];
+                       $location['longitude'] = $coord['lon'];
+               }
+
+               return $location;
+       }
+
+       /**
+        * Returns a tag array for a given item array
         *
         * @param array $item
         *
@@ -597,7 +730,7 @@ class Transmitter
        }
 
        /**
-        * @brief Adds attachment data to the JSON document
+        * Adds attachment data to the JSON document
         *
         * @param array $item Data of the item that is to be posted
         * @param text $type Object type
@@ -651,8 +784,28 @@ class Transmitter
                return $attachments;
        }
 
+        /**
+        * @brief Callback function to replace a Friendica style mention in a mention that is used on AP
+        *
+        * @param array $match Matching values for the callback
+        * @return string Replaced mention
+        */
+       private static function mentionCallback($match)
+       {
+               if (empty($match[1])) {
+                       return;
+               }
+
+               $data = Contact::getDetailsByURL($match[1]);
+               if (empty($data) || empty($data['nick'])) {
+                       return;
+               }
+
+               return '@[url=' . $data['url'] . ']' . $data['nick'] . '[/url]';
+       }
+
        /**
-        * @brief Remove image elements and replaces them with links to the image
+        * Remove image elements and replaces them with links to the image
         *
         * @param string $body
         *
@@ -670,7 +823,7 @@ class Transmitter
        }
 
        /**
-        * @brief Fetches the "context" value for a givem item array from the "conversation" table
+        * Fetches the "context" value for a givem item array from the "conversation" table
         *
         * @param array $item
         *
@@ -690,7 +843,7 @@ class Transmitter
        }
 
        /**
-        * @brief Returns if the post contains sensitive content ("nsfw")
+        * Returns if the post contains sensitive content ("nsfw")
         *
         * @param integer $item_id
         *
@@ -703,7 +856,33 @@ class Transmitter
        }
 
        /**
-        * @brief Creates a note/article object array
+        * Creates event data
+        *
+        * @param array $item
+        *
+        * @return array with the event data
+        */
+       public static function createEvent($item)
+       {
+               $event = [];
+               $event['name'] = $item['event-summary'];
+               $event['content'] = BBCode::convert($item['event-desc'], false, 7);
+               $event['startTime'] = DateTimeFormat::utc($item['event-start'] . '+00:00', DateTimeFormat::ATOM);
+
+               if (!$item['event-nofinish']) {
+                       $event['endTime'] = DateTimeFormat::utc($item['event-finish'] . '+00:00', DateTimeFormat::ATOM);
+               }
+
+               if (!empty($item['event-location'])) {
+                       $item['location'] = $item['event-location'];
+                       $event['location'] = self::createLocation($item);
+               }
+
+               return $event;
+       }
+
+       /**
+        * Creates a note/article object array
         *
         * @param array $item
         *
@@ -711,7 +890,9 @@ class Transmitter
         */
        public static function createNote($item)
        {
-               if (!empty($item['title'])) {
+               if ($item['event-type'] == 'event') {
+                       $type = 'Event';
+               } elseif (!empty($item['title'])) {
                        $type = 'Article';
                } else {
                        $type = 'Note';
@@ -746,12 +927,11 @@ class Transmitter
 
                $data['url'] = $item['plink'];
                $data['attributedTo'] = $item['author-link'];
-               $data['actor'] = $item['author-link'];
                $data['sensitive'] = self::isSensitive($item['id']);
                $data['context'] = self::fetchContextURLForItem($item);
 
                if (!empty($item['title'])) {
-                       $data['name'] = BBCode::convert($item['title'], false, 7);
+                       $data['name'] = BBCode::toPlaintext($item['title'], false);
                }
 
                $body = $item['body'];
@@ -760,7 +940,15 @@ class Transmitter
                        $body = self::removePictures($body);
                }
 
-               $data['content'] = BBCode::convert($body, false, 7);
+               if ($type == 'Event') {
+                       $data = array_merge($data, self::createEvent($item));
+               } else {
+                       $regexp = "/[@!]\[url\=([^\[\]]*)\].*?\[\/url\]/ism";
+                       $body = preg_replace_callback($regexp, ['self', 'mentionCallback'], $body);
+
+                       $data['content'] = BBCode::convert($body, false, 7);
+               }
+
                $data['source'] = ['content' => $item['body'], 'mediaType' => "text/bbcode"];
 
                if (!empty($item['signed_text']) && ($item['uri'] != $item['thr-parent'])) {
@@ -769,16 +957,76 @@ class Transmitter
 
                $data['attachment'] = self::createAttachmentList($item, $type);
                $data['tag'] = self::createTagList($item);
-               $data = array_merge($data, self::createPermissionBlockForItem($item));
+
+               if (empty($data['location']) && (!empty($item['coord']) || !empty($item['location']))) {
+                       $data['location'] = self::createLocation($item);
+               }
+
+               if (!empty($item['app'])) {
+                       $data['generator'] = ['type' => 'Application', 'name' => $item['app']];
+               }
+
+               $data = array_merge($data, self::createPermissionBlockForItem($item, false));
 
                return $data;
        }
 
        /**
-        * @brief Transmits a profile deletion to a given inbox
+        * Creates an announce object entry
+        *
+        * @param array $item
+        *
+        * @return string with announced object url
+        */
+       public static function createAnnounce($item)
+       {
+               $announce = api_share_as_retweet($item);
+               if (empty($announce['plink'])) {
+                       return self::createNote($item);
+               }
+
+               return $announce['plink'];
+       }
+
+       /**
+        * Transmits a contact suggestion to a given inbox
         *
         * @param integer $uid User ID
         * @param string $inbox Target inbox
+        * @param integer $suggestion_id Suggestion ID
+        *
+        * @return boolean was the transmission successful?
+        */
+       public static function sendContactSuggestion($uid, $inbox, $suggestion_id)
+       {
+               $owner = User::getOwnerDataById($uid);
+               $profile = APContact::getByURL($owner['url']);
+
+               $suggestion = DBA::selectFirst('fsuggest', ['url', 'note', 'created'], ['id' => $suggestion_id]);
+
+               $data = ['@context' => 'https://www.w3.org/ns/activitystreams',
+                       'id' => System::baseUrl() . '/activity/' . System::createGUID(),
+                       'type' => 'Announce',
+                       'actor' => $owner['url'],
+                       'object' => $suggestion['url'],
+                       'content' => $suggestion['note'],
+                       'instrument' => ['type' => 'Service', 'name' => BaseObject::getApp()->getUserAgent()],
+                       'to' => [ActivityPub::PUBLIC_COLLECTION],
+                       'cc' => []];
+
+               $signed = LDSignature::sign($data, $owner);
+
+               Logger::log('Deliver profile deletion for user ' . $uid . ' to ' . $inbox . ' via ActivityPub', LOGGER_DEBUG);
+               return HTTPSignature::transmit($signed, $inbox, $uid);
+       }
+
+       /**
+        * Transmits a profile deletion to a given inbox
+        *
+        * @param integer $uid User ID
+        * @param string $inbox Target inbox
+        *
+        * @return boolean was the transmission successful?
         */
        public static function sendProfileDeletion($uid, $inbox)
        {
@@ -791,20 +1039,23 @@ class Transmitter
                        'actor' => $owner['url'],
                        'object' => $owner['url'],
                        'published' => DateTimeFormat::utcNow(DateTimeFormat::ATOM),
+                       'instrument' => ['type' => 'Service', 'name' => BaseObject::getApp()->getUserAgent()],
                        'to' => [ActivityPub::PUBLIC_COLLECTION],
                        'cc' => []];
 
                $signed = LDSignature::sign($data, $owner);
 
-               logger('Deliver profile deletion for user ' . $uid . ' to ' . $inbox . ' via ActivityPub', LOGGER_DEBUG);
-               HTTPSignature::transmit($signed, $inbox, $uid);
+               Logger::log('Deliver profile deletion for user ' . $uid . ' to ' . $inbox . ' via ActivityPub', LOGGER_DEBUG);
+               return HTTPSignature::transmit($signed, $inbox, $uid);
        }
 
        /**
-        * @brief Transmits a profile change to a given inbox
+        * Transmits a profile change to a given inbox
         *
         * @param integer $uid User ID
         * @param string $inbox Target inbox
+        *
+        * @return boolean was the transmission successful?
         */
        public static function sendProfileUpdate($uid, $inbox)
        {
@@ -817,17 +1068,18 @@ class Transmitter
                        'actor' => $owner['url'],
                        'object' => self::getProfile($uid),
                        'published' => DateTimeFormat::utcNow(DateTimeFormat::ATOM),
+                       'instrument' => ['type' => 'Service', 'name' => BaseObject::getApp()->getUserAgent()],
                        'to' => [$profile['followers']],
                        'cc' => []];
 
                $signed = LDSignature::sign($data, $owner);
 
-               logger('Deliver profile update for user ' . $uid . ' to ' . $inbox . ' via ActivityPub', LOGGER_DEBUG);
-               HTTPSignature::transmit($signed, $inbox, $uid);
+               Logger::log('Deliver profile update for user ' . $uid . ' to ' . $inbox . ' via ActivityPub', LOGGER_DEBUG);
+               return HTTPSignature::transmit($signed, $inbox, $uid);
        }
 
        /**
-        * @brief Transmits a given activity to a target
+        * Transmits a given activity to a target
         *
         * @param array $activity
         * @param string $target Target profile
@@ -844,16 +1096,17 @@ class Transmitter
                        'type' => $activity,
                        'actor' => $owner['url'],
                        'object' => $profile['url'],
+                       'instrument' => ['type' => 'Service', 'name' => BaseObject::getApp()->getUserAgent()],
                        'to' => $profile['url']];
 
-               logger('Sending activity ' . $activity . ' to ' . $target . ' for user ' . $uid, LOGGER_DEBUG);
+               Logger::log('Sending activity ' . $activity . ' to ' . $target . ' for user ' . $uid, LOGGER_DEBUG);
 
                $signed = LDSignature::sign($data, $owner);
                HTTPSignature::transmit($signed, $profile['inbox'], $uid);
        }
 
        /**
-        * @brief Transmit a message that the contact request had been accepted
+        * Transmit a message that the contact request had been accepted
         *
         * @param string $target Target profile
         * @param $id
@@ -871,16 +1124,17 @@ class Transmitter
                        'object' => ['id' => $id, 'type' => 'Follow',
                                'actor' => $profile['url'],
                                'object' => $owner['url']],
+                       'instrument' => ['type' => 'Service', 'name' => BaseObject::getApp()->getUserAgent()],
                        'to' => $profile['url']];
 
-               logger('Sending accept to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG);
+               Logger::log('Sending accept to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG);
 
                $signed = LDSignature::sign($data, $owner);
                HTTPSignature::transmit($signed, $profile['inbox'], $uid);
        }
 
        /**
-        * @brief Reject a contact request or terminates the contact relation
+        * Reject a contact request or terminates the contact relation
         *
         * @param string $target Target profile
         * @param $id
@@ -898,16 +1152,17 @@ class Transmitter
                        'object' => ['id' => $id, 'type' => 'Follow',
                                'actor' => $profile['url'],
                                'object' => $owner['url']],
+                       'instrument' => ['type' => 'Service', 'name' => BaseObject::getApp()->getUserAgent()],
                        'to' => $profile['url']];
 
-               logger('Sending reject to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG);
+               Logger::log('Sending reject to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG);
 
                $signed = LDSignature::sign($data, $owner);
                HTTPSignature::transmit($signed, $profile['inbox'], $uid);
        }
 
        /**
-        * @brief Transmits a message that we don't want to follow this contact anymore
+        * Transmits a message that we don't want to follow this contact anymore
         *
         * @param string $target Target profile
         * @param integer $uid User ID
@@ -926,9 +1181,10 @@ class Transmitter
                        'object' => ['id' => $id, 'type' => 'Follow',
                                'actor' => $owner['url'],
                                'object' => $profile['url']],
+                       'instrument' => ['type' => 'Service', 'name' => BaseObject::getApp()->getUserAgent()],
                        'to' => $profile['url']];
 
-               logger('Sending undo to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG);
+               Logger::log('Sending undo to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG);
 
                $signed = LDSignature::sign($data, $owner);
                HTTPSignature::transmit($signed, $profile['inbox'], $uid);