[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 untrusted user: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0

View File

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