Channels can now be created by users

This commit is contained in:
Michael 2023-09-19 09:05:28 +00:00
parent 9ed97caf7b
commit d68572ea44
14 changed files with 306 additions and 35 deletions

View file

@ -22,11 +22,15 @@
namespace Friendica\Content\Conversation\Entity;
/**
* @property-read string $code Channel code
* @property-read string $label Channel label
* @property-read string $description Channel description
* @property-read string $accessKey Access key
* @property-read string $path Path
* @property-read string $code Channel code
* @property-read string $label Channel label
* @property-read string $description Channel description
* @property-read string $accessKey Access key
* @property-read string $path Path
* @property-read int $uid User of the channel
* @property-read string $includeTags The tags to include in the channel
* @property-read string $excludeTags The tags to exclude in the channel
* @property-read string $fullTextSearch full text search pattern
*/
final class Timeline extends \Friendica\BaseEntity
{
@ -56,13 +60,28 @@ final class Timeline extends \Friendica\BaseEntity
protected $accessKey;
/** @var string */
protected $path;
/** @var int */
protected $uid;
/** @var string */
protected $includeTags;
/** @var string */
protected $excludeTags;
/** @var string */
protected $fullTextSearch;
/** @var int */
protected $mediaType;
public function __construct(string $code, string $label, string $description, string $accessKey, string $path = 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)
{
$this->code = $code;
$this->label = $label;
$this->description = $description;
$this->accessKey = $accessKey;
$this->path = $path;
$this->code = $code;
$this->label = $label;
$this->description = $description;
$this->accessKey = $accessKey;
$this->path = $path;
$this->uid = $uid;
$this->includeTags = $includeTags;
$this->excludeTags = $excludeTags;
$this->fullTextSearch = $fullTextSearch;
$this->mediaType = $mediaType;
}
}

View file

@ -21,27 +21,48 @@
namespace Friendica\Content\Conversation\Factory;
use Friendica\Capabilities\ICanCreateFromTableRow;
use Friendica\Content\Conversation\Collection\Timelines;
use Friendica\Model\User;
use Friendica\Content\Conversation\Entity\Timeline as TimelineEntity;
use Friendica\Content\Conversation\Repository\Channel;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\L10n;
use Friendica\Module\Conversation\Community;
use Psr\Log\LoggerInterface;
final class Timeline extends \Friendica\BaseFactory
final class Timeline extends \Friendica\BaseFactory implements ICanCreateFromTableRow
{
/** @var L10n */
protected $l10n;
/** @var IManageConfigValues The config */
protected $config;
/** @var Channel */
protected $channel;
public function __construct(L10n $l10n, LoggerInterface $logger, IManageConfigValues $config)
public function __construct(Channel $channel, L10n $l10n, LoggerInterface $logger, IManageConfigValues $config)
{
parent::__construct($logger);
$this->l10n = $l10n;
$this->config = $config;
$this->channel = $channel;
$this->l10n = $l10n;
$this->config = $config;
}
public function createFromTableRow(array $row): TimelineEntity
{
return new TimelineEntity(
$row['id'] ?? null,
$row['label'],
$row['description'] ?? null,
$row['access-key'] ?? null,
null,
$row['uid'],
$row['include-tags'] ?? null,
$row['exclude-tags'] ?? null,
$row['full-text-search'] ?? null,
$row['media-type'] ?? null,
);
}
/**
@ -65,6 +86,11 @@ final class Timeline extends \Friendica\BaseFactory
new TimelineEntity(TimelineEntity::AUDIO, $this->l10n->t('Audio'), $this->l10n->t('Posts with audio'), 'd'),
new TimelineEntity(TimelineEntity::VIDEO, $this->l10n->t('Videos'), $this->l10n->t('Posts with videos'), 'v'),
];
foreach ($this->channel->selectByUid($uid) as $channel) {
$tabs[] = $channel;
}
return new Timelines($tabs);
}
@ -113,8 +139,11 @@ final class Timeline extends \Friendica\BaseFactory
return in_array($selectedTab, [TimelineEntity::LOCAL, TimelineEntity::GLOBAL]);
}
public function isChannel(string $selectedTab): bool
public function isChannel(string $selectedTab, int $uid): bool
{
if (is_numeric($selectedTab) && $uid && $this->channel->existsById($selectedTab, $uid)) {
return true;
}
return in_array($selectedTab, [TimelineEntity::WHATSHOT, TimelineEntity::FORYOU, TimelineEntity::FOLLOWERS, TimelineEntity::SHARERSOFSHARERS, TimelineEntity::IMAGE, TimelineEntity::VIDEO, TimelineEntity::AUDIO, TimelineEntity::LANGUAGE]);
}
}

View file

@ -0,0 +1,100 @@
<?php
/**
* @copyright Copyright (C) 2010-2023, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
namespace Friendica\Content\Conversation\Repository;
use Friendica\BaseCollection;
use Friendica\Content\Conversation\Entity\Timeline as EntityTimeline;
use Friendica\Content\Conversation\Factory\Timeline;
use Friendica\Database\Database;
use Psr\Log\LoggerInterface;
class Channel extends \Friendica\BaseRepository
{
protected static $table_name = 'channel';
public function __construct(Database $database, LoggerInterface $logger, Timeline $factory)
{
parent::__construct($database, $logger, $factory);
}
/**
* Fetch a single user channel
*
* @param int $id
* @param int $uid
* @return EntityTimeline
* @throws \Friendica\Network\HTTPException\NotFoundException
*/
public function selectById(int $id, int $uid): EntityTimeline
{
return $this->_selectOne(['id' => $id, 'uid' => $uid]);
}
/**
* Checks if the provided channel id exists for this user
*
* @param integer $id
* @param integer $uid
* @return boolean
*/
public function existsById(int $id, int $uid): bool
{
return $this->exists(['id' => $id, 'uid' => $uid]);
}
/**
* Fetch all user channels
*
* @param integer $uid
* @return BaseCollection
*/
public function selectByUid(int $uid): BaseCollection
{
return $this->_select(['uid' => $uid]);
}
public function save(EntityTimeline $Channel): EntityTimeline
{
$fields = [
'label' => $Channel->label,
'description' => $Channel->description,
'access-key' => $Channel->accessKey,
'uid' => $Channel->uid,
'include-tags' => $Channel->includeTags,
'exclude-tags' => $Channel->excludeTags,
'full-text-search' => $Channel->fullTextSearch,
'media-type' => $Channel->mediaType,
];
if ($Channel->code) {
$this->db->update(self::$table_name, $fields, ['uid' => $Channel->uid, 'id' => $Channel->code]);
} else {
$this->db->insert(self::$table_name, $fields, Database::INSERT_IGNORE);
$newChannelId = $this->db->lastInsertId();
$Channel = $this->selectById($newChannelId, $Channel->uid);
}
return $Channel;
}
}