[COMPONENT][Collection] Refactoring: Further work in abstracting collections

This commit is contained in:
Diogo Peralta Cordeiro 2022-01-02 20:04:52 +00:00
parent def5f36c25
commit 5fa8056899
Signed by: diogo
GPG Key ID: 18D2D35001FBFAB0
38 changed files with 119 additions and 77 deletions

View File

@ -0,0 +1,11 @@
<?php
declare(strict_types = 1);
namespace Component\Collection;
use App\Core\Modules\Component;
class Collection extends Component
{
}

View File

@ -30,15 +30,14 @@ declare(strict_types = 1);
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/ */
namespace App\Core\Controller; namespace Component\Collection\Util;
use App\Core\DB\DB; use App\Core\DB\DB;
use function App\Core\I18n\_m; use function App\Core\I18n\_m;
use App\Core\Router\Router; use App\Core\Router\Router;
use App\Util\Exception\ClientException; use App\Util\Exception\ClientException;
use Component\Feed\Util\FeedController;
abstract class ActorController extends FeedController trait ActorControllerTrait
{ {
/** /**
* Generic function that handles getting a representation for an actor from id * Generic function that handles getting a representation for an actor from id

View File

@ -0,0 +1,9 @@
<?php
declare(strict_types = 1);
namespace Component\Collection\Util\Controller;
class CircleController extends OrderedCollection
{
}

View File

@ -0,0 +1,11 @@
<?php
declare(strict_types = 1);
namespace Component\Collection\Util\Controller;
use App\Core\Controller;
class Collection extends Controller
{
}

View File

@ -30,17 +30,15 @@ declare(strict_types = 1);
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/ */
namespace Component\Feed\Util; namespace Component\Collection\Util\Controller;
use App\Core\Controller;
use App\Core\Event; use App\Core\Event;
use App\Entity\Actor; use App\Entity\Actor;
use App\Entity\Note; use App\Entity\Note;
use App\Util\Common; use App\Util\Common;
use Functional as F; use Functional as F;
use function App\Core\I18n\_m;
abstract class FeedController extends Controller abstract class FeedController extends OrderedCollection
{ {
/** /**
* Post-processing of the result of a feed controller, to remove any * Post-processing of the result of a feed controller, to remove any

View File

@ -29,20 +29,19 @@ declare(strict_types = 1);
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/ */
namespace App\Core\Controller; namespace Component\Collection\Util\Controller;
use App\Core\DB\DB; use App\Core\DB\DB;
use App\Core\Form; use App\Core\Form;
use function App\Core\I18n\_m;
use App\Entity\LocalUser; use App\Entity\LocalUser;
use App\Util\Common; use App\Util\Common;
use App\Util\Exception\RedirectException; use App\Util\Exception\RedirectException;
use Component\Feed\Util\FeedController;
use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use function App\Core\I18n\_m;
abstract class CollectionController extends FeedController abstract class MetaCollectionController extends FeedController
{ {
protected string $slug = 'collectionsEntry'; protected string $slug = 'collectionsEntry';
protected string $plural_slug = 'collectionsList'; protected string $plural_slug = 'collectionsList';
@ -50,19 +49,19 @@ abstract class CollectionController extends FeedController
abstract public function getCollectionUrl(int $owner_id, string $owner_nickname, int $collection_id): string; abstract public function getCollectionUrl(int $owner_id, string $owner_nickname, int $collection_id): string;
abstract public function getCollectionItems(int $owner_id, $collection_id): array; abstract public function getCollectionItems(int $owner_id, $collection_id): array;
abstract public function getCollectionsBy(int $owner_id): array; abstract public function getCollectionsByActorId(int $owner_id): array;
abstract public function getCollectionBy(int $owner_id, int $collection_id); abstract public function getCollectionBy(int $owner_id, int $collection_id);
abstract public function createCollection(int $owner_id, string $name); abstract public function createCollection(int $owner_id, string $name);
public function collectionsListViewByActorNickname(Request $request, string $nickname): array public function collectionsViewByActorNickname(Request $request, string $nickname): array
{ {
$user = DB::findOneBy(LocalUser::class, ['nickname' => $nickname]); $user = DB::findOneBy(LocalUser::class, ['nickname' => $nickname]);
return self::collectionsListView($request, $user->getId(), $nickname); return self::collectionsView($request, $user->getId(), $nickname);
} }
public function collectionsListViewByActorId(Request $request, int $id): array public function collectionsViewByActorId(Request $request, int $id): array
{ {
return self::collectionsListView($request, $id, null); return self::collectionsView($request, $id, null);
} }
/** /**
@ -73,12 +72,12 @@ abstract class CollectionController extends FeedController
* *
* @return array twig template options * @return array twig template options
*/ */
public function collectionsListView(Request $request, int $id, ?string $nickname): array public function collectionsView(Request $request, int $id, ?string $nickname): array
{ {
$collections = $this->getCollectionsBy($id); $collections = $this->getCollectionsByActorId($id);
$create_title = _m('Create a ' . mb_strtolower(preg_replace( '/([a-z0-9])([A-Z])/', "$1 $2", $this->slug))); $create_title = _m('Create a ' . mb_strtolower(preg_replace('/([a-z0-9])([A-Z])/', '$1 $2', $this->slug)));
$collections_title = _m('Your ' . mb_strtolower(preg_replace( '/([a-z0-9])([A-Z])/', "$1 $2", $this->plural_slug))); $collections_title = _m('Your ' . mb_strtolower(preg_replace('/([a-z0-9])([A-Z])/', '$1 $2', $this->plural_slug)));
// create collection form // create collection form
$create = null; $create = null;
if (Common::user()?->getId() === $id) { if (Common::user()?->getId() === $id) {
@ -191,7 +190,7 @@ abstract class CollectionController extends FeedController
}; };
return [ return [
'_template' => 'collections/collection_list_view.html.twig', '_template' => 'collection/meta_collections.html.twig',
'page_title' => $this->page_title, 'page_title' => $this->page_title,
'list_title' => $collections_title, 'list_title' => $collections_title,
'add_collection' => $create?->createView(), 'add_collection' => $create?->createView(),

View File

@ -0,0 +1,9 @@
<?php
declare(strict_types = 1);
namespace Component\Collection\Util\Controller;
class OrderedCollection extends Collection
{
}

View File

@ -29,12 +29,13 @@ declare(strict_types = 1);
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/ */
namespace App\Core\Modules; namespace Component\Collection\Util;
use App\Core\DB\DB; use App\Core\DB\DB;
use App\Core\Event; use App\Core\Event;
use App\Core\Form; use App\Core\Form;
use function App\Core\I18n\_m; use function App\Core\I18n\_m;
use App\Core\Modules\Plugin;
use App\Entity\Actor; use App\Entity\Actor;
use App\Util\Common; use App\Util\Common;
use App\Util\Exception\RedirectException; use App\Util\Exception\RedirectException;
@ -44,7 +45,7 @@ use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
abstract class Collection extends Plugin abstract class MetaCollectionPlugin extends Plugin
{ {
protected string $slug = 'collection'; protected string $slug = 'collection';
protected string $plural_slug = 'collections'; protected string $plural_slug = 'collections';
@ -140,7 +141,7 @@ abstract class Collection extends Plugin
} }
$res[] = Formatting::twigRenderFile( $res[] = Formatting::twigRenderFile(
'collections/widget.html.twig', 'collection/widget_add_to.html.twig',
[ [
'ctitle' => _m('Add to ' . $this->plural_slug), 'ctitle' => _m('Add to ' . $this->plural_slug),
'user' => $user, 'user' => $user,

View File

@ -1,4 +1,4 @@
{% extends '/feed/feed.html.twig' %} {% extends '/collection/notes.html.twig' %}
{% block title %}{{ page_title | trans }}{% endblock %} {% block title %}{{ page_title | trans }}{% endblock %}

View File

@ -29,12 +29,12 @@ namespace Component\Conversation\Controller;
use App\Core\DB\DB; use App\Core\DB\DB;
use App\Core\Form; use App\Core\Form;
use Component\Collection\Util\Controller\FeedController;
use function App\Core\I18n\_m; use function App\Core\I18n\_m;
use App\Util\Common; use App\Util\Common;
use App\Util\Exception\RedirectException; use App\Util\Exception\RedirectException;
use Component\Conversation\Entity\ConversationBlock; use Component\Conversation\Entity\ConversationBlock;
use Component\Feed\Feed; use Component\Feed\Feed;
use Component\Feed\Util\FeedController;
use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
@ -50,7 +50,7 @@ class Conversation extends FeedController
$data = Feed::query(query: "note-conversation:{$conversation_id}", page: $this->int('p') ?? 1); $data = Feed::query(query: "note-conversation:{$conversation_id}", page: $this->int('p') ?? 1);
$notes = $data['notes']; $notes = $data['notes'];
return [ return [
'_template' => 'feed/feed.html.twig', '_template' => 'collection/notes.html.twig',
'notes' => $notes, 'notes' => $notes,
'should_format' => false, 'should_format' => false,
'page_title' => _m('Conversation'), 'page_title' => _m('Conversation'),

View File

@ -32,8 +32,8 @@ use App\Util\Exception\ClientException;
use App\Util\Exception\NoLoggedInUser; use App\Util\Exception\NoLoggedInUser;
use App\Util\Exception\NoSuchNoteException; use App\Util\Exception\NoSuchNoteException;
use App\Util\Exception\ServerException; use App\Util\Exception\ServerException;
use Component\Collection\Util\Controller\FeedController;
use Component\Feed\Feed; use Component\Feed\Feed;
use Component\Feed\Util\FeedController;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use function App\Core\I18n\_m; use function App\Core\I18n\_m;
@ -62,7 +62,7 @@ class Reply extends FeedController
$data = Feed::query(query: "note-conversation:{$conversation_id}", page: $this->int('p') ?? 1); $data = Feed::query(query: "note-conversation:{$conversation_id}", page: $this->int('p') ?? 1);
$notes = $data['notes']; $notes = $data['notes'];
return [ return [
'_template' => 'feed/feed.html.twig', '_template' => 'collection/notes.html.twig',
'notes' => $notes, 'notes' => $notes,
'should_format' => false, 'should_format' => false,
'page_title' => _m('Conversation'), 'page_title' => _m('Conversation'),

View File

@ -37,8 +37,8 @@ namespace Component\Feed\Controller;
use function App\Core\I18n\_m; use function App\Core\I18n\_m;
use App\Util\Common; use App\Util\Common;
use Component\Collection\Util\Controller\FeedController;
use Component\Feed\Feed; use Component\Feed\Feed;
use Component\Feed\Util\FeedController;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
class Feeds extends FeedController class Feeds extends FeedController
@ -54,7 +54,7 @@ class Feeds extends FeedController
language: Common::actor()?->getTopLanguage()?->getLocale(), language: Common::actor()?->getTopLanguage()?->getLocale(),
); );
return [ return [
'_template' => 'feed/feed.html.twig', '_template' => 'collection/notes.html.twig',
'page_title' => _m(\is_null(Common::user()) ? 'Feed' : 'Planet'), 'page_title' => _m(\is_null(Common::user()) ? 'Feed' : 'Planet'),
'notes' => $data['notes'], 'notes' => $data['notes'],
]; ];
@ -74,7 +74,7 @@ class Feeds extends FeedController
actor: $actor, actor: $actor,
); );
return [ return [
'_template' => 'feed/feed.html.twig', '_template' => 'collection/notes.html.twig',
'page_title' => _m('Home'), 'page_title' => _m('Home'),
'notes' => $data['notes'], 'notes' => $data['notes'],
]; ];

View File

@ -37,8 +37,8 @@ namespace Component\FreeNetwork\Controller;
use App\Core\DB\DB; use App\Core\DB\DB;
use function App\Core\I18n\_m; use function App\Core\I18n\_m;
use App\Util\Common; use App\Util\Common;
use Component\Collection\Util\Controller\FeedController;
use Component\Feed\Feed; use Component\Feed\Feed;
use Component\Feed\Util\FeedController;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
class Feeds extends FeedController class Feeds extends FeedController
@ -58,7 +58,7 @@ class Feeds extends FeedController
language: Common::actor()?->getTopLanguage()?->getLocale(), language: Common::actor()?->getTopLanguage()?->getLocale(),
); );
return [ return [
'_template' => 'feed/feed.html.twig', '_template' => 'collection/notes.html.twig',
'page_title' => _m('Meteorites'), 'page_title' => _m('Meteorites'),
'should_format' => true, 'should_format' => true,
'notes' => $data['notes'], 'notes' => $data['notes'],
@ -86,7 +86,7 @@ class Feeds extends FeedController
EOF, EOF,
); );
return [ return [
'_template' => 'feed/feed.html.twig', '_template' => 'collection/notes.html.twig',
'page_title' => _m('Planetary System'), 'page_title' => _m('Planetary System'),
'should_format' => true, 'should_format' => true,
'notes' => $notes, 'notes' => $notes,
@ -107,7 +107,7 @@ class Feeds extends FeedController
language: Common::actor()?->getTopLanguage()?->getLocale(), language: Common::actor()?->getTopLanguage()?->getLocale(),
); );
return [ return [
'_template' => 'feed/feed.html.twig', '_template' => 'collection/notes.html.twig',
'page_title' => _m('Galaxy'), 'page_title' => _m('Galaxy'),
'should_format' => true, 'should_format' => true,
'notes' => $data['notes'], 'notes' => $data['notes'],

View File

@ -24,7 +24,6 @@ declare(strict_types = 1);
namespace Component\Group\Controller; namespace Component\Group\Controller;
use App\Core\Cache; use App\Core\Cache;
use App\Core\Controller\ActorController;
use App\Core\DB\DB; use App\Core\DB\DB;
use App\Core\Form; use App\Core\Form;
use function App\Core\I18n\_m; use function App\Core\I18n\_m;
@ -36,13 +35,16 @@ use App\Util\Exception\ClientException;
use App\Util\Exception\RedirectException; use App\Util\Exception\RedirectException;
use App\Util\Form\ActorForms; use App\Util\Form\ActorForms;
use App\Util\Nickname; use App\Util\Nickname;
use Component\Collection\Util\ActorControllerTrait;
use Component\Collection\Util\Controller\FeedController;
use Component\Group\Entity\GroupMember; use Component\Group\Entity\GroupMember;
use Component\Group\Entity\LocalGroup; use Component\Group\Entity\LocalGroup;
use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
class Group extends ActorController class Group extends FeedController
{ {
use ActorControllerTrait;
public function groupViewId(Request $request, int $id) public function groupViewId(Request $request, int $id)
{ {
return $this->handleActorById( return $this->handleActorById(

View File

@ -94,7 +94,7 @@ class Group extends Component
$group = $this->getGroupFromContext($request); $group = $this->getGroupFromContext($request);
if (!\is_null($group)) { if (!\is_null($group)) {
$nick = '!' . $group->getNickname(); $nick = '!' . $group->getNickname();
$targets[$nick] = $nick; $targets[$nick] = $group->getId();
} }
return Event::next; return Event::next;
} }

View File

@ -33,7 +33,7 @@ use App\Entity\Feed;
use App\Util\Common; use App\Util\Common;
use App\Util\Exception\ClientException; use App\Util\Exception\ClientException;
use App\Util\Exception\RedirectException; use App\Util\Exception\RedirectException;
use Component\Feed\Util\FeedController; use Component\Collection\Util\Controller\FeedController;
use Functional as F; use Functional as F;
use Symfony\Component\Form\Extension\Core\Type\IntegerType; use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\SubmitType;

View File

@ -57,7 +57,7 @@ class Feed extends Controller
) )
EOF, ['id' => $user->getId()]); EOF, ['id' => $user->getId()]);
return [ return [
'_template' => 'feed/feed.html.twig', '_template' => 'collection/notes.html.twig',
'page_title' => _m('Notifications'), 'page_title' => _m('Notifications'),
'should_format' => true, 'should_format' => true,
'notes' => $notes, 'notes' => $notes,

View File

@ -30,8 +30,8 @@ use App\Util\Exception\BugFoundException;
use App\Util\Exception\RedirectException; use App\Util\Exception\RedirectException;
use App\Util\Form\FormFields; use App\Util\Form\FormFields;
use App\Util\Formatting; use App\Util\Formatting;
use Component\Collection\Util\Controller\FeedController;
use Component\Feed\Feed; use Component\Feed\Feed;
use Component\Feed\Util\FeedController;
use Component\Search as Comp; use Component\Search as Comp;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\SubmitType;

View File

@ -1,4 +1,4 @@
{% extends 'feed/feed.html.twig' %} {% extends 'collection/notes.html.twig' %}
{% block body %} {% block body %}

View File

@ -165,7 +165,7 @@ class Inbox extends Controller
$ap_actor->getActorId(), $ap_actor->getActorId(),
Discovery::normalize($actor->getNickname() . '@' . parse_url($ap_actor->getInboxUri(), PHP_URL_HOST)), Discovery::normalize($actor->getNickname() . '@' . parse_url($ap_actor->getInboxUri(), PHP_URL_HOST)),
); );
Event::handle('NewNotification', [$actor, $ap_act->getActivity(), [], _m('{nickname} mentioned you.', ['nickname' => $actor->getNickname()])]); Event::handle('NewNotification', [$actor, $ap_act->getActivity(), [], _m('{nickname} mentioned you.', ['{nickname}' => $actor->getNickname()])]);
DB::flush(); DB::flush();
dd($ap_act, $act = $ap_act->getActivity(), $act->getActor(), $act->getObject()); dd($ap_act, $act = $ap_act->getActivity(), $act->getActor(), $act->getObject());

View File

@ -34,18 +34,18 @@ namespace Plugin\ActorCircles;
use App\Core\DB\DB; use App\Core\DB\DB;
use App\Core\Event; use App\Core\Event;
use function App\Core\I18n\_m; use function App\Core\I18n\_m;
use App\Core\Modules\Collection;
use App\Core\Router\RouteLoader; use App\Core\Router\RouteLoader;
use App\Core\Router\Router; use App\Core\Router\Router;
use App\Entity\Actor; use App\Entity\Actor;
use App\Entity\Feed; use App\Entity\Feed;
use App\Entity\LocalUser; use App\Entity\LocalUser;
use App\Util\Nickname; use App\Util\Nickname;
use Component\Collection\Util\MetaCollectionPlugin;
use Plugin\ActorCircles\Controller as C; use Plugin\ActorCircles\Controller as C;
use Plugin\ActorCircles\Entity as E; use Plugin\ActorCircles\Entity as E;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
class ActorCircles extends Collection class ActorCircles extends MetaCollectionPlugin
{ {
protected string $slug = 'circle'; protected string $slug = 'circle';
protected string $plural_slug = 'circles'; protected string $plural_slug = 'circles';
@ -138,23 +138,23 @@ class ActorCircles extends Collection
$r->connect( $r->connect(
id: 'actor_circles_view_by_actor_id', id: 'actor_circles_view_by_actor_id',
uri_path: '/actor/{id<\d+>}/circles', uri_path: '/actor/{id<\d+>}/circles',
target: [C\Controller::class, 'collectionsViewByActorId'], target: [C\Circles::class, 'collectionsViewByActorId'],
); );
$r->connect( $r->connect(
id: 'actor_circles_view_by_nickname', id: 'actor_circles_view_by_nickname',
uri_path: '/@{nickname<' . Nickname::DISPLAY_FMT . '>}/circles', uri_path: '/@{nickname<' . Nickname::DISPLAY_FMT . '>}/circles',
target: [C\Controller::class, 'collectionsByActorNickname'], target: [C\Circles::class, 'collectionsViewByActorNickname'],
); );
// View notes from a circle by actor id and nickname // View notes from a circle by actor id and nickname
$r->connect( $r->connect(
id: 'actor_circles_notes_view_by_actor_id', id: 'actor_circles_notes_view_by_actor_id',
uri_path: '/actor/{id<\d+>}/circles/{cid<\d+>}', uri_path: '/actor/{id<\d+>}/circles/{cid<\d+>}',
target: [C\Controller::class, 'collectionNotesViewByActorId'], target: [C\Circles::class, 'collectionsEntryViewNotesByActorId'],
); );
$r->connect( $r->connect(
id: 'actor_circles_notes_view_by_nickname', id: 'actor_circles_notes_view_by_nickname',
uri_path: '/@{nickname<' . Nickname::DISPLAY_FMT . '>}/circles/{cid<\d+>}', uri_path: '/@{nickname<' . Nickname::DISPLAY_FMT . '>}/circles/{cid<\d+>}',
target: [C\Controller::class, 'collectionNotesByNickname'], target: [C\Circles::class, 'collectionsEntryViewNotesByNickname'],
); );
return Event::next; return Event::next;
} }

View File

@ -23,12 +23,12 @@ declare(strict_types = 1);
namespace Plugin\ActorCircles\Controller; namespace Plugin\ActorCircles\Controller;
use App\Core\Controller\CollectionController;
use App\Core\DB\DB; use App\Core\DB\DB;
use App\Core\Router\Router; use App\Core\Router\Router;
use Component\Collection\Util\Controller\MetaCollectionController;
use Plugin\ActorCircles\Entity\ActorCircles; use Plugin\ActorCircles\Entity\ActorCircles;
class Controller extends CollectionController class Circles extends MetaCollectionController
{ {
protected string $slug = 'circle'; protected string $slug = 'circle';
protected string $plural_slug = 'circles'; protected string $plural_slug = 'circles';
@ -69,16 +69,16 @@ class Controller extends CollectionController
['circle_id' => $collection_id], ['circle_id' => $collection_id],
); );
return [ return [
'_template' => 'feed/feed.html.twig', '_template' => 'collection/notes.html.twig',
'notes' => array_values($notes), 'notes' => array_values($notes),
]; ];
} }
public function getCollectionsBy(int $owner_id): array public function getCollectionsByActorId(int $owner_id): array
{ {
return DB::findBy(ActorCircles::class, ['actor_id' => $owner_id], order_by: ['id' => 'desc']); return DB::findBy(ActorCircles::class, ['actor_id' => $owner_id], order_by: ['id' => 'desc']);
} }
public function getCollectionBy(int $owner_id, int $collection_id): ActorCircles public function getCollectionBy(int $owner_id, int $collection_id): ActorCircles
{ {
return DB::findOneBy(ActorCircles::class, ['id' => $collection_id]); return DB::findOneBy(ActorCircles::class, ['id' => $collection_id, 'actor_id' => $owner_id]);
} }
} }

View File

@ -33,20 +33,20 @@ namespace Plugin\AttachmentCollections;
use App\Core\DB\DB; use App\Core\DB\DB;
use App\Core\Event; use App\Core\Event;
use App\Core\Modules\Collection; use function App\Core\I18n\_m;
use App\Core\Router\RouteLoader; use App\Core\Router\RouteLoader;
use App\Core\Router\Router; use App\Core\Router\Router;
use App\Entity\Actor; use App\Entity\Actor;
use App\Entity\Feed; use App\Entity\Feed;
use App\Entity\LocalUser; use App\Entity\LocalUser;
use App\Util\Nickname; use App\Util\Nickname;
use Component\Collection\Util\MetaCollectionPlugin;
use Plugin\AttachmentCollections\Controller\AttachmentCollections as AttachmentCollectionsController; use Plugin\AttachmentCollections\Controller\AttachmentCollections as AttachmentCollectionsController;
use Plugin\AttachmentCollections\Entity\AttachmentCollection; use Plugin\AttachmentCollections\Entity\AttachmentCollection;
use Plugin\AttachmentCollections\Entity\AttachmentCollectionEntry; use Plugin\AttachmentCollections\Entity\AttachmentCollectionEntry;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use function App\Core\I18n\_m;
class AttachmentCollections extends Collection class AttachmentCollections extends MetaCollectionPlugin
{ {
protected function createCollection(Actor $owner, array $vars, string $name) protected function createCollection(Actor $owner, array $vars, string $name)
{ {
@ -128,12 +128,12 @@ class AttachmentCollections extends Collection
$r->connect( $r->connect(
id: 'collections_view_by_actor_id', id: 'collections_view_by_actor_id',
uri_path: '/actor/{id<\d+>}/collections', uri_path: '/actor/{id<\d+>}/collections',
target: [AttachmentCollectionsController::class, 'collectionsListViewByActorId'], target: [AttachmentCollectionsController::class, 'collectionsViewByActorId'],
); );
$r->connect( $r->connect(
id: 'collections_view_by_nickname', id: 'collections_view_by_nickname',
uri_path: '/@{nickname<' . Nickname::DISPLAY_FMT . '>}/collections', uri_path: '/@{nickname<' . Nickname::DISPLAY_FMT . '>}/collections',
target: [AttachmentCollectionsController::class, 'collectionsListViewByActorNickname'], target: [AttachmentCollectionsController::class, 'collectionsViewByActorNickname'],
); );
// View notes from a collection by actor id and nickname // View notes from a collection by actor id and nickname
$r->connect( $r->connect(

View File

@ -23,12 +23,12 @@ declare(strict_types = 1);
namespace Plugin\AttachmentCollections\Controller; namespace Plugin\AttachmentCollections\Controller;
use App\Core\Controller\CollectionController;
use App\Core\DB\DB; use App\Core\DB\DB;
use App\Core\Router\Router; use App\Core\Router\Router;
use Component\Collection\Util\Controller\MetaCollectionController;
use Plugin\AttachmentCollections\Entity\AttachmentCollection; use Plugin\AttachmentCollections\Entity\AttachmentCollection;
class AttachmentCollections extends CollectionController class AttachmentCollections extends MetaCollectionController
{ {
public function createCollection(int $owner_id, string $name) public function createCollection(int $owner_id, string $name)
{ {
@ -69,7 +69,7 @@ class AttachmentCollections extends CollectionController
'bare_notes' => array_values($notes), 'bare_notes' => array_values($notes),
]; ];
} }
public function getCollectionsBy(int $owner_id): array public function getCollectionsByActorId(int $owner_id): array
{ {
return DB::findBy(AttachmentCollection::class, ['actor_id' => $owner_id], order_by: ['id' => 'desc']); return DB::findBy(AttachmentCollection::class, ['actor_id' => $owner_id], order_by: ['id' => 'desc']);
} }

View File

@ -1,4 +1,4 @@
{% extends 'collections/collection_entry_view.html.twig' %} {% extends 'collection/collection_entry_view.html.twig' %}
{% block collection_items %} {% block collection_items %}
{% for key, attachment in attachments %} {% for key, attachment in attachments %}

View File

@ -28,7 +28,7 @@ use function App\Core\I18n\_m;
use App\Entity\Actor; use App\Entity\Actor;
use App\Util\Exception\BugFoundException; use App\Util\Exception\BugFoundException;
use App\Util\Exception\ClientException; use App\Util\Exception\ClientException;
use Component\Feed\Util\FeedController; use Component\Collection\Util\Controller\CircleController;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
class Directory extends FeedController class Directory extends FeedController
@ -144,7 +144,7 @@ class Directory extends FeedController
} }
return [ return [
'_template' => 'directory/actors.html.twig', '_template' => 'collection/actors.html.twig',
'actors' => $query_fn($actor_type), 'actors' => $query_fn($actor_type),
'title' => $title, 'title' => $title,
'empty_message' => $empty_message, 'empty_message' => $empty_message,

View File

@ -35,7 +35,7 @@ use App\Util\Exception\NoLoggedInUser;
use App\Util\Exception\NoSuchNoteException; use App\Util\Exception\NoSuchNoteException;
use App\Util\Exception\RedirectException; use App\Util\Exception\RedirectException;
use App\Util\Exception\ServerException; use App\Util\Exception\ServerException;
use Component\Feed\Util\FeedController; use Component\Collection\Util\Controller\FeedController;
use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
@ -174,7 +174,7 @@ class Favourite extends FeedController
); );
return [ return [
'_template' => 'feed/feed.html.twig', '_template' => 'collection/notes.html.twig',
'page_title' => 'Favourites feed.', 'page_title' => 'Favourites feed.',
'notes' => $notes, 'notes' => $notes,
]; ];
@ -207,7 +207,7 @@ class Favourite extends FeedController
); );
return [ return [
'_template' => 'feed/feed.html.twig', '_template' => 'collection/notes.html.twig',
'page_title' => 'Reverse favourites feed.', 'page_title' => 'Reverse favourites feed.',
'notes' => $notes, 'notes' => $notes,
]; ];

View File

@ -43,6 +43,7 @@ use App\Util\Functional as GSF;
use Functional as F; use Functional as F;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
// TODO: Migrate this to query filters
class NoteTypeFeedFilter extends Plugin class NoteTypeFeedFilter extends Plugin
{ {
public const ALLOWED_TYPES = ['media', 'link', 'text', 'tag']; public const ALLOWED_TYPES = ['media', 'link', 'text', 'tag'];

View File

@ -23,12 +23,14 @@ declare(strict_types = 1);
namespace App\Controller; namespace App\Controller;
use App\Core\Controller\ActorController;
use App\Entity as E; use App\Entity as E;
use Component\Collection\Util\ActorControllerTrait;
use Component\Collection\Util\Controller\FeedController;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
class Actor extends ActorController class ActorFeed extends FeedController
{ {
use ActorControllerTrait;
public function actorViewId(Request $request, int $id) public function actorViewId(Request $request, int $id)
{ {
return $this->handleActorById( return $this->handleActorById(

View File

@ -163,7 +163,7 @@ class Security extends Controller
$actor, $actor,
$user, $user,
function (int $id) use ($user) { function (int $id) use ($user) {
// Self subscription // Self subscription for the Home feed and alike
DB::persist(Subscription::create(['subscriber_id' => $id, 'subscribed_id' => $id])); DB::persist(Subscription::create(['subscriber_id' => $id, 'subscribed_id' => $id]));
Feed::createDefaultFeeds($id, $user); Feed::createDefaultFeeds($id, $user);
}, },

View File

@ -39,7 +39,7 @@ use App\Util\Exception\BugFoundException;
use App\Util\Exception\ClientException; use App\Util\Exception\ClientException;
use App\Util\Exception\RedirectException; use App\Util\Exception\RedirectException;
use App\Util\Exception\ServerException; use App\Util\Exception\ServerException;
use Component\Feed\Util\FeedController; use Component\Collection\Util\Controller\FeedController;
use Exception; use Exception;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;

View File

@ -45,7 +45,7 @@ abstract class Actor
public static function load(RouteLoader $r): void public static function load(RouteLoader $r): void
{ {
$r->connect(id: 'actor_view_id', uri_path: '/actor/{id<\d+>}', target: [C\Actor::class, 'actorViewId']); $r->connect(id: 'actor_view_id', uri_path: '/actor/{id<\d+>}', target: [C\ActorFeed::class, 'actorViewId']);
$r->connect(id: 'actor_view_nickname', uri_path: '/@{nickname<' . Nickname::DISPLAY_FMT . '>}', target: [C\Actor::class, 'actorViewNickname'], options: ['is_system_path' => false]); $r->connect(id: 'actor_view_nickname', uri_path: '/@{nickname<' . Nickname::DISPLAY_FMT . '>}', target: [C\ActorFeed::class, 'actorViewNickname'], options: ['is_system_path' => false]);
} }
} }

View File

@ -1,4 +1,4 @@
{% extends 'feed/feed.html.twig' %} {% extends 'collection/notes.html.twig' %}
{% block title %}{% trans %}%nickname%'s profile{% endtrans %}{% endblock %} {% block title %}{% trans %}%nickname%'s profile{% endtrans %}{% endblock %}

View File

@ -78,7 +78,7 @@ class FeedsTest extends GNUsocialTestCase
static::assertThrows(ClientException::class, fn () => $feeds->home($req)); static::assertThrows(ClientException::class, fn () => $feeds->home($req));
} }
$result = $feeds->{$route}($req, ...$extra_args); $result = $feeds->{$route}($req, ...$extra_args);
static::assertSame($result['_template'], 'feed/feed.html.twig'); static::assertSame($result['_template'], 'collection/notes.html.twig');
foreach ($result['notes'] as $n) { foreach ($result['notes'] as $n) {
static::assertIsArray($n['replies']); static::assertIsArray($n['replies']);
} }