From 7395ae22f7775f8be104d7ce5f19da6ea72d8347 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 3 Oct 2022 10:40:16 +0000 Subject: [PATCH 1/3] Issue 11952: Avoid to send AP related comments to Diaspora --- src/Protocol/Diaspora.php | 11 +++++++++++ src/Worker/Notifier.php | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index 9e80c1302..1bfe1ca65 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -4133,6 +4133,17 @@ 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']]); + return false; + } + $message = self::constructComment($item, $owner); if ($message === false) { return false; diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php index 3b4e1478c..7d3d3d6b7 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -191,6 +191,10 @@ class Notifier // when the original comment author does support the Diaspora protocol. if ($thr_parent['author-link'] && $target_item['parent-uri'] != $target_item['thr-parent']) { $diaspora_delivery = Diaspora::isSupportedByContactUrl($thr_parent['author-link']); + if ($diaspora_delivery && empty($target_item['signed_text'])) { + Logger::debug('Post has got no Diaspora signature, so there will be no Diaspora delivery', ['guid' => $target_item['guid'], 'uri-id' => $target_item['uri-id']]); + $diaspora_delivery = false; + } Logger::info('Threaded comment', ['diaspora_delivery' => (int)$diaspora_delivery]); } From 5127784acb1cd9f57a0c8ff132a2dc3cc59e4f5e Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 3 Oct 2022 11:04:57 +0000 Subject: [PATCH 2/3] Recursively check if the thread supports Diaspora --- src/Protocol/Diaspora.php | 41 +++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index 1bfe1ca65..4a1779d81 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -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']; From 8347f0144b91816ca9fcfb273b1789dae4fd0687 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 3 Oct 2022 11:42:50 +0000 Subject: [PATCH 3/3] Fix log message --- src/Protocol/Diaspora.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index 4a1779d81..781ae57a3 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -4134,7 +4134,7 @@ class Diaspora } 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']]); + 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; }