. // }}} /** * Handle network public feed * * @package GNUsocial * @category Controller * * @author Hugo Sales * @author Eliseu Amaro * @copyright 2020-2021 Free Software Foundation, Inc http://www.fsf.org * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later */ namespace App\Controller; use App\Core\Controller; use App\Core\DB\DB; 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; class Feeds extends Controller { // Can't have constants inside herestring private $public_scope = VisibilityScope::PUBLIC; private $instance_scope = VisibilityScope::PUBLIC | VisibilityScope::SITE; private $message_scope = VisibilityScope::MESSAGE; private $subscriber_scope = VisibilityScope::PUBLIC | VisibilityScope::SUBSCRIBER; private function feed(string $title, array $notes) { $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, ]; } 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 { $target = DB::findOneBy('actor', ['nickname' => $nickname, 'is_local' => true]); } catch (NotFoundException) { throw new ClientException(_m('User {nickname} doesn\'t exist', ['{nickname}' => $nickname])); } // TODO Handle replies in home stream $query = << {$this->message_scope} order by note.modified DESC END; $notes = DB::sql($query, ['target_actor_id' => $target->getId()]); return $this->feed( title: 'Home feed', notes: $notes, ); } public function network(Request $request) { $notes = Note::getAllNotes($this->public_scope); return $this->feed( title: 'Network feed', notes: $notes, ); } }