]> git.mxchange.org Git - friendica.git/commitdiff
Preparation for quoted reshares on AP
authorMichael <heluecht@pirati.ca>
Sat, 20 Jul 2019 21:32:19 +0000 (21:32 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 20 Jul 2019 21:32:19 +0000 (21:32 +0000)
include/api.php
src/Protocol/ActivityPub/Transmitter.php

index 59a95659fbd921e19ce1f2de9360e8b18e8dc5e3..51ca1e4e17b794c7ba687e03b1c04891dc60c68a 100644 (file)
@@ -5162,17 +5162,22 @@ function api_share_as_retweet(&$item)
                $posted = $matches[1];
        }
 
-       $pre_body = trim(preg_replace("/(.*?)\[share.*?\]\s?.*?\s?\[\/share\]\s?/ism", "$1", $body));
+       if (!preg_match("/(.*?)\[share.*?\]\s?(.*?)\s?\[\/share\]\s?(.*?)/ism", $body, $matches)) {
+               return false;
+       }
+
+       $pre_body = trim($matches[1]);
        if ($pre_body != '') {
                $item['body'] = $pre_body;
        }
 
-       $shared_body = trim(preg_replace("/(.*?)\[share.*?\]\s?(.*?)\s?\[\/share\]\s?/ism", "$2", $body));
+       $shared_body = trim($matches[2]);
 
        if (($shared_body == "") || ($profile == "") || ($author == "") || ($avatar == "") || ($posted == "")) {
                return false;
        }
 
+       $reshared_item["share-pre-body"] = $pre_body;
        $reshared_item["body"] = $shared_body;
        $reshared_item["author-id"] = Contact::getIdForURL($profile, 0, true);
        $reshared_item["author-name"] = $author;
index 1d5192d93be6bb2286738b6ae6ead3a3d202d01c..9f5d17c90ef434f6636dcab522690390eb1e99b2 100644 (file)
@@ -1287,6 +1287,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';
@@ -1299,12 +1300,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;