]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/ActivityPub/Transmitter.php
Merge pull request #7570 from nupplaphil/bug/friendica-7298
[friendica.git] / src / Protocol / ActivityPub / Transmitter.php
index 81b8bc1de310a98d6020adc559de339423868926..e44ae1cf66c2dfa4ff9413cc2b457d10fbb39279 100644 (file)
@@ -229,11 +229,6 @@ class Transmitter
                        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'];
@@ -254,7 +249,7 @@ class Transmitter
                        'publicKeyPem' => $user['pubkey']];
                $data['endpoints'] = ['sharedInbox' => System::baseUrl() . '/inbox'];
                $data['icon'] = ['type' => 'Image',
-                       'url' => $contact['avatar']];
+                       'url' => $contact['photo']];
 
                $data['generator'] = self::getService();
 
@@ -363,7 +358,7 @@ class Transmitter
 
                if (Config::get('debug', 'total_ap_delivery')) {
                        // Will be activated in a later step
-                       $networks = [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS];
+                       $networks = Protocol::FEDERATED;
                } else {
                        // For now only send to these contacts:
                        $networks = [Protocol::ACTIVITYPUB, Protocol::OSTATUS];
@@ -391,7 +386,7 @@ class Transmitter
                                }
                        }
                } else {
-                       $receiver_list = Item::enumeratePermissions($item);
+                       $receiver_list = Item::enumeratePermissions($item, true);
 
                        foreach ($terms as $term) {
                                $cid = Contact::getIdForURL($term['url'], $item['uid']);
@@ -535,7 +530,7 @@ class Transmitter
 
                if (Config::get('debug', 'total_ap_delivery')) {
                        // Will be activated in a later step
-                       $networks = [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS];
+                       $networks = Protocol::FEDERATED;
                } else {
                        // For now only send to these contacts:
                        $networks = [Protocol::ACTIVITYPUB, Protocol::OSTATUS];
@@ -1039,7 +1034,7 @@ class Transmitter
                // Simplify image codes
                $body = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $item['body']);
 
-               // Grab all pictures and create attachments out of them
+               // Grab all pictures without alternative descriptions and create attachments out of them
                if (preg_match_all("/\[img\]([^\[\]]*)\[\/img\]/Usi", $body, $pictures)) {
                        foreach ($pictures[1] as $picture) {
                                $imgdata = Image::getInfoFromURL($picture);
@@ -1052,6 +1047,19 @@ class Transmitter
                        }
                }
 
+               // Grab all pictures with alternative description and create attachments out of them
+               if (preg_match_all("/\[img=([^\[\]]*)\]([^\[\]]*)\[\/img\]/Usi", $body, $pictures, PREG_SET_ORDER)) {
+                       foreach ($pictures as $picture) {
+                               $imgdata = Image::getInfoFromURL($picture[1]);
+                               if ($imgdata) {
+                                       $attachments[] = ['type' => 'Document',
+                                               'mediaType' => $imgdata['mime'],
+                                               'url' => $picture[1],
+                                               'name' => $picture[2]];
+                               }
+                       }
+               }
+
                return $attachments;
        }
 
@@ -1292,6 +1300,7 @@ class Transmitter
         */
        private static function createAnnounce($item, $data)
        {
+               $orig_body = $item['body'];
                $announce = api_share_as_retweet($item);
                if (empty($announce['plink'])) {
                        $data['type'] = 'Create';
@@ -1304,12 +1313,29 @@ class Transmitter
                if (!empty($activity)) {
                        $ldactivity = JsonLD::compact($activity);
                        $id = JsonLD::fetchElement($ldactivity, '@id');
+                       $type = str_replace('as:', '', JsonLD::fetchElement($ldactivity, '@type'));
                        if (!empty($id)) {
-                               $data['object'] = $id;
+                               if (empty($announce['share-pre-body'])) {
+                                       // Pure announce, without a quote
+                                       $data['type'] = 'Announce';
+                                       $data['object'] = $id;
+                                       return $data;
+                               }
+
+                               // Quote
+                               $data['type'] = 'Create';
+                               $item['body'] = trim($announce['share-pre-body']) . "\n" . $id;
+                               $data['object'] = self::createNote($item);
+
+                               /// @todo Finally descide how to implement this in AP. This is a possible way:
+                               $data['object']['attachment'][] = ['type' => $type, 'id' => $id];
+
+                               $data['object']['source']['content'] = $orig_body;
                                return $data;
                        }
                }
 
+               $item['body'] = $orig_body;
                $data['type'] = 'Create';
                $data['object'] = self::createNote($item);
                return $data;
@@ -1479,6 +1505,10 @@ class Transmitter
        public static function sendActivity($activity, $target, $uid, $id = '')
        {
                $profile = APContact::getByURL($target);
+               if (empty($profile['inbox'])) {
+                       Logger::warning('No inbox found for target', ['target' => $target, 'profile' => $profile]);
+                       return;
+               }
 
                $owner = User::getOwnerDataById($uid);
 
@@ -1515,6 +1545,10 @@ class Transmitter
        public static function sendFollowObject($object, $target, $uid = 0)
        {
                $profile = APContact::getByURL($target);
+               if (empty($profile['inbox'])) {
+                       Logger::warning('No inbox found for target', ['target' => $target, 'profile' => $profile]);
+                       return;
+               }
 
                if (empty($uid)) {
                        // Fetch the list of administrators
@@ -1561,6 +1595,10 @@ class Transmitter
        public static function sendContactAccept($target, $id, $uid)
        {
                $profile = APContact::getByURL($target);
+               if (empty($profile['inbox'])) {
+                       Logger::warning('No inbox found for target', ['target' => $target, 'profile' => $profile]);
+                       return;
+               }
 
                $owner = User::getOwnerDataById($uid);
                $data = ['@context' => ActivityPub::CONTEXT,
@@ -1594,6 +1632,10 @@ class Transmitter
        public static function sendContactReject($target, $id, $uid)
        {
                $profile = APContact::getByURL($target);
+               if (empty($profile['inbox'])) {
+                       Logger::warning('No inbox found for target', ['target' => $target, 'profile' => $profile]);
+                       return;
+               }
 
                $owner = User::getOwnerDataById($uid);
                $data = ['@context' => ActivityPub::CONTEXT,
@@ -1627,6 +1669,10 @@ class Transmitter
        public static function sendContactUndo($target, $cid, $uid)
        {
                $profile = APContact::getByURL($target);
+               if (empty($profile['inbox'])) {
+                       Logger::warning('No inbox found for target', ['target' => $target, 'profile' => $profile]);
+                       return;
+               }
 
                $object_id = self::activityIDFromContact($cid);
                if (empty($object_id)) {