. // }}} /** * 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 Network 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 $follower_scope = VisibilityScope::PUBLIC | VisibilityScope::FOLLOWER; public function public(Request $request) { $notes = Note::getAllNotes($this->instance_scope); $notes_out = null; Event::handle('FormatNoteList', [$notes, &$notes_out]); return [ '_template' => 'network/feed.html.twig', 'notes' => $notes_out, 'page_title' => 'Public timeline', ]; } public function home(Request $request, string $nickname) { try { $target = DB::findOneBy('actor', ['nickname' => $nickname]); } catch (NotFoundException) { throw new ClientException(_m('User {nickname} doesn\'t exist', ['{nickname}' => $nickname])); } $query = << {$this->message_scope} order by note.modified DESC END; $notes = DB::sql($query, ['note' => 'App\Entity\Note'], ['target_actor_id' => $target->getId()]); $notes_out = null; Event::handle('FormatNoteList', [$notes, &$notes_out]); return [ '_template' => 'network/feed.html.twig', 'notes' => $notes_out, 'page_title' => 'Home timeline', ]; } public function network(Request $request) { $notes = Note::getAllNotes($this->public_scope); $notes_out = null; Event::handle('FormatNoteList', [$notes, &$notes_out]); return [ '_template' => 'network/feed.html.twig', 'notes' => $notes_out, 'page_title' => 'Network timeline', ]; } public function replies(Request $request) { $actor_id = Common::ensureLoggedIn()->getId(); $notes = DB::dql('select n from App\Entity\Note n ' . 'where n.reply_to is not null and n.actor_id = :id ' . 'order by n.created DESC', ['id' => $actor_id]); $notes_out = null; Event::handle('FormatNoteList', [$notes, &$notes_out]); return [ '_template' => 'network/feed.html.twig', 'notes' => $notes_out, 'page_title' => 'Replies timeline', ]; } }