]> git.mxchange.org Git - friendica.git/commitdiff
Simplified language check
authorMichael <heluecht@pirati.ca>
Sun, 7 Jan 2024 12:09:13 +0000 (12:09 +0000)
committerRoland Häder <roland@mxchange.org>
Sun, 28 Jan 2024 15:37:08 +0000 (16:37 +0100)
src/Model/User.php
src/Protocol/Relay.php

index 3f76da20431d2d22cec9e5d7af54a59ec425c52c..c60f8d7b28ab25fc1adb6aadf64e28b64174e4d7 100644 (file)
@@ -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);
index 934d09651db2d9a75de13ba87d4ab55faebc8105..1b9c7a0563d2debca1980bcfece90fe9fc7218a3 100644 (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]);
                        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;
        }
 
        /**