From: Michael Date: Mon, 11 Dec 2023 22:07:01 +0000 (+0000) Subject: Only use posts with wanted languages for subscribed tags X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=14266a1ca44ffc3207752808f72ecff347ad095d;p=friendica.git Only use posts with wanted languages for subscribed tags --- diff --git a/src/Model/Item.php b/src/Model/Item.php index 5458514aa5..e54d5fb098 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -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) { diff --git a/src/Model/User.php b/src/Model/User.php index 1d4c768aea..a1d3bc65f8 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -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 * diff --git a/src/Module/Conversation/Timeline.php b/src/Module/Conversation/Timeline.php index 88e3261cf2..b5c936b13f 100644 --- a/src/Module/Conversation/Timeline.php +++ b/src/Module/Conversation/Timeline.php @@ -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)) { diff --git a/src/Module/Settings/Display.php b/src/Module/Settings/Display.php index 34c62d1586..623651f481 100644 --- a/src/Module/Settings/Display.php +++ b/src/Module/Settings/Display.php @@ -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 = [];