]> git.mxchange.org Git - friendica.git/commitdiff
Recursively check if the thread supports Diaspora
authorMichael <heluecht@pirati.ca>
Mon, 3 Oct 2022 11:04:57 +0000 (11:04 +0000)
committerMichael <heluecht@pirati.ca>
Mon, 3 Oct 2022 11:04:57 +0000 (11:04 +0000)
src/Protocol/Diaspora.php

index 1bfe1ca652c8c9e6b654a1b8336eb7ff75ff4878..4a1779d8195d15a9938e870558c9c18e24c2dace 100644 (file)
@@ -4133,14 +4133,8 @@ class Diaspora
                        return false;
                }
 
-               $parent_post = Post::selectFirstPost(['gravity', 'signed_text', 'author-link'], ['uri-id' => $item['thr-parent-id']]);
-               if (empty(FContact::getByURL($parent_post['author-link'], false))) {
-                       Logger::info('Parent author is no Diaspora contact. A signature will not be created.', ['uri-id' => $item['uri-id'], 'guid' => $item['guid']]);
-                       return false;
-               }
-
-               if (($parent_post['gravity'] == GRAVITY_COMMENT) && empty($parent_post['signed_text'])) {
-                       Logger::info('Parent comment has got no Diaspora signature. A signature will not be created.', ['uri-id' => $item['uri-id'], 'guid' => $item['guid']]);
+               if (!self::parentSupportDiaspora($item['thr-parent-id'])) {
+                       Logger::info('One of the parents does not support. A signature will not be created.', ['uri-id' => $item['uri-id'], 'guid' => $item['guid']]);
                        return false;
                }
 
@@ -4154,6 +4148,37 @@ 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'];