diff --git a/components/Notification/Controller/Feed.php b/components/Notification/Controller/Feed.php new file mode 100644 index 0000000000..87695d61b5 --- /dev/null +++ b/components/Notification/Controller/Feed.php @@ -0,0 +1,66 @@ +. + +// }}} + +/** + * Handle network public feed + * + * @package GNUsocial + * @category Controller + * + * @author Diogo Peralta Cordeiro <@diogo.site> + * @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 Component\Notification\Controller; + +use App\Core\Controller; +use App\Core\DB\DB; +use function App\Core\I18n\_m; +use App\Util\Common; +use Symfony\Component\HttpFoundation\Request; + +class Feed extends Controller +{ + /** + * Everything with attention to current user + */ + public function notifications(Request $request): array + { + $user = Common::user(); + $notes = DB::dql(<<<'EOF' + SELECT n FROM \App\Entity\Note AS n + WHERE n.id IN ( + SELECT act.object_id FROM \App\Entity\Activity AS act + WHERE act.object_type = 'note' AND act.id IN + (SELECT att.activity_id FROM \Component\Notification\Entity\Notification AS att WHERE att.target_id = :id) + ) + EOF, ['id' => $user->getId()]); + return [ + '_template' => 'feed/feed.html.twig', + 'page_title' => _m('Notifications'), + 'should_format' => true, + 'notes' => $notes, + ]; + } +} diff --git a/components/Notification/Notification.php b/components/Notification/Notification.php index 8c0991c6e5..371f036b40 100644 --- a/components/Notification/Notification.php +++ b/components/Notification/Notification.php @@ -1,6 +1,6 @@ connect('feed_notifications', '/feed/notifications', [Feed::class, 'notifications']); + return Event::next; + } + + public function onCreateDefaultFeeds(int $actor_id, LocalUser $user, int &$ordering) + { + DB::persist(\App\Entity\Feed::create([ + 'actor_id' => $actor_id, + 'url' => Router::url($route = 'feed_notifications', ['nickname' => $user->getNickname()]), + 'route' => $route, + 'title' => _m('Notifications'), + 'ordering' => $ordering++, + ])); + return Event::next; + } + /** * Enqueues a notification for an Actor (user or group) which means * it shows up in their home feed and such. @@ -44,12 +68,6 @@ class Notification extends Component /** * Bring given Activity to Targets's attention - * - * @param Actor $sender - * @param Activity $activity - * @param array $targets - * @param string|null $reason - * @return bool */ public function notify(Actor $sender, Activity $activity, array $targets, ?string $reason = null): bool {