Compare commits
2 Commits
07b65584ff
...
f5fc7b6cd1
Author | SHA1 | Date |
---|---|---|
Hugo Sales | f5fc7b6cd1 | |
Hugo Sales | 141c5f6785 |
|
@ -5,7 +5,12 @@ declare(strict_types = 1);
|
||||||
namespace Component\Collection\Util\Controller;
|
namespace Component\Collection\Util\Controller;
|
||||||
|
|
||||||
use App\Core\Controller;
|
use App\Core\Controller;
|
||||||
|
use Component\Feed\Feed;
|
||||||
|
|
||||||
class Collection extends Controller
|
class Collection extends Controller
|
||||||
{
|
{
|
||||||
|
public function query(string $query, ?string $language = null, ?Actor $actor = null)
|
||||||
|
{
|
||||||
|
return Feed::query($query, $this->int('page') ?? 1, $language, $actor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,6 @@ use App\Util\Common;
|
||||||
use App\Util\Exception\RedirectException;
|
use App\Util\Exception\RedirectException;
|
||||||
use Component\Collection\Util\Controller\FeedController;
|
use Component\Collection\Util\Controller\FeedController;
|
||||||
use Component\Conversation\Entity\ConversationMute;
|
use Component\Conversation\Entity\ConversationMute;
|
||||||
use Component\Feed\Feed;
|
|
||||||
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;
|
||||||
|
|
||||||
|
@ -47,7 +46,7 @@ class Conversation extends FeedController
|
||||||
*/
|
*/
|
||||||
public function showConversation(Request $request, int $conversation_id)
|
public function showConversation(Request $request, int $conversation_id)
|
||||||
{
|
{
|
||||||
$data = Feed::query(query: "note-conversation:{$conversation_id}", page: $this->int('p') ?? 1);
|
$data = $this->query(query: "note-conversation:{$conversation_id}");
|
||||||
$notes = $data['notes'];
|
$notes = $data['notes'];
|
||||||
return [
|
return [
|
||||||
'_template' => 'collection/notes.html.twig',
|
'_template' => 'collection/notes.html.twig',
|
||||||
|
|
|
@ -59,7 +59,7 @@ class Reply extends FeedController
|
||||||
}
|
}
|
||||||
|
|
||||||
$conversation_id = $note->getConversationId();
|
$conversation_id = $note->getConversationId();
|
||||||
$data = Feed::query(query: "note-conversation:{$conversation_id}", page: $this->int('p') ?? 1);
|
$data = $this->query(query: "note-conversation:{$conversation_id}");
|
||||||
$notes = $data['notes'];
|
$notes = $data['notes'];
|
||||||
return [
|
return [
|
||||||
'_template' => 'collection/notes.html.twig',
|
'_template' => 'collection/notes.html.twig',
|
||||||
|
|
|
@ -38,7 +38,6 @@ 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\Collection\Util\Controller\FeedController;
|
||||||
use Component\Feed\Feed;
|
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
class Feeds extends FeedController
|
class Feeds extends FeedController
|
||||||
|
@ -48,9 +47,8 @@ class Feeds extends FeedController
|
||||||
*/
|
*/
|
||||||
public function public(Request $request): array
|
public function public(Request $request): array
|
||||||
{
|
{
|
||||||
$data = Feed::query(
|
$data = $this->query(
|
||||||
query: 'note-local:true',
|
query: 'note-local:true',
|
||||||
page: $this->int('p'),
|
|
||||||
language: Common::actor()?->getTopLanguage()?->getLocale(),
|
language: Common::actor()?->getTopLanguage()?->getLocale(),
|
||||||
);
|
);
|
||||||
return [
|
return [
|
||||||
|
@ -67,9 +65,8 @@ class Feeds extends FeedController
|
||||||
{
|
{
|
||||||
$user = Common::ensureLoggedIn();
|
$user = Common::ensureLoggedIn();
|
||||||
$actor = $user->getActor();
|
$actor = $user->getActor();
|
||||||
$data = Feed::query(
|
$data = $this->query(
|
||||||
query: 'note-from:subscribed-person,subscribed-group,subscribed-organization,subscribed-business',
|
query: 'note-from:subscribed-person,subscribed-group,subscribed-organization,subscribed-business',
|
||||||
page: $this->int('p'),
|
|
||||||
language: $actor->getTopLanguage()->getLocale(),
|
language: $actor->getTopLanguage()->getLocale(),
|
||||||
actor: $actor,
|
actor: $actor,
|
||||||
);
|
);
|
||||||
|
|
|
@ -38,7 +38,6 @@ 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\Collection\Util\Controller\FeedController;
|
||||||
use Component\Feed\Feed;
|
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
class Feeds extends FeedController
|
class Feeds extends FeedController
|
||||||
|
@ -52,9 +51,8 @@ class Feeds extends FeedController
|
||||||
public function network(Request $request): array
|
public function network(Request $request): array
|
||||||
{
|
{
|
||||||
Common::ensureLoggedIn();
|
Common::ensureLoggedIn();
|
||||||
$data = Feed::query(
|
$data = $this->query(
|
||||||
query: 'note-local:false',
|
query: 'note-local:false',
|
||||||
page: $this->int('p'),
|
|
||||||
language: Common::actor()?->getTopLanguage()?->getLocale(),
|
language: Common::actor()?->getTopLanguage()?->getLocale(),
|
||||||
);
|
);
|
||||||
return [
|
return [
|
||||||
|
@ -101,9 +99,8 @@ class Feeds extends FeedController
|
||||||
public function federated(Request $request): array
|
public function federated(Request $request): array
|
||||||
{
|
{
|
||||||
Common::ensureLoggedIn();
|
Common::ensureLoggedIn();
|
||||||
$data = Feed::query(
|
$data = $this->query(
|
||||||
query: '',
|
query: '',
|
||||||
page: $this->int('p'),
|
|
||||||
language: Common::actor()?->getTopLanguage()?->getLocale(),
|
language: Common::actor()?->getTopLanguage()?->getLocale(),
|
||||||
);
|
);
|
||||||
return [
|
return [
|
||||||
|
|
|
@ -31,7 +31,6 @@ 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\Collection\Util\Controller\FeedController;
|
||||||
use Component\Feed\Feed;
|
|
||||||
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;
|
||||||
|
@ -49,7 +48,7 @@ class Search extends FeedController
|
||||||
$language = !\is_null($actor) ? $actor->getTopLanguage()->getLocale() : null;
|
$language = !\is_null($actor) ? $actor->getTopLanguage()->getLocale() : null;
|
||||||
$q = $this->string('q');
|
$q = $this->string('q');
|
||||||
|
|
||||||
$data = Feed::query(query: $q, page: $this->int('p'), language: $language);
|
$data = $this->query(query: $q, language: $language);
|
||||||
$notes = $data['notes'];
|
$notes = $data['notes'];
|
||||||
$actors = $data['actors'];
|
$actors = $data['actors'];
|
||||||
|
|
||||||
|
|
|
@ -53,6 +53,7 @@ use Symfony\Component\HttpKernel\Event\ExceptionEvent;
|
||||||
use Symfony\Component\HttpKernel\Event\ViewEvent;
|
use Symfony\Component\HttpKernel\Event\ViewEvent;
|
||||||
use Symfony\Component\HttpKernel\KernelEvents;
|
use Symfony\Component\HttpKernel\KernelEvents;
|
||||||
use Symfony\Component\Validator\Exception\ValidatorException;
|
use Symfony\Component\Validator\Exception\ValidatorException;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method ?int int(string $param)
|
* @method ?int int(string $param)
|
||||||
|
@ -242,11 +243,21 @@ abstract class Controller extends AbstractController implements EventSubscriberI
|
||||||
{
|
{
|
||||||
switch ($method) {
|
switch ($method) {
|
||||||
case 'int':
|
case 'int':
|
||||||
return !$this->request->query->has($args[0]) ? null : $this->request->query->getInt($args[0]);
|
|
||||||
case 'bool':
|
case 'bool':
|
||||||
return !$this->request->query->has($args[0]) ? null : $this->request->query->getBoolean($args[0]);
|
|
||||||
case 'string':
|
case 'string':
|
||||||
return !$this->request->query->has($args[0]) ? null : $this->request->query->get($args[0]);
|
if ($this->request->query->has($args[0])) {
|
||||||
|
return match ($method) {
|
||||||
|
'int' => $this->request->query->getInt($args[0]),
|
||||||
|
'bool' => $this->request->query->getBoolean($args[0]),
|
||||||
|
'string' => $this->request->query->get($args[0]),
|
||||||
|
default => throw new BugFoundException('Inconsistent switch/match spotted'),
|
||||||
|
};
|
||||||
|
} elseif (\array_key_exists(1, $args) && $args[1] instanceof Throwable) {
|
||||||
|
throw $args[1];
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 'params':
|
case 'params':
|
||||||
return $this->request->query->all();
|
return $this->request->query->all();
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in New Issue