From 5349a81039e5addea68dc788ad7a8309442e2132 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 7 Jan 2024 12:09:13 +0000 Subject: [PATCH] Simplified language check --- src/Model/User.php | 4 ++++ src/Protocol/Relay.php | 37 +++++++++++++++++-------------------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/Model/User.php b/src/Model/User.php index 3f76da2043..c60f8d7b28 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -644,6 +644,10 @@ class User } } + if (!DI::config()->get('system', 'relay_deny_undetected_language')) { + $languages['un'] = 'un'; + } + ksort($languages); $languages = array_keys($languages); DI::cache()->set($cachekey, $languages); diff --git a/src/Protocol/Relay.php b/src/Protocol/Relay.php index 934d09651d..1b9c7a0563 100644 --- a/src/Protocol/Relay.php +++ b/src/Protocol/Relay.php @@ -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]); return true; } - if (!empty($languages) || !empty($detected)) { - $user_languages = User::getLanguages(); + $user_languages = User::getLanguages(); - foreach ($detected as $language) { - if (in_array($language, $user_languages)) { - Logger::debug('Wanted language found in detected languages', ['language' => $language, 'detected' => $detected, 'userlang' => $user_languages, 'body' => $body]); - return true; - } + foreach ($detected as $language) { + if (in_array($language, $user_languages)) { + Logger::debug('Wanted language found in detected languages', ['language' => $language, 'detected' => $detected, 'userlang' => $user_languages, 'body' => $body]); + 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; - } + } + 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; } - - return true; + Logger::debug('No wanted language found', ['languages' => $languages, 'detected' => $detected, 'userlang' => $user_languages, 'body' => $body]); + return false; } /** -- 2.39.5