]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/ActivityPub/Transmitter.php
Merge remote-tracking branch 'upstream/develop' into quote
[friendica.git] / src / Protocol / ActivityPub / Transmitter.php
index 023bd5c83cce179c8c6cd16d2f9408b099f41f72..6a601b6f98636e2791dfbb67414f2ffb3977a20b 100644 (file)
@@ -21,6 +21,7 @@
 
 namespace Friendica\Protocol\ActivityPub;
 
+use Friendica\App;
 use Friendica\Content\Feature;
 use Friendica\Content\Text\BBCode;
 use Friendica\Core\Cache\Enum\Duration;
@@ -31,7 +32,6 @@ use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model\APContact;
 use Friendica\Model\Contact;
-use Friendica\Model\Conversation;
 use Friendica\Model\GServer;
 use Friendica\Model\Item;
 use Friendica\Model\Photo;
@@ -41,6 +41,7 @@ use Friendica\Model\User;
 use Friendica\Network\HTTPException;
 use Friendica\Protocol\Activity;
 use Friendica\Protocol\ActivityPub;
+use Friendica\Protocol\Diaspora;
 use Friendica\Protocol\Relay;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\HTTPSignature;
@@ -60,7 +61,6 @@ class Transmitter
 {
        const CACHEKEY_FEATURED = 'transmitter:getFeatured:';
        const CACHEKEY_CONTACTS = 'transmitter:getContacts:';
-       const CACHEKEY_OUTBOX   = 'transmitter:getOutbox:';
 
        /**
         * Add relay servers to the list of inboxes
@@ -68,7 +68,7 @@ class Transmitter
         * @param array $inboxes
         * @return array inboxes with added relay servers
         */
-       public static function addRelayServerInboxes(array $inboxes = [])
+       public static function addRelayServerInboxes(array $inboxes = []): array
        {
                foreach (Relay::getList(['inbox']) as $contact) {
                        $inboxes[$contact['inbox']] = $contact['inbox'];
@@ -83,7 +83,7 @@ class Transmitter
         * @param array $inboxes
         * @return array inboxes with added relay servers
         */
-       public static function addRelayServerInboxesForItem(int $item_id, array $inboxes = [])
+       public static function addRelayServerInboxesForItem(int $item_id, array $inboxes = []): array
        {
                $item = Post::selectFirst(['uid'], ['id' => $item_id]);
                if (empty($item)) {
@@ -103,12 +103,12 @@ class Transmitter
        }
 
        /**
-        * Subscribe to a relay
+        * Subscribe to a relay and updates contact on success
         *
         * @param string $url Subscribe actor url
         * @return bool success
         */
-       public static function sendRelayFollow(string $url)
+       public static function sendRelayFollow(string $url): bool
        {
                $contact = Contact::getByURL($url);
                if (empty($contact)) {
@@ -125,13 +125,13 @@ class Transmitter
        }
 
        /**
-        * Unsubscribe from a relay
+        * Unsubscribe from a relay and updates contact on success or forced
         *
         * @param string $url   Subscribe actor url
         * @param bool   $force Set the relay status as non follower even if unsubscribe hadn't worked
         * @return bool success
         */
-       public static function sendRelayUndoFollow(string $url, bool $force = false)
+       public static function sendRelayUndoFollow(string $url, bool $force = false): bool
        {
                $contact = Contact::getByURL($url);
                if (empty($contact)) {
@@ -139,6 +139,7 @@ class Transmitter
                }
 
                $success = self::sendContactUndo($url, $contact['id'], 0);
+
                if ($success || $force) {
                        Contact::update(['rel' => Contact::NOTHING], ['id' => $contact['id']]);
                }
@@ -155,11 +156,10 @@ class Transmitter
         * @param integer $page      Page number
         * @param string  $requester URL of the requester
         * @param boolean $nocache   Wether to bypass caching
-        *
         * @return array of owners
         * @throws \Exception
         */
-       public static function getContacts(array $owner, array $rel, string $module, int $page = null, string $requester = null, $nocache = false)
+       public static function getContacts(array $owner, array $rel, string $module, int $page = null, string $requester = null, bool $nocache = false): array
        {
                if (empty($page)) {
                        $cachekey = self::CACHEKEY_CONTACTS . $module . ':'. $owner['uid'];
@@ -246,21 +246,12 @@ class Transmitter
         * @param integer $page      Page number
         * @param string  $requester URL of requesting account
         * @param boolean $nocache   Wether to bypass caching
-        *
         * @return array of posts
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         * @throws \ImagickException
         */
-       public static function getOutbox(array $owner, int $page = null, string $requester = '', $nocache = false)
+       public static function getOutbox(array $owner, int $page = null, string $requester = '', bool $nocache = false): array
        {
-               if (empty($page)) {
-                       $cachekey = self::CACHEKEY_OUTBOX . $owner['uid'];
-                       $result = DI::cache()->get($cachekey);
-                       if (!$nocache && !is_null($result)) {
-                               return $result;
-                       }
-               }
-
                $condition = ['private' => [Item::PUBLIC, Item::UNLISTED]];
 
                if (!empty($requester)) {
@@ -274,22 +265,23 @@ class Transmitter
                        }
                }
 
-               $condition = array_merge($condition,
-                       ['uid'           => $owner['uid'],
+               $condition = array_merge($condition, [
+                       'uid'           => $owner['uid'],
                        'author-id'      => Contact::getIdForURL($owner['url'], 0, false),
-                       'gravity'        => [GRAVITY_PARENT, GRAVITY_COMMENT],
+                       'gravity'        => [Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT],
                        'network'        => Protocol::FEDERATED,
                        'parent-network' => Protocol::FEDERATED,
                        'origin'         => true,
                        'deleted'        => false,
-                       'visible'        => true]);
+                       'visible'        => true
+               ]);
 
-               $count = Post::count($condition);
+               $apcontact = APContact::getByURL($owner['url']);
 
                $data = ['@context' => ActivityPub::CONTEXT];
                $data['id'] = DI::baseUrl() . '/outbox/' . $owner['nickname'];
                $data['type'] = 'OrderedCollection';
-               $data['totalItems'] = $count;
+               $data['totalItems'] = $apcontact['statuses_count'] ?? 0;
 
                if (!empty($page)) {
                        $data['id'] .= '?' . http_build_query(['page' => $page]);
@@ -317,15 +309,17 @@ class Transmitter
                                $data['next'] = DI::baseUrl() . '/outbox/' . $owner['nickname'] . '?page=' . ($page + 1);
                        }
 
+                       // Fix the cached total item count when it is lower than the real count
+                       $total = (($page - 1) * 20) + $data['totalItems'];
+                       if ($total > $data['totalItems']) {
+                               $data['totalItems'] = $total;
+                       }
+
                        $data['partOf'] = DI::baseUrl() . '/outbox/' . $owner['nickname'];
 
                        $data['orderedItems'] = $list;
                }
 
-               if (!empty($cachekey)) {
-                       DI::cache()->set($cachekey, $data, Duration::DAY);
-               }
-
                return $data;
        }
 
@@ -340,7 +334,7 @@ class Transmitter
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         * @throws \ImagickException
         */
-       public static function getFeatured(array $owner, int $page = null, $nocache = false)
+       public static function getFeatured(array $owner, int $page = null, bool $nocache = false): array
        {
                if (empty($page)) {
                        $cachekey = self::CACHEKEY_FEATURED . $owner['uid'];
@@ -355,16 +349,17 @@ class Transmitter
                $condition = ["`uri-id` IN (SELECT `uri-id` FROM `collection-view` WHERE `cid` = ? AND `type` = ?)",
                        $owner_cid, Post\Collection::FEATURED];
 
-               $condition = DBA::mergeConditions($condition,
-                       ['uid'           => $owner['uid'],
+               $condition = DBA::mergeConditions($condition, [
+                       'uid'           => $owner['uid'],
                        'author-id'      => $owner_cid,
                        'private'        => [Item::PUBLIC, Item::UNLISTED],
-                       'gravity'        => [GRAVITY_PARENT, GRAVITY_COMMENT],
+                       'gravity'        => [Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT],
                        'network'        => Protocol::FEDERATED,
                        'parent-network' => Protocol::FEDERATED,
                        'origin'         => true,
                        'deleted'        => false,
-                       'visible'        => true]);
+                       'visible'        => true
+               ]);
 
                $count = Post::count($condition);
 
@@ -418,11 +413,13 @@ class Transmitter
         *
         * @return array with service data
         */
-       private static function getService()
+       private static function getService(): array
        {
-               return ['type' => 'Service',
-                       'name' =>  FRIENDICA_PLATFORM . " '" . FRIENDICA_CODENAME . "' " . FRIENDICA_VERSION . '-' . DB_UPDATE_VERSION,
-                       'url' => DI::baseUrl()->get()];
+               return [
+                       'type' => 'Service',
+                       'name' =>  App::PLATFORM . " '" . App::CODENAME . "' " . App::VERSION . '-' . DB_UPDATE_VERSION,
+                       'url' => DI::baseUrl()->get()
+               ];
        }
 
        /**
@@ -537,7 +534,7 @@ class Transmitter
         * @return array
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public static function getDeletedUser($username)
+       public static function getDeletedUser(string $username): array
        {
                return [
                        '@context' => ActivityPub::CONTEXT,
@@ -559,7 +556,7 @@ class Transmitter
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         * @throws \ImagickException
         */
-       private static function fetchPermissionBlockFromThreadParent(array $item, bool $is_forum_thread)
+       private static function fetchPermissionBlockFromThreadParent(array $item, bool $is_forum_thread): array
        {
                if (empty($item['thr-parent-id'])) {
                        return [];
@@ -582,7 +579,7 @@ class Transmitter
                $item_profile = APContact::getByURL($item['author-link']);
                $exclude[] = $item['author-link'];
 
-               if ($item['gravity'] == GRAVITY_PARENT) {
+               if ($item['gravity'] == Item::GRAVITY_PARENT) {
                        $exclude[] = $item['owner-link'];
                }
 
@@ -606,7 +603,7 @@ class Transmitter
         * @param integer $item_id
         * @return boolean "true" if the post is from ActivityPub
         */
-       private static function isAPPost(int $item_id)
+       private static function isAPPost(int $item_id): bool
        {
                if (empty($item_id)) {
                        return false;
@@ -626,7 +623,7 @@ class Transmitter
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         * @throws \ImagickException
         */
-       private static function createPermissionBlockForItem($item, $blindcopy, $last_id = 0)
+       private static function createPermissionBlockForItem(array $item, bool $blindcopy, int $last_id = 0): array
        {
                if ($last_id == 0) {
                        $last_id = $item['id'];
@@ -653,7 +650,7 @@ class Transmitter
                }
 
                $parent = Post::selectFirst(['causer-link', 'post-reason'], ['id' => $item['parent']]);
-               if (($parent['post-reason'] == Item::PR_ANNOUNCEMENT) && !empty($parent['causer-link'])) {
+               if (!empty($parent) && ($parent['post-reason'] == Item::PR_ANNOUNCEMENT) && !empty($parent['causer-link'])) {
                        $profile = APContact::getByURL($parent['causer-link'], false);
                        $is_forum_thread = isset($profile['type']) && $profile['type'] == 'Group';
                } else {
@@ -670,7 +667,7 @@ class Transmitter
 
                $data = ['to' => [], 'cc' => [], 'bcc' => []];
 
-               if ($item['gravity'] == GRAVITY_PARENT) {
+               if ($item['gravity'] == Item::GRAVITY_PARENT) {
                        $actor_profile = APContact::getByURL($item['owner-link']);
                } else {
                        $actor_profile = APContact::getByURL($item['author-link']);
@@ -758,10 +755,10 @@ class Transmitter
                if (!empty($item['parent'])) {
                        $parents = Post::select(['id', 'author-link', 'owner-link', 'gravity', 'uri'], ['parent' => $item['parent']], ['order' => ['id']]);
                        while ($parent = Post::fetch($parents)) {
-                               if ($parent['gravity'] == GRAVITY_PARENT) {
+                               if ($parent['gravity'] == Item::GRAVITY_PARENT) {
                                        $profile = APContact::getByURL($parent['owner-link'], false);
                                        if (!empty($profile)) {
-                                               if ($item['gravity'] != GRAVITY_PARENT) {
+                                               if ($item['gravity'] != Item::GRAVITY_PARENT) {
                                                        // Comments to forums are directed to the forum
                                                        // But comments to forums aren't directed to the followers collection
                                                        // This rule is only valid when the actor isn't the forum.
@@ -770,7 +767,7 @@ class Transmitter
                                                                $data['to'][] = $profile['url'];
                                                        } else {
                                                                $data['cc'][] = $profile['url'];
-                                                               if (($item['private'] != Item::PRIVATE) && !empty($actor_profile['followers'])&& !$is_forum_thread) {
+                                                               if (($item['private'] != Item::PRIVATE) && !empty($actor_profile['followers']) && (!$exclusive || !$is_forum_thread)) {
                                                                        $data['cc'][] = $actor_profile['followers'];
                                                                }
                                                        }
@@ -858,10 +855,9 @@ class Transmitter
         * Check if an inbox is archived
         *
         * @param string $url Inbox url
-        *
         * @return boolean "true" if inbox is archived
         */
-       public static function archivedInbox($url)
+       public static function archivedInbox(string $url): bool
        {
                return DBA::exists('inbox-status', ['url' => $url, 'archive' => true]);
        }
@@ -869,12 +865,12 @@ class Transmitter
        /**
         * Check if a given contact should be delivered via AP
         *
-        * @param array $contact
-        * @param array $networks
-        * @return bool
+        * @param array $contact Contact array
+        * @param array $networks Array with networks
+        * @return bool Whether the used protocol matches ACTIVITYPUB
         * @throws Exception
         */
-       private static function isAPContact(array $contact, array $networks)
+       private static function isAPContact(array $contact, array $networks): bool
        {
                if (in_array($contact['network'], $networks) || ($contact['protocol'] == Protocol::ACTIVITYPUB)) {
                        return true;
@@ -889,12 +885,11 @@ class Transmitter
         * @param integer $uid      User ID
         * @param boolean $personal fetch personal inboxes
         * @param boolean $all_ap   Retrieve all AP enabled inboxes
-        *
         * @return array of follower inboxes
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         * @throws \ImagickException
         */
-       public static function fetchTargetInboxesforUser($uid, $personal = false, bool $all_ap = false)
+       public static function fetchTargetInboxesforUser(int $uid, bool $personal = false, bool $all_ap = false): array
        {
                $inboxes = [];
 
@@ -915,7 +910,13 @@ class Transmitter
                        $networks = [Protocol::ACTIVITYPUB, Protocol::OSTATUS];
                }
 
-               $condition = ['uid' => $uid, 'archive' => false, 'pending' => false, 'blocked' => false, 'network' => Protocol::FEDERATED];
+               $condition = [
+                       'uid' => $uid,
+                       'archive' => false,
+                       'pending' => false,
+                       'blocked' => false,
+                       'network' => Protocol::FEDERATED,
+               ];
 
                if (!empty($uid)) {
                        $condition['rel'] = [Contact::FOLLOWER, Contact::FRIEND];
@@ -963,7 +964,7 @@ class Transmitter
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         * @throws \ImagickException
         */
-       public static function fetchTargetInboxes($item, $uid, $personal = false, $last_id = 0)
+       public static function fetchTargetInboxes(array $item, int $uid, bool $personal = false, int $last_id = 0): array
        {
                $permissions = self::createPermissionBlockForItem($item, true, $last_id);
                if (empty($permissions)) {
@@ -972,7 +973,7 @@ class Transmitter
 
                $inboxes = [];
 
-               if ($item['gravity'] == GRAVITY_ACTIVITY) {
+               if ($item['gravity'] == Item::GRAVITY_ACTIVITY) {
                        $item_profile = APContact::getByURL($item['author-link'], false);
                } else {
                        $item_profile = APContact::getByURL($item['owner-link'], false);
@@ -1022,12 +1023,11 @@ class Transmitter
        /**
         * Creates an array in the structure of the item table for a given mail id
         *
-        * @param integer $mail_id
-        *
+        * @param integer $mail_id Mail id
         * @return array
         * @throws \Exception
         */
-       public static function ItemArrayFromMail($mail_id, $use_title = false)
+       public static function getItemArrayFromMail(int $mail_id, bool $use_title = false): array
        {
                $mail = DBA::selectFirst('mail', [], ['id' => $mail_id]);
                if (!DBA::isResult($mail)) {
@@ -1062,7 +1062,7 @@ class Transmitter
                $mail['parent-uri']       = $reply['uri'];
                $mail['parent-uri-id']    = $reply['uri-id'];
                $mail['parent-author-id'] = Contact::getIdForURL($reply['from-url'], 0, false);
-               $mail['gravity']          = ($mail['reply'] ? GRAVITY_COMMENT: GRAVITY_PARENT);
+               $mail['gravity']          = ($mail['reply'] ? Item::GRAVITY_COMMENT: Item::GRAVITY_PARENT);
                $mail['event-type']       = '';
                $mail['language']         = '';
                $mail['parent']           = 0;
@@ -1079,9 +1079,9 @@ class Transmitter
         * @return array of activity
         * @throws \Exception
         */
-       public static function createActivityFromMail($mail_id, $object_mode = false)
+       public static function createActivityFromMail(int $mail_id, bool $object_mode = false): array
        {
-               $mail = self::ItemArrayFromMail($mail_id);
+               $mail = self::getItemArrayFromMail($mail_id);
                if (empty($mail)) {
                        return [];
                }
@@ -1133,18 +1133,17 @@ class Transmitter
        /**
         * Returns the activity type of a given item
         *
-        * @param array $item
-        *
+        * @param array $item Item array
         * @return string with activity type
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         * @throws \ImagickException
         */
-       private static function getTypeOfItem($item)
+       private static function getTypeOfItem(array $item): string
        {
                $reshared = false;
 
                // Only check for a reshare, if it is a real reshare and no quoted reshare
-               if (strpos($item['body'], "[share") === 0) {
+               if (strpos($item['body'], '[share') === 0) {
                        $announce = self::getAnnounceArray($item);
                        $reshared = !empty($announce);
                }
@@ -1183,15 +1182,14 @@ class Transmitter
        /**
         * Creates the activity or fetches it from the cache
         *
-        * @param integer $item_id
+        * @param integer $item_id Item id
         * @param boolean $force Force new cache entry
-        *
-        * @return array with the activity
+        * @return array|false activity or false on failure
         * @throws \Exception
         */
-       public static function createCachedActivityFromItem($item_id, $force = false)
+       public static function createCachedActivityFromItem(int $item_id, bool $force = false, bool $object_mode = false)
        {
-               $cachekey = 'APDelivery:createActivity:' . $item_id;
+               $cachekey = 'APDelivery:createActivity:' . $item_id . ':' . (int)$object_mode;
 
                if (!$force) {
                        $data = DI::cache()->get($cachekey);
@@ -1200,7 +1198,7 @@ class Transmitter
                        }
                }
 
-               $data = self::createActivityFromItem($item_id);
+               $data = self::createActivityFromItem($item_id, $object_mode);
 
                DI::cache()->set($cachekey, $data, Duration::QUARTER_HOUR);
                return $data;
@@ -1211,7 +1209,6 @@ class Transmitter
         *
         * @param integer $item_id
         * @param boolean $object_mode Is the activity item is used inside another object?
-        *
         * @return false|array
         * @throws \Exception
         */
@@ -1229,36 +1226,28 @@ class Transmitter
                }
 
                if (!$item['deleted']) {
-                       $condition = ['item-uri' => $item['uri'], 'protocol' => Conversation::PARCEL_ACTIVITYPUB];
-                       $conversation = DBA::selectFirst('conversation', ['source'], $condition);
-                       if (!$item['origin'] && DBA::isResult($conversation)) {
-                               $data = json_decode($conversation['source'], true);
-                               if (!empty($data['type'])) {
-                                       if (in_array($data['type'], ['Create', 'Update'])) {
-                                               if ($object_mode) {
-                                                       unset($data['@context']);
-                                                       unset($data['signature']);
-                                               }
-                                               Logger::info('Return stored conversation', ['item' => $item_id]);
-                                               return $data;
-                                       } elseif (in_array('as:' . $data['type'], Receiver::CONTENT_TYPES)) {
-                                               if (!empty($data['@context'])) {
-                                                       $context = $data['@context'];
-                                                       unset($data['@context']);
-                                               }
-                                               unset($data['actor']);
-                                               $object = $data;
-                                       }
+                       $data = Post\Activity::getByURIId($item['uri-id']);
+                       if (!$item['origin'] && !empty($data)) {
+                               if ($object_mode) {
+                                       unset($data['@context']);
+                                       unset($data['signature']);
                                }
+                               Logger::info('Return stored conversation', ['item' => $item_id]);
+                               return $data;
                        }
                }
 
+               if (!$item['origin'] && empty($object)) {
+                       Logger::debug('Post is not ours and is not stored', ['id' => $item_id, 'uri-id' => $item['uri-id']]);
+                       return false;
+               }
+
                $type = self::getTypeOfItem($item);
 
                if (!$object_mode) {
                        $data = ['@context' => $context ?? ActivityPub::CONTEXT];
 
-                       if ($item['deleted'] && ($item['gravity'] == GRAVITY_ACTIVITY)) {
+                       if ($item['deleted'] && ($item['gravity'] == Item::GRAVITY_ACTIVITY)) {
                                $type = 'Undo';
                        } elseif ($item['deleted']) {
                                $type = 'Delete';
@@ -1268,8 +1257,8 @@ class Transmitter
                }
 
                if ($type == 'Delete') {
-                       $data['id'] = Item::newURI($item['uid'], $item['guid']) . '/' . $type;;
-               } elseif (($item['gravity'] == GRAVITY_ACTIVITY) && ($type != 'Undo')) {
+                       $data['id'] = Item::newURI($item['guid']) . '/' . $type;;
+               } elseif (($item['gravity'] == Item::GRAVITY_ACTIVITY) && ($type != 'Undo')) {
                        $data['id'] = $item['uri'];
                } else {
                        $data['id'] = $item['uri'] . '/' . $type;
@@ -1277,7 +1266,7 @@ class Transmitter
 
                $data['type'] = $type;
 
-               if (($type != 'Announce') || ($item['gravity'] != GRAVITY_PARENT)) {
+               if (($type != 'Announce') || ($item['gravity'] != Item::GRAVITY_PARENT)) {
                        $data['actor'] = $item['author-link'];
                } else {
                        $data['actor'] = $item['owner-link'];
@@ -1335,11 +1324,10 @@ class Transmitter
        /**
         * Creates a location entry for a given item array
         *
-        * @param array $item
-        *
+        * @param array $item Item array
         * @return array with location array
         */
-       private static function createLocation($item)
+       private static function createLocation(array $item): array
        {
                $location = ['type' => 'Place'];
 
@@ -1369,12 +1357,12 @@ class Transmitter
        /**
         * Returns a tag array for a given item array
         *
-        * @param array $item
-        *
+        * @param array  $item      Item array
+        * @param string $quote_url Url of the attached quote link
         * @return array of tags
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       private static function createTagList($item)
+       private static function createTagList(array $item, string $quote_url): array
        {
                $tags = [];
 
@@ -1404,6 +1392,17 @@ class Transmitter
                        $tags[] = ['type' => 'Mention', 'href' => $announce['actor']['url'], 'name' => '@' . $announce['actor']['addr']];
                }
 
+               // @see https://codeberg.org/fediverse/fep/src/branch/main/feps/fep-e232.md
+               if (!empty($quote_url)) {
+                       // Currently deactivated because of compatibility issues with Pleroma
+                       //$tags[] = [
+                       //      'type'      => 'Link',
+                       //      'mediaType' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
+                       //      'href'      => $quote_url,
+                       //      'name'      => '♲ ' . BBCode::convertForUriId($item['uri-id'], $quote_url, BBCode::ACTIVITYPUB)
+                       //];
+               }
+
                return $tags;
        }
 
@@ -1411,51 +1410,39 @@ class Transmitter
         * Adds attachment data to the JSON document
         *
         * @param array  $item Data of the item that is to be posted
-        * @param string $type Object type
         *
         * @return array with attachment data
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       private static function createAttachmentList($item, $type)
+       private static function createAttachmentList(array $item): array
        {
                $attachments = [];
 
-               $uriids = [$item['uri-id']];
-               $shared = BBCode::fetchShareAttributes($item['body']);
-               if (!empty($shared['guid'])) {
-                       $shared_item = Post::selectFirst(['uri-id'], ['guid' => $shared['guid']]);
-                       if (!empty($shared_item['uri-id'])) {
-                               $uriids[] = $shared_item['uri-id'];
-                       }
-               }
-
                $urls = [];
-               foreach ($uriids as $uriid) {
-                       foreach (Post\Media::getByURIId($uriid, [Post\Media::AUDIO, Post\Media::IMAGE, Post\Media::VIDEO, Post\Media::DOCUMENT, Post\Media::TORRENT]) as $attachment) {
-                               if (in_array($attachment['url'], $urls)) {
-                                       continue;
-                               }
-                               $urls[] = $attachment['url'];
-
-                               $attach = ['type' => 'Document',
-                                       'mediaType' => $attachment['mimetype'],
-                                       'url' => $attachment['url'],
-                                       'name' => $attachment['description']];
+               foreach (Post\Media::getByURIId($item['uri-id'], [Post\Media::AUDIO, Post\Media::IMAGE, Post\Media::VIDEO, Post\Media::DOCUMENT, Post\Media::TORRENT]) as $attachment) {
+                       if (in_array($attachment['url'], $urls)) {
+                               continue;
+                       }
+                       $urls[] = $attachment['url'];
 
-                               if (!empty($attachment['height'])) {
-                                       $attach['height'] = $attachment['height'];
-                               }
+                       $attach = ['type' => 'Document',
+                               'mediaType' => $attachment['mimetype'],
+                               'url' => $attachment['url'],
+                               'name' => $attachment['description']];
 
-                               if (!empty($attachment['width'])) {
-                                       $attach['width'] = $attachment['width'];
-                               }
+                       if (!empty($attachment['height'])) {
+                               $attach['height'] = $attachment['height'];
+                       }
 
-                               if (!empty($attachment['preview'])) {
-                                       $attach['image'] = $attachment['preview'];
-                               }
+                       if (!empty($attachment['width'])) {
+                               $attach['width'] = $attachment['width'];
+                       }
 
-                               $attachments[] = $attach;
+                       if (!empty($attachment['preview'])) {
+                               $attach['image'] = $attachment['preview'];
                        }
+
+                       $attachments[] = $attach;
                }
 
                return $attachments;
@@ -1468,7 +1455,7 @@ class Transmitter
         * @return string Replaced mention
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       private static function mentionAddrCallback($match)
+       private static function mentionAddrCallback(array $match): string
        {
                if (empty($match[1])) {
                        return '';
@@ -1485,11 +1472,10 @@ class Transmitter
        /**
         * Remove image elements since they are added as attachment
         *
-        * @param string $body
-        *
+        * @param string $body HTML code
         * @return string with removed images
         */
-       private static function removePictures($body)
+       private static function removePictures(string $body): string
        {
                // Simplify image codes
                $body = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $body);
@@ -1515,36 +1501,14 @@ class Transmitter
                return $body;
        }
 
-       /**
-        * Fetches the "context" value for a givem item array from the "conversation" table
-        *
-        * @param array $item
-        *
-        * @return string with context url
-        * @throws \Exception
-        */
-       private static function fetchContextURLForItem($item)
-       {
-               $conversation = DBA::selectFirst('conversation', ['conversation-href', 'conversation-uri'], ['item-uri' => $item['parent-uri']]);
-               if (DBA::isResult($conversation) && !empty($conversation['conversation-href'])) {
-                       $context_uri = $conversation['conversation-href'];
-               } elseif (DBA::isResult($conversation) && !empty($conversation['conversation-uri'])) {
-                       $context_uri = $conversation['conversation-uri'];
-               } else {
-                       $context_uri = $item['parent-uri'] . '#context';
-               }
-               return $context_uri;
-       }
-
        /**
         * Returns if the post contains sensitive content ("nsfw")
         *
-        * @param integer $uri_id
-        *
-        * @return boolean
+        * @param integer $uri_id URI id
+        * @return boolean Whether URI id was found
         * @throws \Exception
         */
-       private static function isSensitive($uri_id)
+       private static function isSensitive(int $uri_id): bool
        {
                return DBA::exists('tag-view', ['uri-id' => $uri_id, 'name' => 'nsfw', 'type' => Tag::HASHTAG]);
        }
@@ -1552,12 +1516,11 @@ class Transmitter
        /**
         * Creates event data
         *
-        * @param array $item
-        *
+        * @param array $item Item array
         * @return array with the event data
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       private static function createEvent($item)
+       private static function createEvent(array $item): array
        {
                $event = [];
                $event['name'] = $item['event-summary'];
@@ -1583,12 +1546,11 @@ class Transmitter
         * Creates a note/article object array
         *
         * @param array $item
-        *
         * @return array with the object data
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         * @throws \ImagickException
         */
-       public static function createNote($item)
+       public static function createNote(array $item): array
        {
                if (empty($item)) {
                        return [];
@@ -1597,7 +1559,7 @@ class Transmitter
                // We are treating posts differently when they are directed to a community.
                // This is done to better support Lemmy. Most of the changes should work with other systems as well.
                // But to not risk compatibility issues we currently perform the changes only for communities.
-               if ($item['gravity'] == GRAVITY_PARENT) {
+               if ($item['gravity'] == Item::GRAVITY_PARENT) {
                        $isCommunityPost = !empty(Tag::getByURIId($item['uri-id'], [Tag::EXCLUSIVE_MENTION]));
                        $links = Post\Media::getByURIId($item['uri-id'], [Post\Media::HTML]);
                        if ($isCommunityPost && (count($links) == 1)) {
@@ -1650,7 +1612,10 @@ class Transmitter
                $data['url'] = $link ?? $item['plink'];
                $data['attributedTo'] = $item['author-link'];
                $data['sensitive'] = self::isSensitive($item['uri-id']);
-               $data['context'] = self::fetchContextURLForItem($item);
+
+               if (!empty($item['conversation']) && ($item['conversation'] != './')) {
+                       $data['conversation'] = $data['context'] = $item['conversation'];
+               }
 
                if (!empty($item['title'])) {
                        $data['name'] = BBCode::toPlaintext($item['title'], false);
@@ -1658,6 +1623,8 @@ class Transmitter
 
                $permission_block = self::createPermissionBlockForItem($item, false);
 
+               $real_quote = false;
+
                $body = $item['body'];
 
                if ($type == 'Note') {
@@ -1699,6 +1666,17 @@ class Transmitter
 
                        $body = BBCode::setMentionsToNicknames($body);
 
+                       if (!empty($item['quote-uri-id'])) {
+                               $body = BBCode::removeSharedData($body);
+                               if (Post::exists(['uri-id' => $item['quote-uri-id'], 'network' => [Protocol::ACTIVITYPUB, Protocol::DFRN]])) {
+                                       $real_quote = true;
+                                       $data['quoteUrl'] = $item['quote-uri'];
+                                       $body = DI::contentItem()->addShareLink($body, $item['quote-uri-id']);
+                               } else {
+                                       $body = DI::contentItem()->addSharedPost($item, $body);
+                               }
+                       }
+
                        $data['content'] = BBCode::convertForUriId($item['uri-id'], $body, BBCode::ACTIVITYPUB);
                }
 
@@ -1708,6 +1686,14 @@ class Transmitter
                $language = self::getLanguage($item);
                if (!empty($language)) {
                        $richbody = BBCode::setMentionsToNicknames($item['body'] ?? '');
+                       if (!empty($item['quote-uri-id'])) {
+                               $richbody = BBCode::removeSharedData($richbody);
+                               if ($real_quote) {
+                                       $richbody = DI::contentItem()->addShareLink($richbody, $item['quote-uri-id']);
+                               } else {
+                                       $richbody = DI::contentItem()->addSharedPost($item, $richbody);
+                               }
+                       }
                        $richbody = BBCode::removeAttachment($richbody);
 
                        $data['contentMap'][$language] = BBCode::convertForUriId($item['uri-id'], $richbody, BBCode::EXTERNAL);
@@ -1719,8 +1705,8 @@ class Transmitter
                        $data['diaspora:comment'] = $item['signed_text'];
                }
 
-               $data['attachment'] = self::createAttachmentList($item, $type);
-               $data['tag'] = self::createTagList($item);
+               $data['attachment'] = self::createAttachmentList($item);
+               $data['tag'] = self::createTagList($item, $data['quoteUrl'] ?? '');  
 
                if (empty($data['location']) && (!empty($item['coord']) || !empty($item['location']))) {
                        $data['location'] = self::createLocation($item);
@@ -1739,10 +1725,9 @@ class Transmitter
         * Fetches the language from the post, the user or the system.
         *
         * @param array $item
-        *
         * @return string language string
         */
-       private static function getLanguage(array $item)
+       private static function getLanguage(array $item): string
        {
                // Try to fetch the language from the post itself
                if (!empty($item['language'])) {
@@ -1767,105 +1752,96 @@ class Transmitter
        /**
         * Creates an an "add tag" entry
         *
-        * @param array $item
-        * @param array $data activity data
-        *
+        * @param array $item Item array
+        * @param array $activity activity data
         * @return array with activity data for adding tags
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         * @throws \ImagickException
         */
-       private static function createAddTag($item, $data)
+       private static function createAddTag(array $item, array $activity): array
        {
                $object = XML::parseString($item['object']);
-               $target = XML::parseString($item["target"]);
+               $target = XML::parseString($item['target']);
 
-               $data['diaspora:guid'] = $item['guid'];
-               $data['actor'] = $item['author-link'];
-               $data['target'] = (string)$target->id;
-               $data['summary'] = BBCode::toPlaintext($item['body']);
-               $data['object'] = ['id' => (string)$object->id, 'type' => 'tag', 'name' => (string)$object->title, 'content' => (string)$object->content];
+               $activity['diaspora:guid'] = $item['guid'];
+               $activity['actor'] = $item['author-link'];
+               $activity['target'] = (string)$target->id;
+               $activity['summary'] = BBCode::toPlaintext($item['body']);
+               $activity['object'] = ['id' => (string)$object->id, 'type' => 'tag', 'name' => (string)$object->title, 'content' => (string)$object->content];
 
-               return $data;
+               return $activity;
        }
 
        /**
         * Creates an announce object entry
         *
-        * @param array $item
-        * @param array $data activity data
-        *
+        * @param array $item Item array
+        * @param array $activity activity data
         * @return array with activity data
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         * @throws \ImagickException
         */
-       private static function createAnnounce($item, $data)
+       private static function createAnnounce(array $item, array $activity): array
        {
                $orig_body = $item['body'];
                $announce = self::getAnnounceArray($item);
                if (empty($announce)) {
-                       $data['type'] = 'Create';
-                       $data['object'] = self::createNote($item);
-                       return $data;
+                       $activity['type'] = 'Create';
+                       $activity['object'] = self::createNote($item);
+                       return $activity;
                }
 
                if (empty($announce['comment'])) {
                        // Pure announce, without a quote
-                       $data['type'] = 'Announce';
-                       $data['object'] = $announce['object']['uri'];
-                       return $data;
+                       $activity['type'] = 'Announce';
+                       $activity['object'] = $announce['object']['uri'];
+                       return $activity;
                }
 
                // Quote
-               $data['type'] = 'Create';
+               $activity['type'] = 'Create';
                $item['body'] = $announce['comment'] . "\n" . $announce['object']['plink'];
-               $data['object'] = self::createNote($item);
+               $activity['object'] = self::createNote($item);
 
                /// @todo Finally descide how to implement this in AP. This is a possible way:
-               $data['object']['attachment'][] = self::createNote($announce['object']);
+               $activity['object']['attachment'][] = self::createNote($announce['object']);
 
-               $data['object']['source']['content'] = $orig_body;
-               return $data;
+               $activity['object']['source']['content'] = $orig_body;
+               return $activity;
        }
 
        /**
         * Return announce related data if the item is an annunce
         *
         * @param array $item
-        *
-        * @return array
+        * @return array Announcement array
         */
-       public static function getAnnounceArray($item)
+       private static function getAnnounceArray(array $item): array
        {
-               $reshared = Item::getShareArray($item);
-               if (empty($reshared['guid'])) {
-                       return [];
-               }
-
-               $reshared_item = Post::selectFirst(Item::DELIVER_FIELDLIST, ['guid' => $reshared['guid']]);
-               if (!DBA::isResult($reshared_item)) {
+               $reshared = DI::contentItem()->getSharedPost($item, Item::DELIVER_FIELDLIST);
+               if (empty($reshared)) {
                        return [];
                }
 
-               if (!in_array($reshared_item['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN])) {
+               if (!in_array($reshared['post']['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN])) {
                        return [];
                }
 
-               $profile = APContact::getByURL($reshared_item['author-link'], false);
+               $profile = APContact::getByURL($reshared['post']['author-link'], false);
                if (empty($profile)) {
                        return [];
                }
 
-               return ['object' => $reshared_item, 'actor' => $profile, 'comment' => $reshared['comment']];
+               return ['object' => $reshared['post'], 'actor' => $profile, 'comment' => $reshared['comment']];
        }
 
        /**
         * Checks if the provided item array is an announce
         *
-        * @param array $item
-        *
-        * @return boolean
+        * @param array $item Item array
+        * @return boolean Whether item is an announcement
         */
-       public static function isAnnounce($item)
+       public static function isAnnounce(array $item): bool
        {
                if (!empty($item['verb']) && ($item['verb'] == Activity::ANNOUNCE)) {
                        return true;
@@ -1886,7 +1862,7 @@ class Transmitter
         *
         * @return bool|string activity id
         */
-       public static function activityIDFromContact($cid)
+       public static function activityIDFromContact(int $cid)
        {
                $contact = DBA::selectFirst('contact', ['uid', 'id', 'created'], ['id' => $cid]);
                if (!DBA::isResult($contact)) {
@@ -1904,17 +1880,17 @@ class Transmitter
         * @param integer $uid           User ID
         * @param string  $inbox         Target inbox
         * @param integer $suggestion_id Suggestion ID
-        *
         * @return boolean was the transmission successful?
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public static function sendContactSuggestion($uid, $inbox, $suggestion_id)
+       public static function sendContactSuggestion(int $uid, string $inbox, int $suggestion_id): bool
        {
                $owner = User::getOwnerDataById($uid);
 
                $suggestion = DI::fsuggest()->selectOneById($suggestion_id);
 
-               $data = ['@context' => ActivityPub::CONTEXT,
+               $data = [
+                       '@context' => ActivityPub::CONTEXT,
                        'id' => DI::baseUrl() . '/activity/' . System::createGUID(),
                        'type' => 'Announce',
                        'actor' => $owner['url'],
@@ -1922,7 +1898,8 @@ class Transmitter
                        'content' => $suggestion->note,
                        'instrument' => self::getService(),
                        'to' => [ActivityPub::PUBLIC_COLLECTION],
-                       'cc' => []];
+                       'cc' => []
+               ];
 
                $signed = LDSignature::sign($data, $owner);
 
@@ -1935,15 +1912,15 @@ class Transmitter
         *
         * @param integer $uid   User ID
         * @param string  $inbox Target inbox
-        *
         * @return boolean was the transmission successful?
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public static function sendProfileRelocation($uid, $inbox)
+       public static function sendProfileRelocation(int $uid, string $inbox): bool
        {
                $owner = User::getOwnerDataById($uid);
 
-               $data = ['@context' => ActivityPub::CONTEXT,
+               $data = [
+                       '@context' => ActivityPub::CONTEXT,
                        'id' => DI::baseUrl() . '/activity/' . System::createGUID(),
                        'type' => 'dfrn:relocate',
                        'actor' => $owner['url'],
@@ -1951,7 +1928,8 @@ class Transmitter
                        'published' => DateTimeFormat::utcNow(DateTimeFormat::ATOM),
                        'instrument' => self::getService(),
                        'to' => [ActivityPub::PUBLIC_COLLECTION],
-                       'cc' => []];
+                       'cc' => []
+               ];
 
                $signed = LDSignature::sign($data, $owner);
 
@@ -1964,11 +1942,10 @@ class Transmitter
         *
         * @param integer $uid   User ID
         * @param string  $inbox Target inbox
-        *
         * @return boolean was the transmission successful?
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public static function sendProfileDeletion($uid, $inbox)
+       public static function sendProfileDeletion(int $uid, string $inbox): bool
        {
                $owner = User::getOwnerDataById($uid);
 
@@ -2003,7 +1980,6 @@ class Transmitter
         *
         * @param integer $uid   User ID
         * @param string  $inbox Target inbox
-        *
         * @return boolean was the transmission successful?
         * @throws HTTPException\InternalServerErrorException
         * @throws HTTPException\NotFoundException
@@ -2036,17 +2012,18 @@ class Transmitter
         * @param string  $activity Type name
         * @param string  $target   Target profile
         * @param integer $uid      User ID
+        * @param string  $id Activity-identifier
         * @return bool
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         * @throws \ImagickException
         * @throws \Exception
         */
-       public static function sendActivity($activity, $target, $uid, $id = '')
+       public static function sendActivity(string $activity, string $target, int $uid, string $id = ''): bool
        {
                $profile = APContact::getByURL($target);
                if (empty($profile['inbox'])) {
                        Logger::warning('No inbox found for target', ['target' => $target, 'profile' => $profile]);
-                       return;
+                       return false;
                }
 
                $owner = User::getOwnerDataById($uid);
@@ -2055,13 +2032,15 @@ class Transmitter
                        $id = DI::baseUrl() . '/activity/' . System::createGUID();
                }
 
-               $data = ['@context' => ActivityPub::CONTEXT,
+               $data = [
+                       '@context' => ActivityPub::CONTEXT,
                        'id' => $id,
                        'type' => $activity,
                        'actor' => $owner['url'],
                        'object' => $profile['url'],
                        'instrument' => self::getService(),
-                       'to' => [$profile['url']]];
+                       'to' => [$profile['url']],
+               ];
 
                Logger::info('Sending activity ' . $activity . ' to ' . $target . ' for user ' . $uid);
 
@@ -2081,12 +2060,12 @@ class Transmitter
         * @throws \ImagickException
         * @throws \Exception
         */
-       public static function sendFollowObject($object, $target, $uid = 0)
+       public static function sendFollowObject(string $object, string $target, int $uid = 0): bool
        {
                $profile = APContact::getByURL($target);
                if (empty($profile['inbox'])) {
                        Logger::warning('No inbox found for target', ['target' => $target, 'profile' => $profile]);
-                       return;
+                       return false;
                }
 
                if (empty($uid)) {
@@ -2108,13 +2087,15 @@ class Transmitter
 
                $owner = User::getOwnerDataById($uid);
 
-               $data = ['@context' => ActivityPub::CONTEXT,
+               $data = [
+                       '@context' => ActivityPub::CONTEXT,
                        'id' => DI::baseUrl() . '/activity/' . System::createGUID(),
                        'type' => 'Follow',
                        'actor' => $owner['url'],
                        'object' => $object,
                        'instrument' => self::getService(),
-                       'to' => [$profile['url']]];
+                       'to' => [$profile['url']],
+               ];
 
                Logger::info('Sending follow ' . $object . ' to ' . $target . ' for user ' . $uid);
 
@@ -2126,12 +2107,13 @@ class Transmitter
         * Transmit a message that the contact request had been accepted
         *
         * @param string  $target Target profile
-        * @param         $id
+        * @param string  $id Object id
         * @param integer $uid    User ID
+        * @return void
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         * @throws \ImagickException
         */
-       public static function sendContactAccept($target, $id, $uid)
+       public static function sendContactAccept(string $target, string $id, int $uid)
        {
                $profile = APContact::getByURL($target);
                if (empty($profile['inbox'])) {
@@ -2140,18 +2122,20 @@ class Transmitter
                }
 
                $owner = User::getOwnerDataById($uid);
-               $data = ['@context' => ActivityPub::CONTEXT,
+               $data = [
+                       '@context' => ActivityPub::CONTEXT,
                        'id' => DI::baseUrl() . '/activity/' . System::createGUID(),
                        'type' => 'Accept',
                        'actor' => $owner['url'],
                        'object' => [
-                               'id' => (string)$id,
+                               'id' => $id,
                                'type' => 'Follow',
                                'actor' => $profile['url'],
                                'object' => $owner['url']
                        ],
                        'instrument' => self::getService(),
-                       'to' => [$profile['url']]];
+                       'to' => [$profile['url']],
+               ];
 
                Logger::debug('Sending accept to ' . $target . ' for user ' . $uid . ' with id ' . $id);
 
@@ -2162,14 +2146,14 @@ class Transmitter
        /**
         * Reject a contact request or terminates the contact relation
         *
-        * @param string  $target Target profile
-        * @param         $id
-        * @param integer $uid    User ID
+        * @param string $target   Target profile
+        * @param string $objectId Object id
+        * @param int    $uid      User ID
         * @return bool Operation success
         * @throws HTTPException\InternalServerErrorException
         * @throws \ImagickException
         */
-       public static function sendContactReject($target, $id, $uid): bool
+       public static function sendContactReject(string $target, string $objectId, int $uid): bool
        {
                $profile = APContact::getByURL($target);
                if (empty($profile['inbox'])) {
@@ -2178,20 +2162,22 @@ class Transmitter
                }
 
                $owner = User::getOwnerDataById($uid);
-               $data = ['@context' => ActivityPub::CONTEXT,
+               $data = [
+                       '@context' => ActivityPub::CONTEXT,
                        'id' => DI::baseUrl() . '/activity/' . System::createGUID(),
                        'type' => 'Reject',
-                       'actor' => $owner['url'],
+                       'actor'  => $owner['url'],
                        'object' => [
-                               'id' => (string)$id,
+                               'id' => $objectId,
                                'type' => 'Follow',
                                'actor' => $profile['url'],
                                'object' => $owner['url']
                        ],
                        'instrument' => self::getService(),
-                       'to' => [$profile['url']]];
+                       'to' => [$profile['url']],
+               ];
 
-               Logger::debug('Sending reject to ' . $target . ' for user ' . $uid . ' with id ' . $id);
+               Logger::debug('Sending reject to ' . $target . ' for user ' . $uid . ' with id ' . $objectId);
 
                $signed = LDSignature::sign($data, $owner);
                return HTTPSignature::transmit($signed, $profile['inbox'], $uid);
@@ -2201,13 +2187,14 @@ class Transmitter
         * Transmits a message that we don't want to follow this contact anymore
         *
         * @param string  $target Target profile
+        * @param integer $cid    Contact id
         * @param integer $uid    User ID
+        * @return bool success
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         * @throws \ImagickException
         * @throws \Exception
-        * @return bool success
         */
-       public static function sendContactUndo($target, $cid, $uid)
+       public static function sendContactUndo(string $target, int $cid, int $uid): bool
        {
                $profile = APContact::getByURL($target);
                if (empty($profile['inbox'])) {
@@ -2220,26 +2207,39 @@ class Transmitter
                        return false;
                }
 
-               $id = DI::baseUrl() . '/activity/' . System::createGUID();
+               $objectId = DI::baseUrl() . '/activity/' . System::createGUID();
 
                $owner = User::getOwnerDataById($uid);
-               $data = ['@context' => ActivityPub::CONTEXT,
-                       'id' => $id,
+               $data = [
+                       '@context' => ActivityPub::CONTEXT,
+                       'id' => $objectId,
                        'type' => 'Undo',
                        'actor' => $owner['url'],
-                       'object' => ['id' => $object_id, 'type' => 'Follow',
+                       'object' => [
+                               'id' => $object_id,
+                               'type' => 'Follow',
                                'actor' => $owner['url'],
-                               'object' => $profile['url']],
+                               'object' => $profile['url']
+                       ],
                        'instrument' => self::getService(),
-                       'to' => [$profile['url']]];
+                       'to' => [$profile['url']],
+               ];
 
-               Logger::info('Sending undo to ' . $target . ' for user ' . $uid . ' with id ' . $id);
+               Logger::info('Sending undo to ' . $target . ' for user ' . $uid . ' with id ' . $objectId);
 
                $signed = LDSignature::sign($data, $owner);
                return HTTPSignature::transmit($signed, $profile['inbox'], $uid);
        }
 
-       private static function prependMentions($body, int $uriid, string $authorLink)
+       /**
+        * Prepends mentions (@) to $body variable
+        *
+        * @param string $body HTML code
+        * @param int    $uriId
+        * @param string $authorLink Author link
+        * @return string HTML code with prepended mentions
+        */
+       private static function prependMentions(string $body, int $uriid, string $authorLink): string
        {
                $mentions = [];