]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/Diaspora.php
Delay unprepared posts
[friendica.git] / src / Protocol / Diaspora.php
index 2b4db128fdc85c7b18d07b00ee6af6105e590383..5f28e092d5798ab751c701a1c412eeca50ae5cfa 100644 (file)
@@ -1507,9 +1507,9 @@ class Diaspora
 
                if (isset($data->thread_parent_guid)) {
                        $thread_parent_guid = Strings::escapeTags(XML::unescape($data->thread_parent_guid));
-                       $thr_uri = self::getUriFromGuid("", $thread_parent_guid, true);
+                       $thr_parent = self::getUriFromGuid("", $thread_parent_guid, true);
                } else {
-                       $thr_uri = "";
+                       $thr_parent = "";
                }
 
                $contact = self::allowedContactByHandle($importer, $sender, true);
@@ -1522,8 +1522,8 @@ class Diaspora
                        return true;
                }
 
-               $parent_item = self::parentItem($importer["uid"], $parent_guid, $author, $contact);
-               if (!$parent_item) {
+               $toplevel_parent_item = self::parentItem($importer["uid"], $parent_guid, $author, $contact);
+               if (!$toplevel_parent_item) {
                        return false;
                }
 
@@ -1564,11 +1564,7 @@ class Diaspora
                $datarray["verb"] = Activity::POST;
                $datarray["gravity"] = GRAVITY_COMMENT;
 
-               if ($thr_uri != "") {
-                       $datarray["parent-uri"] = $thr_uri;
-               } else {
-                       $datarray["parent-uri"] = $parent_item["uri"];
-               }
+               $datarray['thr-parent'] = $thr_parent ?: $toplevel_parent_item['uri'];
 
                $datarray["object-type"] = Activity\ObjectType::COMMENT;
 
@@ -1577,7 +1573,7 @@ class Diaspora
 
                $datarray["changed"] = $datarray["created"] = $datarray["edited"] = $created_at;
 
-               $datarray["plink"] = self::plink($author, $guid, $parent_item['guid']);
+               $datarray["plink"] = self::plink($author, $guid, $toplevel_parent_item['guid']);
                $body = Markdown::toBBCode($text);
 
                $datarray["body"] = self::replacePeopleGuid($body, $person["url"]);
@@ -1589,7 +1585,7 @@ class Diaspora
 
                // If we are the origin of the parent we store the original data.
                // We notify our followers during the item storage.
-               if ($parent_item["origin"]) {
+               if ($toplevel_parent_item["origin"]) {
                        $datarray['diaspora_signed_text'] = json_encode($data);
                }
 
@@ -1763,8 +1759,8 @@ class Diaspora
                        return true;
                }
 
-               $parent_item = self::parentItem($importer["uid"], $parent_guid, $author, $contact);
-               if (!$parent_item) {
+               $toplevel_parent_item = self::parentItem($importer["uid"], $parent_guid, $author, $contact);
+               if (!$toplevel_parent_item) {
                        return false;
                }
 
@@ -1801,7 +1797,7 @@ class Diaspora
 
                $datarray["verb"] = $verb;
                $datarray["gravity"] = GRAVITY_ACTIVITY;
-               $datarray["parent-uri"] = $parent_item["uri"];
+               $datarray['thr-parent'] = $toplevel_parent_item['uri'];
 
                $datarray["object-type"] = Activity\ObjectType::NOTE;
 
@@ -1811,11 +1807,11 @@ class Diaspora
                $datarray["changed"] = $datarray["created"] = $datarray["edited"] = DateTimeFormat::utcNow();
 
                // like on comments have the comment as parent. So we need to fetch the toplevel parent
-               if ($parent_item['gravity'] != GRAVITY_PARENT) {
-                       $toplevel = Item::selectFirst(['origin'], ['id' => $parent_item['parent']]);
+               if ($toplevel_parent_item['gravity'] != GRAVITY_PARENT) {
+                       $toplevel = Item::selectFirst(['origin'], ['id' => $toplevel_parent_item['parent']]);
                        $origin = $toplevel["origin"];
                } else {
-                       $origin = $parent_item["origin"];
+                       $origin = $toplevel_parent_item["origin"];
                }
 
                // If we are the origin of the parent we store the original data.
@@ -1926,16 +1922,16 @@ class Diaspora
                        return true;
                }
 
-               $parent_item = self::parentItem($importer["uid"], $parent_guid, $author, $contact);
-               if (!$parent_item) {
+               $toplevel_parent_item = self::parentItem($importer["uid"], $parent_guid, $author, $contact);
+               if (!$toplevel_parent_item) {
                        return false;
                }
 
-               if (!$parent_item['origin']) {
+               if (!$toplevel_parent_item['origin']) {
                        Logger::info('Not our origin. Participation is ignored', ['parent_guid' => $parent_guid, 'guid' => $guid, 'author' => $author]);
                }
 
-               if (!in_array($parent_item['private'], [Item::PUBLIC, Item::UNLISTED])) {
+               if (!in_array($toplevel_parent_item['private'], [Item::PUBLIC, Item::UNLISTED])) {
                        Logger::info('Item is not public, participation is ignored', ['parent_guid' => $parent_guid, 'guid' => $guid, 'author' => $author]);
                        return false;
                }
@@ -1965,7 +1961,7 @@ class Diaspora
 
                $datarray["verb"] = Activity::FOLLOW;
                $datarray["gravity"] = GRAVITY_ACTIVITY;
-               $datarray["parent-uri"] = $parent_item["uri"];
+               $datarray['thr-parent'] = $toplevel_parent_item['uri'];
 
                $datarray["object-type"] = Activity\ObjectType::NOTE;
 
@@ -1980,7 +1976,7 @@ class Diaspora
 
                // Send all existing comments and likes to the requesting server
                $comments = Item::select(['id', 'uri-id', 'parent-author-network', 'author-network', 'verb'],
-                       ['parent' => $parent_item['id'], 'gravity' => [GRAVITY_COMMENT, GRAVITY_ACTIVITY]]);
+                       ['parent' => $toplevel_parent_item['id'], 'gravity' => [GRAVITY_COMMENT, GRAVITY_ACTIVITY]]);
                while ($comment = Item::fetch($comments)) {
                        if (in_array($comment['verb'], [Activity::FOLLOW, Activity::TAG])) {
                                Logger::info('participation messages are not relayed', ['item' => $comment['id']]);
@@ -2357,7 +2353,7 @@ class Diaspora
 
                $datarray['guid'] = $parent['guid'] . '-' . $guid;
                $datarray['uri'] = self::getUriFromGuid($author, $datarray['guid']);
-               $datarray['parent-uri'] = $parent['uri'];
+               $datarray['thr-parent'] = $parent['uri'];
 
                $datarray['verb'] = $datarray['body'] = Activity::ANNOUNCE;
                $datarray['gravity'] = GRAVITY_ACTIVITY;
@@ -2428,7 +2424,7 @@ class Diaspora
                $datarray["owner-id"] = $datarray["author-id"];
 
                $datarray["guid"] = $guid;
-               $datarray["uri"] = $datarray["parent-uri"] = self::getUriFromGuid($author, $guid);
+               $datarray["uri"] = $datarray["thr-parent"] = self::getUriFromGuid($author, $guid);
                $datarray['uri-id'] = ItemURI::insert(['uri' => $datarray['uri'], 'guid' => $datarray['guid']]);
 
                $datarray["verb"] = Activity::POST;
@@ -2513,7 +2509,7 @@ class Diaspora
                }
 
                // Fetch items that are about to be deleted
-               $fields = ['uid', 'id', 'parent', 'parent-uri', 'author-link', 'file'];
+               $fields = ['uid', 'id', 'parent', 'author-link', 'file'];
 
                // When we receive a public retraction, we delete every item that we find.
                if ($importer['uid'] == 0) {
@@ -2682,7 +2678,7 @@ class Diaspora
                $datarray = [];
 
                $datarray["guid"] = $guid;
-               $datarray["uri"] = $datarray["parent-uri"] = self::getUriFromGuid($author, $guid);
+               $datarray["uri"] = $datarray["thr-parent"] = self::getUriFromGuid($author, $guid);
                $datarray['uri-id'] = ItemURI::insert(['uri' => $datarray['uri'], 'guid' => $datarray['guid']]);
 
                // Attach embedded pictures to the body
@@ -3035,7 +3031,18 @@ class Diaspora
                        $owner['uprvkey'] = $owner['prvkey'];
                }
 
-               $envelope = self::buildMessage($msg, $owner, $contact, $owner['uprvkey'], $contact['pubkey'], $public_batch);
+               // When sending content to Friendica contacts using the Diaspora protocol
+               // we have to fetch the public key from the fcontact.
+               // This is due to the fact that legacy DFRN had unique keys for every contact.
+               $pubkey = $contact['pubkey'];
+               if (!empty($contact['addr'])) {
+                       $fcontact = FContact::getByURL($contact['addr']);
+                       if (!empty($fcontact)) {
+                               $pubkey = $fcontact['pubkey'];
+                       }
+               }
+
+               $envelope = self::buildMessage($msg, $owner, $contact, $owner['uprvkey'], $pubkey, $public_batch);
 
                $return_code = self::transmit($owner, $contact, $envelope, $public_batch, $guid);
 
@@ -3375,7 +3382,6 @@ class Diaspora
                        }
 
                        if ($item['author-link'] != $item['owner-link']) {
-                               require_once 'mod/share.php';
                                $body = BBCode::getShareOpeningTag($item['author-name'], $item['author-link'], $item['author-avatar'],
                                        $item['plink'], $item['created']) . $body . '[/share]';
                        }
@@ -3491,12 +3497,12 @@ class Diaspora
         */
        private static function constructLike(array $item, array $owner)
        {
-               $parent = Item::selectFirst(['guid', 'uri', 'parent-uri'], ['uri' => $item["thr-parent"]]);
+               $parent = Item::selectFirst(['guid', 'uri', 'thr-parent'], ['uri' => $item["thr-parent"]]);
                if (!DBA::isResult($parent)) {
                        return false;
                }
 
-               $target_type = ($parent["uri"] === $parent["parent-uri"] ? "Post" : "Comment");
+               $target_type = ($parent["uri"] === $parent["thr-parent"] ? "Post" : "Comment");
                $positive = null;
                if ($item['verb'] === Activity::LIKE) {
                        $positive = "true";
@@ -3523,7 +3529,7 @@ class Diaspora
         */
        private static function constructAttend(array $item, array $owner)
        {
-               $parent = Item::selectFirst(['guid', 'uri', 'parent-uri'], ['uri' => $item["thr-parent"]]);
+               $parent = Item::selectFirst(['guid'], ['uri' => $item['thr-parent']]);
                if (!DBA::isResult($parent)) {
                        return false;
                }
@@ -4052,10 +4058,7 @@ class Diaspora
                        return false;
                }
 
-               // This is a workaround for the behaviour of the "insert" function, see mod/item.php
-               $item['thr-parent'] = $item['parent-uri'];
-
-               $parent = Item::selectFirst(['parent-uri'], ['uri' => $item['parent-uri']]);
+               $parent = Item::selectFirst(['parent-uri'], ['uri' => $item['thr-parent']]);
                if (!DBA::isResult($parent)) {
                        return;
                }