[COMPONENT][Notification] Introduce Notifications Feed

This commit is contained in:
Diogo Peralta Cordeiro 2021-12-23 13:18:50 +00:00
parent 2004f1883a
commit e743a17883
Signed by: diogo
GPG Key ID: 18D2D35001FBFAB0
2 changed files with 91 additions and 7 deletions

View File

@ -0,0 +1,66 @@
<?php
declare(strict_types = 1);
// {{{ License
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
// }}}
/**
* 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,
];
}
}

View File

@ -21,15 +21,39 @@ declare(strict_types=1);
namespace Component\Notification;
use App\Core\DB\DB;
use App\Core\Event;
use function App\Core\I18n\_m;
use App\Core\Log;
use App\Core\Modules\Component;
use App\Core\Router\RouteLoader;
use App\Core\Router\Router;
use App\Entity\Activity;
use App\Entity\Actor;
use App\Entity\LocalUser;
use Component\FreeNetwork\FreeNetwork;
use Component\Notification\Controller\Feed;
class Notification extends Component
{
public function onAddRoute(RouteLoader $m): bool
{
$m->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
{