[COMPONENT][Feed] Refactor Feed component

This commit is contained in:
Hugo Sales 2021-12-29 13:26:11 +00:00
parent f16df759a9
commit cbb70a5054
Signed by untrusted user: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
4 changed files with 16 additions and 8 deletions

View File

@ -33,7 +33,7 @@ declare(strict_types = 1);
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
namespace App\Controller;
namespace Component\Feed\Controller;
use function App\Core\I18n\_m;
use App\Util\Common;
@ -65,12 +65,13 @@ class Feeds extends FeedController
*/
public function home(Request $request): array
{
Common::ensureLoggedIn();
$data = Feed::query(
$user = Common::ensureLoggedIn();
$actor = $user->getActor();
$data = Feed::query(
query: 'note-from:subscribed-person,subscribed-group,subscribed-organization,subscribed-business',
page: $this->int('p'),
language: Common::actor()?->getTopLanguage()?->getLocale(),
actor: Common::actor(),
language: $actor?->getTopLanguage()?->getLocale(),
actor: $actor,
);
return [
'_template' => 'feed/feed.html.twig',

View File

@ -26,9 +26,11 @@ namespace Component\Feed;
use App\Core\DB\DB;
use App\Core\Event;
use App\Core\Modules\Component;
use App\Core\Router\RouteLoader;
use App\Entity\Actor;
use App\Entity\Subscription;
use App\Util\Formatting;
use Component\Feed\Controller as C;
use Component\Search\Util\Parser;
use Doctrine\Common\Collections\ExpressionBuilder;
use Doctrine\ORM\Query\Expr;
@ -36,6 +38,13 @@ use Doctrine\ORM\QueryBuilder;
class Feed extends Component
{
public function onAddRoute(RouteLoader $r): bool
{
$r->connect('feed_public', '/feed/public', [C\Feeds::class, 'public']);
$r->connect('feed_home', '/feed/home', [C\Feeds::class, 'home']);
return Event::next;
}
/**
* Perform a high level query on notes or actors
*

View File

@ -152,7 +152,7 @@ class Feed extends Entity
public static function createDefaultFeeds(int $actor_id, LocalUser $user): void
{
$ordering = 1;
DB::persist(self::create(['actor_id' => $actor_id, 'url' => Router::url($route = 'feed_home', ['nickname' => $user->getNickname()]), 'route' => $route, 'title' => _m('Home'), 'ordering' => $ordering++]));
DB::persist(self::create(['actor_id' => $actor_id, 'url' => Router::url($route = 'feed_home'), 'route' => $route, 'title' => _m('Home'), 'ordering' => $ordering++]));
DB::persist(self::create(['actor_id' => $actor_id, 'url' => Router::url($route = 'feed_public'), 'route' => $route, 'title' => _m('Planet'), 'ordering' => $ordering++]));
Event::handle('CreateDefaultFeeds', [$actor_id, $user, &$ordering]);
}

View File

@ -54,8 +54,6 @@ abstract class Main
$r->connect('security_recover_password_token', '/main/recover-password/{token?}', [C\ResetPassword::class, 'reset']);
$r->connect('root', '/', RedirectController::class, ['defaults' => ['route' => 'feed_public']]);
$r->connect('feed_public', '/feed/public', [C\Feeds::class, 'public']);
$r->connect('feed_home', '/feed/home', [C\Feeds::class, 'home']);
$r->connect('panel', '/panel', [C\AdminPanel::class, 'site']);
$r->connect('panel_site', '/panel/site', [C\AdminPanel::class, 'site']);