]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/Diaspora.php
Improve quote share ("message_id" added)
[friendica.git] / src / Protocol / Diaspora.php
index 9e80c130282428401353223353ec1cac6fd4c6d9..bcf049945ff544ce6c3530e82d1121bf1636b402 100644 (file)
@@ -2483,7 +2483,8 @@ class Diaspora
                        $original_item['author-avatar'],
                        $original_item['plink'],
                        $original_item['created'],
-                       $original_item['guid']
+                       $original_item['guid'],
+                       $original_item['uri'],
                );
 
                if (!empty($original_item['title'])) {
@@ -4133,6 +4134,11 @@ class Diaspora
                        return false;
                }
 
+               if (!self::parentSupportDiaspora($item['thr-parent-id'])) {
+                       Logger::info('One of the parents does not support Diaspora. A signature will not be created.', ['uri-id' => $item['uri-id'], 'guid' => $item['guid']]);
+                       return false;
+               }
+
                $message = self::constructComment($item, $owner);
                if ($message === false) {
                        return false;
@@ -4143,9 +4149,40 @@ class Diaspora
                return $message;
        }
 
+       /**
+        * Check if the parent and their parents support Diaspora
+        *
+        * @param integer $parent_id
+        * @return boolean
+        */
+       private static function parentSupportDiaspora(int $parent_id): bool
+       {
+               $parent_post = Post::selectFirstPost(['gravity', 'signed_text', 'author-link', 'thr-parent-id'], ['uri-id' => $parent_id]);
+               if (empty($parent_post['thr-parent-id'])) {
+                       Logger::warning('Parent post does not exist.', ['parent-id' => $parent_id]);
+                       return false;
+               }
+
+               if (empty(FContact::getByURL($parent_post['author-link'], false))) {
+                       Logger::info('Parent author is no Diaspora contact.', ['parent-id' => $parent_id]);
+                       return false;
+               }
+
+               if (($parent_post['gravity'] == GRAVITY_COMMENT) && empty($parent_post['signed_text'])) {
+                       Logger::info('Parent comment has got no Diaspora signature.', ['parent-id' => $parent_id]);
+                       return false;
+               }
+
+               if ($parent_post['gravity'] == GRAVITY_COMMENT) {
+                       return self::parentSupportDiaspora($parent_post['thr-parent-id']);
+               }
+
+               return true;
+       }
+
        public static function performReshare(int $UriId, int $uid): int
        {
-               $fields = ['uri-id', 'body', 'title', 'author-name', 'author-link', 'author-avatar', 'guid', 'created', 'plink'];
+               $fields = ['uri-id', 'body', 'title', 'author-name', 'author-link', 'author-avatar', 'guid', 'created', 'plink', 'uri'];
                $item = Post::selectFirst($fields, ['uri-id' => $UriId, 'uid' => [$uid, 0], 'private' => [Item::PUBLIC, Item::UNLISTED]]);
                if (!DBA::isResult($item)) {
                        return 0;
@@ -4155,7 +4192,7 @@ class Diaspora
                        $pos = strpos($item['body'], '[share');
                        $post = substr($item['body'], $pos);
                } else {
-                       $post = BBCode::getShareOpeningTag($item['author-name'], $item['author-link'], $item['author-avatar'], $item['plink'], $item['created'], $item['guid']);
+                       $post = BBCode::getShareOpeningTag($item['author-name'], $item['author-link'], $item['author-avatar'], $item['plink'], $item['created'], $item['guid'], $item['uri']);
 
                        if (!empty($item['title'])) {
                                $post .= '[h3]' . $item['title'] . "[/h3]\n";