]> git.mxchange.org Git - friendica.git/commitdiff
Channels in your language
authorMichael <heluecht@pirati.ca>
Sun, 3 Sep 2023 05:23:49 +0000 (05:23 +0000)
committerMichael <heluecht@pirati.ca>
Sun, 3 Sep 2023 05:23:49 +0000 (05:23 +0000)
database.sql
doc/Accesskeys.md
src/Module/Conversation/Channel.php
static/defaults.config.php

index aa2b27eeb4e4aecca2454a033199b6ce0ddc148c..ea4a62647c7ec22d60216f03cf5cbbf26fa7893c 100644 (file)
@@ -1308,6 +1308,7 @@ CREATE TABLE IF NOT EXISTS `post-engagement` (
        `owner-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Item owner',
        `contact-type` tinyint NOT NULL DEFAULT 0 COMMENT 'Person, organisation, news, community, relay',
        `media-type` tinyint NOT NULL DEFAULT 0 COMMENT 'Type of media in a bit array (1 = image, 2 = video, 4 = audio',
+       `language` varbinary(128) COMMENT 'Language information about this post',
        `created` datetime COMMENT '',
        `comments` mediumint unsigned COMMENT 'Number of comments',
        `activities` mediumint unsigned COMMENT 'Number of activities (like, dislike, ...)',
index 936e044ee1a892311ed729cc023086ed0ffa41dd..885378231b27938316126f03a711c2c530642ac3 100644 (file)
@@ -37,6 +37,8 @@ General
 * i - Images
 * v - Videos
 * d - Audio
+* g - Posts in your language
+* o - Hot posts in your language
 
 ../profile
 --------
index ed4437cd32cf110284c2ea6766a5ecb9b22d2d1a..708764b455f99670148ac4f1b2bda04492c80f5b 100644 (file)
@@ -46,6 +46,7 @@ use Friendica\Network\HTTPException;
 use Friendica\Core\Session\Model\UserSession;
 use Friendica\Database\Database;
 use Friendica\Module\Response;
+use Friendica\Navigation\SystemMessages;
 use Friendica\Util\Profiler;
 use Psr\Log\LoggerInterface;
 
@@ -57,6 +58,8 @@ class Channel extends BaseModule
        const IMAGE     = 'image';
        const VIDEO     = 'video';
        const AUDIO     = 'audio';
+       const LANGUAGE  = 'language';
+       const HOTLANG   = 'hotlang';
 
        protected static $content;
        protected static $accountTypeString;
@@ -86,18 +89,19 @@ class Channel extends BaseModule
        protected $database;
 
 
-       public function __construct(Database $database, IManagePersonalConfigValues $pConfig, Mode $mode, Conversation $conversation, App\Page $page, IManageConfigValues $config, ICanCache $cache, IHandleUserSessions $session, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
+       public function __construct(SystemMessages $systemMessages, Database $database, IManagePersonalConfigValues $pConfig, Mode $mode, Conversation $conversation, App\Page $page, IManageConfigValues $config, ICanCache $cache, IHandleUserSessions $session, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
        {
                parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
 
-               $this->database     = $database;
-               $this->pConfig      = $pConfig;
-               $this->mode         = $mode;
-               $this->conversation = $conversation;
-               $this->page         = $page;
-               $this->config       = $config;
-               $this->cache        = $cache;
-               $this->session      = $session;
+               $this->systemMessages = $systemMessages;
+               $this->database       = $database;
+               $this->pConfig        = $pConfig;
+               $this->mode           = $mode;
+               $this->conversation   = $conversation;
+               $this->page           = $page;
+               $this->config         = $config;
+               $this->cache          = $cache;
+               $this->session        = $session;
        }
 
        protected function content(array $request = []): string
@@ -176,6 +180,28 @@ class Channel extends BaseModule
                                'accesskey' => 'd'
                        ];
 
+                       $owner     = User::getOwnerDataById($this->session->getLocalUserId());
+                       $languages = $this->l10n->getAvailableLanguages();
+                       if (!empty($owner['language']) && !empty($languages[$owner['language']])) {
+                               $tabs[] = [
+                                       'label'     => $languages[$owner['language']],
+                                       'url'       => 'channel/' . self::LANGUAGE,
+                                       'sel'       => self::$content == self::LANGUAGE ? 'active' : '',
+                                       'title'     => $this->l10n->t('Posts in %s', $languages[$owner['language']]),
+                                       'id'        => 'channel-language-tab',
+                                       'accesskey' => 'g'
+                               ];
+
+                               $tabs[] = [
+                                       'label'     => $this->l10n->t('Whats Hot %s', $languages[$owner['language']]),
+                                       'url'       => 'channel/' . self::HOTLANG,
+                                       'sel'       => self::$content == self::HOTLANG ? 'active' : '',
+                                       'title'     => $this->l10n->t('Posts in %s with a lot of interactions', $languages[$owner['language']]),
+                                       'id'        => 'channel-hotlang-tab',
+                                       'accesskey' => 'o'
+                               ];
+                       }
+
                        $tab_tpl = Renderer::getMarkupTemplate('common_tabs.tpl');
                        $o .= Renderer::replaceMacros($tab_tpl, ['$tabs' => $tabs]);
 
@@ -263,7 +289,7 @@ class Channel extends BaseModule
                        self::$content = self::FORYOU;
                }
 
-               if (!in_array(self::$content, [self::WHATSHOT, self::FORYOU, self::FOLLOWERS, self::IMAGE, self::VIDEO, self::AUDIO])) {
+               if (!in_array(self::$content, [self::WHATSHOT, self::FORYOU, self::FOLLOWERS, self::IMAGE, self::VIDEO, self::AUDIO, self::LANGUAGE, self::HOTLANG])) {
                        throw new HTTPException\BadRequestException($this->l10n->t('Channel not available.'));
                }
 
@@ -327,6 +353,16 @@ class Channel extends BaseModule
                        $condition = ["`media-type` & ?", 2];
                } elseif (self::$content == self::AUDIO) {
                        $condition = ["`media-type` & ?", 4];
+               } elseif (self::$content == self::LANGUAGE) {
+                       $owner     = User::getOwnerDataById($this->session->getLocalUserId());
+                       $condition = ["JSON_EXTRACT(`language`, ?) > ?", '$.' . $owner['language'], $this->config->get('channel', 'language_threshold')];
+               } elseif (self::$content == self::HOTLANG) {
+                       $owner = User::getOwnerDataById($this->session->getLocalUserId());
+                       if (!is_null(self::$accountType)) {
+                               $condition = ["(`comments` >= ? OR `activities` >= ?) AND `contact-type` = ? AND JSON_EXTRACT(`language`, ?) > ?", $this->getMedianComments(4), $this->getMedianActivities(4), self::$accountType, '$.' . $owner['language'], $this->config->get('channel', 'language_threshold')];
+                       } else {
+                               $condition = ["(`comments` >= ? OR `activities` >= ?) AND `contact-type` != ? AND JSON_EXTRACT(`language`, ?) > ?", $this->getMedianComments(4), $this->getMedianActivities(4), Contact::TYPE_COMMUNITY, '$.' . $owner['language'], $this->config->get('channel', 'language_threshold')];
+                       }
                }
 
                $condition[0] .= " AND NOT EXISTS(SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `cid` = `post-engagement`.`owner-id` AND (`ignored` OR `blocked` OR `collapsed`))";
index f73a3300a15f696d8b936458154b39df7857b8a3..d440f9c6a52976fcf4ebef25583d37de533612be 100644 (file)
@@ -797,12 +797,16 @@ return [
                'public' => true,
        ],
        'channel' => [
+               // engagement_hours (Integer)
+               // Number of hours posts are held in the engagement table
+               'engagement_hours' => 24,
+
                // interaction_score_days (Integer)
                // Number of days that are used to calculate the interaction score.
                'interaction_score_days' => 30,
 
-               // engagement_hours (Integer)
-               // Number of hours posts are held in the engagement table
-               'engagement_hours' => 24,
+               // language_threshold (Float)
+               // Treshold for the language detection.
+               'language_threshold' => 0.6,
        ],
 ];