diff --git a/plugins/Pinboard/Pinboard.php b/plugins/Pinboard/Pinboard.php index 29bf6a66c3..562ef5f289 100644 --- a/plugins/Pinboard/Pinboard.php +++ b/plugins/Pinboard/Pinboard.php @@ -35,7 +35,10 @@ namespace Plugin\Pinboard; use App\Core\Event; use App\Core\Modules\Plugin; use App\Core\Router; +use App\Entity\Actor; +use App\Entity\LocalUser; use Plugin\Pinboard\Controller as C; +use Plugin\Pinboard\Entity\Token; use Symfony\Component\HttpFoundation\Request; class Pinboard extends Plugin @@ -102,4 +105,17 @@ class Pinboard extends Plugin } return Event::next; } + + public function onActorFormInvalidateRelated(Actor $actor, ?LocalUser $user) + { + $user ??= $actor->getLocal(); + if (!$user instanceof LocalUser) { + return Event::next; + } + Cache::delete(Token::cacheKeys($user->getNickname())['user-token']); + DB::remove(DB::refetch(Token::get(nickname: null, token: null, user: $user))); + DB::flush(); + // TODO notify user that their token got invalidated + return Event::next; + } } diff --git a/src/Util/Form/ActorForms.php b/src/Util/Form/ActorForms.php index 3523237d60..f26face835 100644 --- a/src/Util/Form/ActorForms.php +++ b/src/Util/Form/ActorForms.php @@ -35,6 +35,7 @@ declare(strict_types = 1); namespace App\Util\Form; use App\Core\Cache; +use App\Core\Event; use App\Core\Form; use function App\Core\I18n\_m; use App\Entity\Actor; @@ -116,10 +117,11 @@ class ActorForms } // Delete related cache - $cache_keys = Actor::cacheKeys($target->getId()); - foreach (['id', 'nickname', 'fullname'] as $key) { - Cache::delete($cache_keys[$key]); + $cache_keys = array_intersect(Actor::cacheKeys($target->getId()), array_flip(['id', 'nickname', 'fullname'])); + foreach ($cache_keys as $key) { + Cache::delete($key); } + Event::handle('ActorFormInvalidateRelated', [$target, $local]); }; return Form::handle(