mirror of
https://git.sekbaer.de/Friendica/friendica.git
synced 2025-06-11 17:44:27 +02:00
Accept relay posts based on the selected user languages
This commit is contained in:
parent
8b02c28547
commit
7c0b5be70f
4 changed files with 57 additions and 10 deletions
|
@ -1001,7 +1001,7 @@ class Processor
|
|||
}
|
||||
|
||||
$tags = array_column(Tag::getByURIId($item['uri-id'], [Tag::HASHTAG]), 'name');
|
||||
if (Relay::isSolicitedPost($tags, $item['body'], $item['author-id'], $item['uri'], Protocol::ACTIVITYPUB, $activity['thread-completion'] ?? 0)) {
|
||||
if (Relay::isSolicitedPost($tags, $item['title'] . ' ' . ($item['content-warning'] ?? '') . ' ' . $item['body'], $item['author-id'], $item['uri'], Protocol::ACTIVITYPUB, $activity['thread-completion'] ?? 0)) {
|
||||
Logger::debug('Post is accepted because of the relay settings', ['uri-id' => $item['uri-id'], 'guid' => $item['guid'], 'url' => $item['uri']]);
|
||||
return true;
|
||||
} else {
|
||||
|
|
|
@ -23,6 +23,7 @@ namespace Friendica\Protocol;
|
|||
|
||||
use Friendica\Content\Smilies;
|
||||
use Friendica\Content\Text\BBCode;
|
||||
use Friendica\Core\Cache\Enum\Duration;
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\Protocol;
|
||||
use Friendica\Database\DBA;
|
||||
|
@ -34,6 +35,7 @@ use Friendica\Model\Item;
|
|||
use Friendica\Model\Post;
|
||||
use Friendica\Model\Search;
|
||||
use Friendica\Model\Tag;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use Friendica\Util\Strings;
|
||||
|
||||
|
@ -185,13 +187,22 @@ class Relay
|
|||
}
|
||||
}
|
||||
|
||||
Logger::debug('Got languages', ['languages' => $languages, 'body' => $body]);
|
||||
|
||||
if (!empty($languages)) {
|
||||
if (in_array($languages[0], DI::config()->get('system', 'relay_deny_languages'))) {
|
||||
Logger::info('Unwanted language found', ['language' => $languages[0]]);
|
||||
return false;
|
||||
$cachekey = 'relay:isWantedLanguage';
|
||||
$user_languages = DI::cache()->get($cachekey);
|
||||
if (is_null($user_languages)) {
|
||||
$user_languages = User::getLanguages();
|
||||
DI::cache()->set($cachekey, $user_languages, Duration::HALF_HOUR);
|
||||
}
|
||||
|
||||
foreach ($languages as $language) {
|
||||
if (in_array($language, $user_languages)) {
|
||||
Logger::debug('Wanted language found', ['language' => $language, 'languages' => $languages, 'userlang' => $user_languages, 'body' => $body]);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Logger::debug('No wanted language found', ['languages' => $languages, 'userlang' => $user_languages, 'body' => $body]);
|
||||
return false;
|
||||
} elseif (DI::config()->get('system', 'relay_deny_undetected_language')) {
|
||||
Logger::info('Undetected language found', ['body' => $body]);
|
||||
return false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue