User defined channels can now base on circles/channels

This commit is contained in:
Michael 2023-09-24 00:45:07 +00:00
parent 2164787499
commit 9f23bee6e4
11 changed files with 136 additions and 73 deletions

View file

@ -62,6 +62,8 @@ final class Timeline extends \Friendica\BaseEntity
protected $path;
/** @var int */
protected $uid;
/** @var int */
protected $circle;
/** @var string */
protected $includeTags;
/** @var string */
@ -71,7 +73,7 @@ final class Timeline extends \Friendica\BaseEntity
/** @var int */
protected $mediaType;
public function __construct(string $code = null, string $label = null, string $description = null, string $accessKey = null, string $path = null, int $uid = null, string $includeTags = null, string $excludeTags = null, string $fullTextSearch = null, int $mediaType = null)
public function __construct(string $code = null, string $label = null, string $description = null, string $accessKey = null, string $path = null, int $uid = null, string $includeTags = null, string $excludeTags = null, string $fullTextSearch = null, int $mediaType = null, int $circle = null)
{
$this->code = $code;
$this->label = $label;
@ -83,5 +85,6 @@ final class Timeline extends \Friendica\BaseEntity
$this->excludeTags = $excludeTags;
$this->fullTextSearch = $fullTextSearch;
$this->mediaType = $mediaType;
$this->circle = $circle;
}
}

View file

@ -62,6 +62,7 @@ final class Timeline extends \Friendica\BaseFactory implements ICanCreateFromTab
$row['exclude-tags'] ?? null,
$row['full-text-search'] ?? null,
$row['media-type'] ?? null,
$row['circle'] ?? null,
);
}

View file

@ -91,6 +91,7 @@ class Channel extends \Friendica\BaseRepository
'description' => $Channel->description,
'access-key' => $Channel->accessKey,
'uid' => $Channel->uid,
'circle' => $Channel->circle,
'include-tags' => $Channel->includeTags,
'exclude-tags' => $Channel->excludeTags,
'full-text-search' => $Channel->fullTextSearch,

View file

@ -478,6 +478,22 @@ class Circle
return $return;
}
public static function getByUID(int $uid): array
{
$circles = [];
$stmt = DBA::select('group', [], ['deleted' => false, 'uid' => $uid, 'cid' => null], ['order' => ['id']]);
while ($circle = DBA::fetch($stmt)) {
$circles[] = [
'id' => $circle['id'],
'name' => $circle['name'],
];
}
DBA::close($stmt);
return $circles;
}
/**
* Returns a templated circle selection list
*

View file

@ -375,6 +375,16 @@ class Timeline extends BaseModule
$condition = [];
if (!empty($channel->circle)) {
if ($channel->circle == -1) {
$condition = ["`owner-id` IN (SELECT `pid` FROM `account-user-view` WHERE `uid` = ? AND `rel` IN (?, ?))", $uid, Contact::SHARING, Contact::FRIEND];
} elseif ($channel->circle == -2) {
$condition = ["`owner-id` IN (SELECT `pid` FROM `account-user-view` WHERE `uid` = ? AND `rel` = ?)", $uid, Contact::FOLLOWER];
} elseif ($channel->circle > 0) {
$condition = DBA::mergeConditions($condition, ["`owner-id` IN (SELECT `pid` FROM `group_member` INNER JOIN `account-user-view` ON `group_member`.`contact-id` = `account-user-view`.`id` WHERE `gid` = ? AND `account-user-view`.`uid` = ?)", $channel->circle, $uid]);
}
}
if (!empty($channel->fullTextSearch)) {
$search = $channel->fullTextSearch;
foreach (['from', 'to', 'group', 'tag', 'network', 'visibility'] as $keyword) {
@ -399,7 +409,8 @@ class Timeline extends BaseModule
$condition = DBA::mergeConditions($condition, ["`media-type` & ?", $channel->mediaType]);
}
return $condition;
// For "addLanguageCondition" to work, the condition must not be empty
return $condition ?: ["true"];
}
private function addLanguageCondition(int $uid, array $condition): array

View file

@ -27,6 +27,7 @@ use Friendica\Content\Conversation\Repository\Channel;
use Friendica\Core\L10n;
use Friendica\Core\Renderer;
use Friendica\Core\Session\Capability\IHandleUserSessions;
use Friendica\Model\Circle;
use Friendica\Module\BaseSettings;
use Friendica\Module\Response;
use Friendica\Network\HTTPException;
@ -67,6 +68,7 @@ class Channels extends BaseSettings
'description' => $request['new_description'],
'access-key' => substr(mb_strtolower($request['new_access_key']), 0, 1),
'uid' => $uid,
'circle' => (int)$request['new_circle'],
'include-tags' => $this->cleanTags($request['new_include_tags']),
'exclude-tags' => $this->cleanTags($request['new_exclude_tags']),
'full-text-search' => $this->cleanTags($request['new_text_search']),
@ -90,6 +92,7 @@ class Channels extends BaseSettings
'description' => $request['description'][$id],
'access-key' => substr(mb_strtolower($request['access_key'][$id]), 0, 1),
'uid' => $uid,
'circle' => (int)$request['circle'][$id],
'include-tags' => $this->cleanTags($request['include_tags'][$id]),
'exclude-tags' => $this->cleanTags($request['exclude_tags'][$id]),
'full-text-search' => $this->cleanTags($request['text_search'][$id]),
@ -111,12 +114,23 @@ class Channels extends BaseSettings
throw new HTTPException\ForbiddenException($this->t('Permission denied.'));
}
$circles = [
0 => $this->l10n->t('Global Community'),
-1 => $this->l10n->t('Following'),
-2 => $this->l10n->t('Followers'),
];
foreach (Circle::getByUID($uid) as $circle) {
$circles[$circle['id']] = $circle['name'];
}
$blocklistform = [];
foreach ($this->channel->selectByUid($uid) as $channel) {
$blocklistform[] = [
'label' => ["label[$channel->code]", $this->t('Label'), $channel->label, '', $this->t('Required')],
'description' => ["description[$channel->code]", $this->t("Description"), $channel->description],
'access_key' => ["access_key[$channel->code]", $this->t("Access Key"), $channel->accessKey],
'circle' => ["circle[$channel->code]", $this->t('Circle/Channel'), $channel->circle, '', $circles],
'include_tags' => ["include_tags[$channel->code]", $this->t("Include Tags"), $channel->includeTags],
'exclude_tags' => ["exclude_tags[$channel->code]", $this->t("Exclude Tags"), $channel->excludeTags],
'text_search' => ["text_search[$channel->code]", $this->t("Full Text Search"), $channel->fullTextSearch],
@ -132,6 +146,7 @@ class Channels extends BaseSettings
'label' => ["new_label", $this->t('Label'), '', $this->t('Short name for the channel. It is displayed on the channels widget.'), $this->t('Required')],
'description' => ["new_description", $this->t("Description"), '', $this->t('This should describe the content of the channel in a few word.')],
'access_key' => ["new_access_key", $this->t("Access Key"), '', $this->t('When you want to access this channel via an access key, you can define it here. Pay attention to not use an already used one.')],
'circle' => ['new_circle', $this->t('Circle/Channel'), 0, $this->t('Select a circle or channel, that your channel should be based on.'), $circles],
'include_tags' => ["new_include_tags", $this->t("Include Tags"), '', $this->t('Comma separated list of tags. A post will be used when it contains any of the listed tags.')],
'exclude_tags' => ["new_exclude_tags", $this->t("Exclude Tags"), '', $this->t('Comma separated list of tags. If a post contain any of these tags, then it will not be part of nthis channel.')],
'text_search' => ["new_text_search", $this->t("Full Text Search"), '', $this->t('Search terms for the body, supports the "boolean mode" operators from MariaDB. See the help for a complete list of operators and additional keywords: %s', '<a href="help/Channels">help/Channels</a>')],