diff --git a/src/Controller/Network.php b/src/Controller/Network.php index 16a6d70a23..06d8297a69 100644 --- a/src/Controller/Network.php +++ b/src/Controller/Network.php @@ -33,29 +33,67 @@ namespace App\Controller; use App\Core\Controller; use App\Core\DB\DB; +use function App\Core\I18n\_m; +use App\Core\NoteScope; use App\Util\Common; +use App\Util\Exception\ClientException; use Symfony\Component\HttpFoundation\Request; class Network extends Controller { + // Can't have constanst inside herestring + private $public_scope = NoteScope::PUBLIC; + private $instance_scope = NoteScope::PUBLIC | NoteScope::SITE; + private $message_scope = NoteScope::MESSAGE; + private $follower_scope = NoteScope::PUBLIC | NoteScope::FOLLOWER; + public function public(Request $request) { return [ '_template' => 'network/public.html.twig', - 'notes' => DB::dql('select n from App\Entity\Note n ' . - 'where n.reply_to is null order by n.created DESC'), + 'notes' => DB::sql('select * from note n ' . + "where n.reply_to is null and (n.scope & {$this->instance_scope}) <> 0 " . + 'order by n.created DESC', + ['n' => 'App\Entity\Note']), ]; } - public function home(Request $request) + public function home(Request $request, string $nickname) { + $target = DB::findOneBy('gsactor', ['nickname' => $nickname]); + if ($target == null) { + 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()]); + return [ '_template' => 'network/public.html.twig', - 'notes' => DB::dql('select n, g_inbox, g_member ' . - 'from App\Entity\Note n inner join App\Entity\GroupInbox g_inbox inner join App\Entity\GroupMember g_member ' . - 'with n.id = g_inbox.activity_id ' . - 'order by n.created DESC' - ), + 'notes' => $notes, ]; } @@ -64,8 +102,8 @@ class Network extends Controller return [ '_template' => 'network/public.html.twig', 'notes' => DB::dql('select n from App\Entity\Note n ' . - 'where n.scope = 1 ' . - 'order by n.created DESC' + "where n.scope = {$this->public_scope} " . + 'order by n.created DESC' ), ]; }