Issue 11309: Check if a post is wanted

This commit is contained in:
Michael 2022-03-11 14:00:05 +00:00
parent e3025c2c15
commit f264923cad
3 changed files with 56 additions and 6 deletions

View file

@ -572,6 +572,53 @@ class Processor
return $host_hash . '-'. hash('fnv164', $path) . '-'. hash('joaat', $path); return $host_hash . '-'. hash('fnv164', $path) . '-'. hash('joaat', $path);
} }
/**
* Checks if an incoming message is wanted
*
* @param array $activity
* @param array $item
* @return boolean Is the message wanted?
*/
private static function isSolicitedMessage(array $activity, array $item)
{
// The checks are split to improve the support when searching why a message was accepted.
if (count($activity['receiver']) != 1) {
// The message has more than one receiver, so it is wanted.
Logger::debug('Message has got several receivers - accepted', ['uri-id' => $item['uri-id'], 'guid' => $item['guid'], 'url' => $item['uri']]);
return true;
}
if ($item['private'] == Item::PRIVATE) {
// We only look at public posts here. Private posts are expected to be intentionally posted to the single receiver.
Logger::debug('Message is private - accepted', ['uri-id' => $item['uri-id'], 'guid' => $item['guid'], 'url' => $item['uri']]);
return true;
}
if (!empty($activity['from-relay'])) {
// We check relay posts at another place. When it arrived here, the message is already checked.
Logger::debug('Message is a relay post that is already checked - accepted', ['uri-id' => $item['uri-id'], 'guid' => $item['guid'], 'url' => $item['uri']]);
return true;
}
if (!empty($activity['thread-completion'])) {
// The thread completion mode means that the post is fetched intentionally.
// This can have several causes, in doubt we keep the message.
// This can possibly be improved in the future.
Logger::debug('Message is in completion mode - accepted', ['uri-id' => $item['uri-id'], 'guid' => $item['guid'], 'url' => $item['uri']]);
return true;
}
if ($item['gravity'] != GRAVITY_PARENT) {
// We cannot reliably check at this point if a comment or activity belongs to an accepted post or needs to be fetched
// This can possibly be improved in the future.
Logger::debug('Message is no parent - accepted', ['uri-id' => $item['uri-id'], 'guid' => $item['guid'], 'url' => $item['uri']]);
return true;
}
$tags = array_column(Tag::getByURIId($item['uri-id'], [Tag::HASHTAG]), 'name');
return Relay::isSolicitedPost($tags, $item['body'], $item['author-id'], $item['uri'], Protocol::ACTIVITYPUB);
}
/** /**
* Creates an item post * Creates an item post
* *
@ -589,6 +636,11 @@ class Processor
$stored = false; $stored = false;
ksort($activity['receiver']); ksort($activity['receiver']);
if (!self::isSolicitedMessage($activity, $item)) {
DBA::delete('item-uri', ['id' => $item['uri-id']]);
return;
}
foreach ($activity['receiver'] as $receiver) { foreach ($activity['receiver'] as $receiver) {
if ($receiver == -1) { if ($receiver == -1) {
continue; continue;

View file

@ -1775,12 +1775,11 @@ class DFRN
{ {
if (DBA::exists('contact', ["`nurl` = ? AND `uid` != ? AND `rel` IN (?, ?)", if (DBA::exists('contact', ["`nurl` = ? AND `uid` != ? AND `rel` IN (?, ?)",
Strings::normaliseLink($item["author-link"]), 0, Contact::FRIEND, Contact::SHARING])) { Strings::normaliseLink($item["author-link"]), 0, Contact::FRIEND, Contact::SHARING])) {
Logger::info('Author has got followers - accepted', ['uri' => $item['uri'], 'author' => $item["author-link"]]); Logger::debug('Author has got followers - accepted', ['uri' => $item['uri'], 'author' => $item["author-link"]]);
return true; return true;
} }
$taglist = Tag::getByURIId($item['uri-id'], [Tag::HASHTAG]); $tags = array_column(Tag::getByURIId($item['uri-id'], [Tag::HASHTAG]), 'name');
$tags = array_column($taglist, 'name');
return Relay::isSolicitedPost($tags, $item['body'], $item['author-id'], $item['uri'], Protocol::DFRN); return Relay::isSolicitedPost($tags, $item['body'], $item['author-id'], $item['uri'], Protocol::DFRN);
} }

View file

@ -2620,12 +2620,11 @@ class Diaspora
$contact = Contact::getByURL($author); $contact = Contact::getByURL($author);
if (DBA::exists('contact', ["`nurl` = ? AND `uid` != ? AND `rel` IN (?, ?)", if (DBA::exists('contact', ["`nurl` = ? AND `uid` != ? AND `rel` IN (?, ?)",
$contact['nurl'], 0, Contact::FRIEND, Contact::SHARING])) { $contact['nurl'], 0, Contact::FRIEND, Contact::SHARING])) {
Logger::info('Author has got followers - accepted', ['url' => $url, 'author' => $author]); Logger::debug('Author has got followers - accepted', ['url' => $url, 'author' => $author]);
return true; return true;
} }
$taglist = Tag::getByURIId($uriid, [Tag::HASHTAG]); $tags = array_column(Tag::getByURIId($uriid, [Tag::HASHTAG]), 'name');
$tags = array_column($taglist, 'name');
return Relay::isSolicitedPost($tags, $body, $contact['id'], $url, Protocol::DIASPORA); return Relay::isSolicitedPost($tags, $body, $contact['id'], $url, Protocol::DIASPORA);
} }