diff --git a/plugins/TagBasedFiltering/Controller/TagBasedFiltering.php b/plugins/TagBasedFiltering/Controller/TagBasedFiltering.php index 3bd523ee70..b5dfbd76d4 100644 --- a/plugins/TagBasedFiltering/Controller/TagBasedFiltering.php +++ b/plugins/TagBasedFiltering/Controller/TagBasedFiltering.php @@ -48,6 +48,9 @@ use Symfony\Component\HttpFoundation\Request; class TagBasedFiltering extends Controller { + /** + * Edit the blocked tags of $type_name for target with ID $id. Handles both actor and note tags + */ private function editBlocked( Request $request, ?int $id, diff --git a/plugins/TagBasedFiltering/TagBasedFiltering.php b/plugins/TagBasedFiltering/TagBasedFiltering.php index a476fc6005..673af0bf48 100644 --- a/plugins/TagBasedFiltering/TagBasedFiltering.php +++ b/plugins/TagBasedFiltering/TagBasedFiltering.php @@ -31,6 +31,8 @@ use App\Core\Modules\Plugin; use App\Core\Router\RouteLoader; use App\Core\Router\Router; use App\Entity\Actor; +use App\Entity\ActorTag; +use App\Entity\ActorTagBlock; use App\Entity\LocalUser; use App\Entity\Note; use App\Entity\NoteTag; @@ -79,13 +81,28 @@ class TagBasedFiltering extends Plugin self::cacheKeys($actor)['note'], fn () => DB::dql('select ntb from note_tag_block ntb where ntb.blocker = :blocker', ['blocker' => $actor->getId()]), ); + $blocked_actor_tags = Cache::get( + self::cacheKeys($actor)['actor'], + fn () => DB::dql('select atb from actor_tag_block atb where atb.blocker = :blocker', ['blocker' => $actor->getId()]), + ); + $notes_out = F\reject( $notes, - fn (Note $n) => F\some( - dump(NoteTag::getByNoteId($n->getId())), - fn ($nt) => NoteTagBlock::checkBlocksNoteTag($nt, $blocked_note_tags), + fn (Note $n) => ( + $n->getActor()->getId() != $actor->getId() + && ( + F\some( + NoteTag::getByNoteId($n->getId()), + fn ($nt) => NoteTagBlock::checkBlocksNoteTag($nt, $blocked_note_tags), + ) + || F\some( + ActorTag::getByActorId($n->getActor()->getId()), + fn ($at) => ActorTagBlock::checkBlocksActorTag($at, $blocked_actor_tags), + ) + ) ), ); + return Event::next; } } diff --git a/src/Entity/Actor.php b/src/Entity/Actor.php index 5e66c55e10..13820c1af1 100644 --- a/src/Entity/Actor.php +++ b/src/Entity/Actor.php @@ -367,12 +367,12 @@ class Actor extends Entity foreach ($tags_to_add as $tag) { $canonical_tag = TagComponent::canonicalTag($tag, $this->getTopLanguage()->getLocale()); DB::persist(ActorCircle::create(['tagger' => $this->getId(), 'tag' => $canonical_tag, 'private' => false])); - DB::persist(ActorTag::create(['tagger' => $this->id, 'tagged' => $this->id, 'tag' => $tag, 'canonical' => $canonical_tag])); + DB::persist(ActorTag::create(['tagger' => $this->id, 'tagged' => $this->id, 'tag' => $tag, 'canonical' => $canonical_tag, 'use_canonical' => true])); // TODO make use canonical configurable } foreach ($actor_tags_to_remove as $actor_tag) { $canonical_tag = TagComponent::canonicalTag($actor_tag->getTag(), $this->getTopLanguage()->getLocale()); DB::removeBy('actor_tag', ['tagger' => $this->getId(), 'tagged' => $this->getId(), 'canonical' => $canonical_tag]); - DB::removeBy('actor_circle', ['tagger' => $this->getId(), 'tag' => $canonical_tag]); + DB::removeBy('actor_circle', ['tagger' => $this->getId(), 'tag' => $canonical_tag]); // TODO only remove if unused } Cache::delete("selftags-{$this->getId()}"); Cache::delete("othertags-{$this->getId()}-by-{$this->getId()}"); diff --git a/src/Entity/ActorTag.php b/src/Entity/ActorTag.php index 0c367274b3..df2d5c94aa 100644 --- a/src/Entity/ActorTag.php +++ b/src/Entity/ActorTag.php @@ -164,4 +164,9 @@ class ActorTag extends Entity ], ]; } + + public function __toString(): string + { + return $this->getTag(); + } }