Simplified language check

This commit is contained in:
Michael 2024-01-07 12:09:13 +00:00
parent 6e830f7774
commit da02df20c3
2 changed files with 22 additions and 21 deletions

View File

@ -644,6 +644,10 @@ class User
} }
} }
if (!DI::config()->get('system', 'relay_deny_undetected_language')) {
$languages['un'] = 'un';
}
ksort($languages); ksort($languages);
$languages = array_keys($languages); $languages = array_keys($languages);
DI::cache()->set($cachekey, $languages); DI::cache()->set($cachekey, $languages);

View File

@ -188,34 +188,31 @@ class Relay
} }
} }
if (empty($languages) && empty($detected) && (empty($body) || Smilies::isEmojiPost($body))) { if (empty($detected)) {
$detected = ['un'];
}
if (empty($body) || Smilies::isEmojiPost($body)) {
Logger::debug('Empty body or only emojis', ['body' => $body]); Logger::debug('Empty body or only emojis', ['body' => $body]);
return true; return true;
} }
if (!empty($languages) || !empty($detected)) { $user_languages = User::getLanguages();
$user_languages = User::getLanguages();
foreach ($detected as $language) { foreach ($detected as $language) {
if (in_array($language, $user_languages)) { if (in_array($language, $user_languages)) {
Logger::debug('Wanted language found in detected languages', ['language' => $language, 'detected' => $detected, 'userlang' => $user_languages, 'body' => $body]); Logger::debug('Wanted language found in detected languages', ['language' => $language, 'detected' => $detected, 'userlang' => $user_languages, 'body' => $body]);
return true; return true;
}
} }
foreach ($languages as $language) {
if (in_array($language, $user_languages)) {
Logger::debug('Wanted language found in defined languages', ['language' => $language, 'languages' => $languages, 'detected' => $detected, 'userlang' => $user_languages, 'body' => $body]);
return true;
}
}
Logger::debug('No wanted language found', ['languages' => $languages, 'detected' => $detected, '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;
} }
foreach ($languages as $language) {
return true; if (in_array($language, $user_languages)) {
Logger::debug('Wanted language found in defined languages', ['language' => $language, 'languages' => $languages, 'detected' => $detected, 'userlang' => $user_languages, 'body' => $body]);
return true;
}
}
Logger::debug('No wanted language found', ['languages' => $languages, 'detected' => $detected, 'userlang' => $user_languages, 'body' => $body]);
return false;
} }
/** /**