[CONTROLLER][Feeds][EVENT] Refactor and add 'FilterNoteList' event

This commit is contained in:
Hugo Sales 2021-12-04 13:08:33 +00:00
parent 2f5bde913c
commit 8a495bd714
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
1 changed files with 26 additions and 20 deletions

View File

@ -41,6 +41,7 @@ use App\Core\Event;
use function App\Core\I18n\_m; use function App\Core\I18n\_m;
use App\Core\VisibilityScope; use App\Core\VisibilityScope;
use App\Entity\Note; use App\Entity\Note;
use App\Util\Common;
use App\Util\Exception\ClientException; use App\Util\Exception\ClientException;
use App\Util\Exception\NotFoundException; use App\Util\Exception\NotFoundException;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
@ -53,20 +54,34 @@ class Feeds extends Controller
private $message_scope = VisibilityScope::MESSAGE; private $message_scope = VisibilityScope::MESSAGE;
private $subscriber_scope = VisibilityScope::PUBLIC | VisibilityScope::SUBSCRIBER; private $subscriber_scope = VisibilityScope::PUBLIC | VisibilityScope::SUBSCRIBER;
public function public(Request $request) private function feed(string $title, array $notes)
{ {
$notes = Note::getAllNotes($this->instance_scope); $actor = Common::actor();
if (!\is_null($actor)) {
$notes_out = null;
Event::handle('FilterNoteList', [$actor, $notes, &$notes_out]);
$notes = $notes_out;
}
$notes_out = null; $notes_out = null;
Event::handle('FormatNoteList', [$notes, &$notes_out]); Event::handle('FormatNoteList', [$notes, &$notes_out]);
return [ return [
'_template' => 'feeds/feed.html.twig', '_template' => 'feeds/feed.html.twig',
'page_title' => $title,
'notes' => $notes_out, 'notes' => $notes_out,
'page_title' => 'Public feed',
]; ];
} }
public function public(Request $request)
{
$notes = Note::getAllNotes($this->instance_scope);
return $this->feed(
title: 'Public feed',
notes: $notes,
);
}
public function home(Request $request, string $nickname) public function home(Request $request, string $nickname)
{ {
try { try {
@ -102,27 +117,18 @@ class Feeds extends Controller
END; END;
$notes = DB::sql($query, ['target_actor_id' => $target->getId()]); $notes = DB::sql($query, ['target_actor_id' => $target->getId()]);
$notes_out = null; return $this->feed(
Event::handle('FormatNoteList', [$notes, &$notes_out]); title: 'Home feed',
notes: $notes,
return [ );
'_template' => 'feeds/feed.html.twig',
'notes' => $notes_out,
'page_title' => 'Home feed',
];
} }
public function network(Request $request) public function network(Request $request)
{ {
$notes = Note::getAllNotes($this->public_scope); $notes = Note::getAllNotes($this->public_scope);
return $this->feed(
$notes_out = null; title: 'Network feed',
Event::handle('FormatNoteList', [$notes, &$notes_out]); notes: $notes,
);
return [
'_template' => 'feeds/feed.html.twig',
'notes' => $notes_out,
'page_title' => 'Network feed',
];
} }
} }