[PLUGIN][TagBasedFiltering] Block actor tags, but don't block notes from the current actor

This commit is contained in:
Hugo Sales 2021-12-05 18:34:33 +00:00
parent 259e07b259
commit 2a161c9c66
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
4 changed files with 30 additions and 5 deletions

View File

@ -48,6 +48,9 @@ use Symfony\Component\HttpFoundation\Request;
class TagBasedFiltering extends Controller 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( private function editBlocked(
Request $request, Request $request,
?int $id, ?int $id,

View File

@ -31,6 +31,8 @@ use App\Core\Modules\Plugin;
use App\Core\Router\RouteLoader; use App\Core\Router\RouteLoader;
use App\Core\Router\Router; use App\Core\Router\Router;
use App\Entity\Actor; use App\Entity\Actor;
use App\Entity\ActorTag;
use App\Entity\ActorTagBlock;
use App\Entity\LocalUser; use App\Entity\LocalUser;
use App\Entity\Note; use App\Entity\Note;
use App\Entity\NoteTag; use App\Entity\NoteTag;
@ -79,13 +81,28 @@ class TagBasedFiltering extends Plugin
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()]),
); );
$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_out = F\reject(
$notes, $notes,
fn (Note $n) => F\some( fn (Note $n) => (
dump(NoteTag::getByNoteId($n->getId())), $n->getActor()->getId() != $actor->getId()
&& (
F\some(
NoteTag::getByNoteId($n->getId()),
fn ($nt) => NoteTagBlock::checkBlocksNoteTag($nt, $blocked_note_tags), 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; return Event::next;
} }
} }

View File

@ -367,12 +367,12 @@ class Actor extends Entity
foreach ($tags_to_add as $tag) { foreach ($tags_to_add as $tag) {
$canonical_tag = TagComponent::canonicalTag($tag, $this->getTopLanguage()->getLocale()); $canonical_tag = TagComponent::canonicalTag($tag, $this->getTopLanguage()->getLocale());
DB::persist(ActorCircle::create(['tagger' => $this->getId(), 'tag' => $canonical_tag, 'private' => false])); 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) { foreach ($actor_tags_to_remove as $actor_tag) {
$canonical_tag = TagComponent::canonicalTag($actor_tag->getTag(), $this->getTopLanguage()->getLocale()); $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_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("selftags-{$this->getId()}");
Cache::delete("othertags-{$this->getId()}-by-{$this->getId()}"); Cache::delete("othertags-{$this->getId()}-by-{$this->getId()}");

View File

@ -164,4 +164,9 @@ class ActorTag extends Entity
], ],
]; ];
} }
public function __toString(): string
{
return $this->getTag();
}
} }