[CORE] Add option to filter notes even when there's no actor

This commit is contained in:
Phablulo 2021-12-21 10:34:04 -03:00
parent ce91826d31
commit dd5d46c556
4 changed files with 7 additions and 6 deletions

View File

@ -29,14 +29,16 @@ use App\Entity\Note;
use App\Util\Formatting; use App\Util\Formatting;
use App\Util\Functional as GSF; use App\Util\Functional as GSF;
use Doctrine\Common\Collections\ExpressionBuilder; use Doctrine\Common\Collections\ExpressionBuilder;
use Symfony\Component\HttpFoundation\Request;
use Doctrine\ORM\Query\Expr; use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Functional as F; use Functional as F;
class Language extends Component class Language extends Component
{ {
public function onFilterNoteList(Actor $actor, array &$notes) public function onFilterNoteList(?Actor $actor, array &$notes, Request $request)
{ {
if (\is_null($actor)) return Event::next;
$notes = F\select( $notes = F\select(
$notes, $notes,
fn (Note $n) => \in_array($n->getLanguageId(), ActorLanguage::getActorRelatedLanguagesIds($actor)), fn (Note $n) => \in_array($n->getLanguageId(), ActorLanguage::getActorRelatedLanguagesIds($actor)),

View File

@ -76,8 +76,9 @@ class TagBasedFiltering extends Plugin
]; ];
} }
public function onFilterNoteList(Actor $actor, array &$notes) public function onFilterNoteList(?Actor $actor, array &$notes, Request $request)
{ {
if (\is_null($actor)) return Event::next;
$blocked_note_tags = Cache::get( $blocked_note_tags = Cache::get(
self::cacheKeys($actor)['note'], self::cacheKeys($actor)['note'],
fn () => DB::dql('select ntb from note_tag_block ntb where ntb.blocker = :blocker', ['blocker' => $actor->getId()]), fn () => DB::dql('select ntb from note_tag_block ntb where ntb.blocker = :blocker', ['blocker' => $actor->getId()]),

View File

@ -49,9 +49,7 @@ abstract class FeedController extends Controller
if (\array_key_exists('notes', $result)) { if (\array_key_exists('notes', $result)) {
$notes = $result['notes']; $notes = $result['notes'];
if (!\is_null($actor)) { Event::handle('FilterNoteList', [$actor, &$notes, $result['request']]);
Event::handle('FilterNoteList', [$actor, &$notes]);
}
if ($result['should_format'] ?? true) { if ($result['should_format'] ?? true) {
$notes_out = null; $notes_out = null;

View File

@ -9,7 +9,7 @@
{% endblock stylesheets %} {% endblock stylesheets %}
{% block body %} {% block body %}
{% for block in handle_event('BeforeFeed') %} {% for block in handle_event('BeforeFeed', app.request) %}
{{ block | raw }} {{ block | raw }}
{% endfor %} {% endfor %}
{# Backwards compatibility with hAtom 0.1 #} {# Backwards compatibility with hAtom 0.1 #}