1
1
Fork 0

Merge pull request #11956 from annando/issue-11952

Issue 11952: Avoid to send AP related comments to Diaspora
This commit is contained in:
Hypolite Petovan 2022-10-03 09:20:37 -04:00 committed by GitHub
commit 3895da3618
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 0 deletions

View file

@ -4133,6 +4133,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,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'];

View file

@ -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]);
}