mirror of
https://github.com/friendica/friendica
synced 2025-04-23 01:10:11 +00:00
Merge remote-tracking branch 'upstream/develop' into channel-model
This commit is contained in:
commit
067d72ec85
7 changed files with 190 additions and 157 deletions
|
@ -50,6 +50,7 @@ use Friendica\Database\Database;
|
|||
use Friendica\Model\Item;
|
||||
use Friendica\Module\Response;
|
||||
use Friendica\Navigation\SystemMessages;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use Friendica\Util\Profiler;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
|
@ -221,7 +222,7 @@ class Channel extends BaseModule
|
|||
self::$content = ChannelEntity::FORYOU;
|
||||
}
|
||||
|
||||
if (!in_array(self::$content, [ChannelEntity::WHATSHOT, ChannelEntity::FORYOU, ChannelEntity::FOLLOWERS, ChannelEntity::IMAGE, ChannelEntity::VIDEO, ChannelEntity::AUDIO, ChannelEntity::LANGUAGE])) {
|
||||
if (!in_array(self::$content, [ChannelEntity::WHATSHOT, ChannelEntity::FORYOU, ChannelEntity::FOLLOWERS, ChannelEntity::SHARERSOFSHARERS, ChannelEntity::IMAGE, ChannelEntity::VIDEO, ChannelEntity::AUDIO, ChannelEntity::LANGUAGE])) {
|
||||
throw new HTTPException\BadRequestException($this->l10n->t('Channel not available.'));
|
||||
}
|
||||
|
||||
|
@ -271,14 +272,24 @@ class Channel extends BaseModule
|
|||
}
|
||||
} elseif (self::$content == ChannelEntity::FORYOU) {
|
||||
$cid = Contact::getPublicIdByUserId($this->session->getLocalUserId());
|
||||
|
||||
$condition = ["(`owner-id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `thread-score` > ?) OR
|
||||
((`comments` >= ? OR `activities` >= ?) AND `owner-id` IN (SELECT `pid` FROM `account-user-view` WHERE `uid` = ? AND `rel` IN (?, ?))) OR
|
||||
( `owner-id` IN (SELECT `pid` FROM `account-user-view` WHERE `uid` = ? AND `rel` IN (?, ?) AND `notify_new_posts`)))",
|
||||
$cid, $this->getMedianThreadScore($cid, 4), $this->getMedianComments(4), $this->getMedianActivities(4), $this->session->getLocalUserId(), Contact::FRIEND, Contact::SHARING,
|
||||
$this->session->getLocalUserId(), Contact::FRIEND, Contact::SHARING];
|
||||
$condition = [
|
||||
"(`owner-id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND `relation-thread-score` > ?) OR
|
||||
((`comments` >= ? OR `activities` >= ?) AND `owner-id` IN (SELECT `cid` FROM `contact-relation` WHERE `follows` AND `relation-cid` = ?)) OR
|
||||
(`owner-id` IN (SELECT `pid` FROM `account-user-view` WHERE `uid` = ? AND `rel` IN (?, ?) AND `notify_new_posts`)))",
|
||||
$cid, $this->getMedianRelationThreadScore($cid, 4), $this->getMedianComments(4), $this->getMedianActivities(4), $cid,
|
||||
$this->session->getLocalUserId(), Contact::FRIEND, Contact::SHARING
|
||||
];
|
||||
} elseif (self::$content == ChannelEntity::FOLLOWERS) {
|
||||
$condition = ["`owner-id` IN (SELECT `pid` FROM `account-user-view` WHERE `uid` = ? AND `rel` = ?)", $this->session->getLocalUserId(), Contact::FOLLOWER];
|
||||
} elseif (self::$content == ChannelEntity::SHARERSOFSHARERS) {
|
||||
$cid = Contact::getPublicIdByUserId($this->session->getLocalUserId());
|
||||
|
||||
$condition = [
|
||||
"`owner-id` IN (SELECT `cid` FROM `contact-relation` WHERE `follows` AND `last-interaction` > ?
|
||||
AND `relation-cid` IN (SELECT `cid` FROM `contact-relation` WHERE `follows` AND `relation-cid` = ? AND `relation-thread-score` >= ?)
|
||||
AND NOT `cid` IN (SELECT `cid` FROM `contact-relation` WHERE `follows` AND `relation-cid` = ?))",
|
||||
DateTimeFormat::utc('now - 90 day'), $cid, $this->getMedianRelationThreadScore($cid, 4), $cid
|
||||
];
|
||||
} elseif (self::$content == ChannelEntity::IMAGE) {
|
||||
$condition = ["`media-type` & ?", 1];
|
||||
} elseif (self::$content == ChannelEntity::VIDEO) {
|
||||
|
@ -398,7 +409,7 @@ class Channel extends BaseModule
|
|||
return $activities;
|
||||
}
|
||||
|
||||
private function getMedianThreadScore(int $cid, int $divider): int
|
||||
private function getMedianRelationThreadScore(int $cid, int $divider): int
|
||||
{
|
||||
$cache_key = 'Channel:getThreadScore:' . $cid . ':' . $divider;
|
||||
$score = $this->cache->get($cache_key);
|
||||
|
@ -406,9 +417,9 @@ class Channel extends BaseModule
|
|||
return $score;
|
||||
}
|
||||
|
||||
$limit = $this->database->count('contact-relation', ["`cid` = ? AND `thread-score` > ?", $cid, 0]) / $divider;
|
||||
$relation = $this->database->selectToArray('contact-relation', ['thread-score'], ['cid' => $cid], ['order' => ['thread-score' => true], 'limit' => [$limit, 1]]);
|
||||
$score = $relation[0]['thread-score'] ?? 0;
|
||||
$limit = $this->database->count('contact-relation', ["`relation-cid` = ? AND `relation-thread-score` > ?", $cid, 0]) / $divider;
|
||||
$relation = $this->database->selectToArray('contact-relation', ['relation-thread-score'], ['relation-cid' => $cid], ['order' => ['relation-thread-score' => true], 'limit' => [$limit, 1]]);
|
||||
$score = $relation[0]['relation-thread-score'] ?? 0;
|
||||
if (empty($score)) {
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue