forked from GNUsocial/gnu-social
[PLUGIN][TagBasedFiltering] Block actor tags, but don't block notes from the current actor
This commit is contained in:
parent
259e07b259
commit
2a161c9c66
@ -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,
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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()}");
|
||||
|
@ -164,4 +164,9 @@ class ActorTag extends Entity
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->getTag();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user