]> git.mxchange.org Git - friendica.git/commitdiff
Only use posts with wanted languages for subscribed tags
authorMichael <heluecht@pirati.ca>
Mon, 11 Dec 2023 22:07:01 +0000 (22:07 +0000)
committerMichael <heluecht@pirati.ca>
Mon, 11 Dec 2023 22:07:01 +0000 (22:07 +0000)
src/Model/Item.php
src/Model/User.php
src/Module/Conversation/Timeline.php
src/Module/Settings/Display.php

index 5458514aa5b4bfde125dd74b4935a54d56fb3ca3..e54d5fb098e8a79f337814200cc728494f31282a 100644 (file)
@@ -138,7 +138,7 @@ class Item
                'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'post-type', 'post-reason',
                'private', 'pubmail', 'visible', 'starred',
                'unseen', 'deleted', 'origin', 'mention', 'global', 'network',
-               'title', 'content-warning', 'body', 'location', 'coord', 'app',
+               'title', 'content-warning', 'body', 'language', 'location', 'coord', 'app',
                'rendered-hash', 'rendered-html', 'object-type', 'object', 'target-type', 'target',
                'author-id', 'author-link', 'author-name', 'author-avatar', 'author-network',
                'owner-id', 'owner-link', 'owner-name', 'owner-avatar', 'causer-id'
@@ -1541,7 +1541,25 @@ class Item
                        return;
                }
 
+               $languages = $item['language'] ? array_keys(json_decode($item['language'], true)) : [];
+               
                foreach (Tag::getUIDListByURIId($item['uri-id']) as $uid => $tags) {
+                       if (!empty($languages)) {
+                               $keep = false;
+                               $user_languages = User::getWantedLanguages($uid);
+                               foreach ($user_languages as $language) {
+                                       if (in_array($language, $languages)) {
+                                               $keep = true;
+                                       }
+                               }
+                               if ($keep) {
+                                       Logger::debug('Wanted languages found', ['uid' => $uid, 'user-languages' => $user_languages, 'item-languages' => $languages]);
+                               } else {
+                                       Logger::debug('No wanted languages found', ['uid' => $uid, 'user-languages' => $user_languages, 'item-languages' => $languages]);
+                                       continue;
+                               }
+                       }
+
                        $stored = self::storeForUserByUriId($item['uri-id'], $uid, ['post-reason' => self::PR_TAG]);
                        Logger::info('Stored item for users', ['uri-id' => $item['uri-id'], 'uid' => $uid, 'stored' => $stored]);
                        foreach ($tags as $tag) {
index 1d4c768aeab55f82c56ae5d317b2aeec1e48ed57..a1d3bc65f851faf8d0a8e2a1da878a46095dd05c 100644 (file)
@@ -575,6 +575,17 @@ class User
                return DI::l10n()->toISO6391(DI::config()->get('system', 'language'));
        }
 
+       /**
+        * Fetch the wanted languages for a given user
+        *
+        * @param integer $uid
+        * @return array
+        */
+       public static function getWantedLanguages(int $uid): array
+       {
+               return DI::pConfig()->get($uid, 'channel', 'languages', [User::getLanguageCode($uid)]) ?? [];
+       }
+
        /**
         * Get a list of all languages that are used by the users
         *
index 88e3261cf2e4fa580795af3311389b5e91a367bc..b5c936b13fbf3ab2bb6008565771df269a53f281 100644 (file)
@@ -426,7 +426,7 @@ class Timeline extends BaseModule
        private function addLanguageCondition(int $uid, array $condition): array
        {
                $conditions = [];
-               $languages  = $this->pConfig->get($uid, 'channel', 'languages', [User::getLanguageCode($uid)]);
+               $languages  = User::getWantedLanguages($uid);
                foreach ($languages as $language) {
                        $conditions[] = "JSON_EXTRACT(JSON_KEYS(language), '$[0]') = ?";
                        $condition[]  = $language;
@@ -439,7 +439,7 @@ class Timeline extends BaseModule
 
        private function getMedianComments(int $uid, int $divider): int
        {
-               $languages = $this->pConfig->get($uid, 'channel', 'languages', [User::getLanguageCode($uid)]);
+               $languages = User::getWantedLanguages($uid);
                $cache_key = 'Channel:getMedianComments:' . $divider . ':' . implode(':', $languages);
                $comments  = $this->cache->get($cache_key);
                if (!empty($comments)) {
@@ -463,7 +463,7 @@ class Timeline extends BaseModule
 
        private function getMedianActivities(int $uid, int $divider): int
        {
-               $languages  = $this->pConfig->get($uid, 'channel', 'languages', [User::getLanguageCode($uid)]);
+               $languages  = User::getWantedLanguages($uid);
                $cache_key  = 'Channel:getMedianActivities:' . $divider . ':' . implode(':', $languages);
                $activities = $this->cache->get($cache_key);
                if (!empty($activities)) {
index 34c62d1586dd8ddc6192388da325e44f5b6ac9b1..623651f481471502b1d5a79df44a8aaaa5e08705 100644 (file)
@@ -265,7 +265,7 @@ class Display extends BaseSettings
 
                $bookmarked_timelines = $this->pConfig->get($uid, 'system', 'network_timelines', $this->getAvailableTimelines($uid, true)->column('code'));
                $enabled_timelines    = $this->pConfig->get($uid, 'system', 'enabled_timelines', $this->getAvailableTimelines($uid, false)->column('code'));
-               $channel_languages = $this->pConfig->get($uid, 'channel', 'languages', [User::getLanguageCode($uid)]);
+               $channel_languages = User::getWantedLanguages($uid);
                $languages         = $this->l10n->getLanguageCodes(true);
 
                $timelines = [];