From 5990c58c9cc9d4b8e432872234cfd35db28c281a Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Wed, 21 Aug 2019 10:49:30 -0100 Subject: [PATCH] remove follows on deleted account Signed-off-by: Maxence Lange --- lib/Db/FollowsRequest.php | 16 +++++++++- lib/Interfaces/Activity/DeleteInterface.php | 33 ++++++++------------- lib/Interfaces/Actor/PersonInterface.php | 10 ++++++- lib/Interfaces/Object/NoteInterface.php | 10 ++++--- 4 files changed, 42 insertions(+), 27 deletions(-) diff --git a/lib/Db/FollowsRequest.php b/lib/Db/FollowsRequest.php index 77ab6894..f2256cd8 100644 --- a/lib/Db/FollowsRequest.php +++ b/lib/Db/FollowsRequest.php @@ -267,7 +267,6 @@ class FollowsRequest extends FollowsRequestBuilder { $qb->execute(); } - /** * @param Follow $follow */ @@ -279,6 +278,21 @@ class FollowsRequest extends FollowsRequestBuilder { $qb->execute(); } + /** + * @param string $actorId + */ + public function deleteRelatedId(string $actorId) { + $qb = $this->getFollowsDeleteSql(); + $this->limitToActorId($qb, $actorId); + + $qb->execute(); + + $qb = $this->getFollowsDeleteSql(); + $this->limitToFollowId($qb, $actorId); + + $qb->execute(); + } + } diff --git a/lib/Interfaces/Activity/DeleteInterface.php b/lib/Interfaces/Activity/DeleteInterface.php index f087cf97..643f6fcb 100644 --- a/lib/Interfaces/Activity/DeleteInterface.php +++ b/lib/Interfaces/Activity/DeleteInterface.php @@ -65,24 +65,18 @@ class DeleteInterface implements IActivityPubInterface { $item->checkOrigin($item->getId()); if (!$item->hasObject()) { + $types = ['Note', 'Person']; + foreach ($types as $type) { + try { + $item->checkOrigin($item->getObjectId()); - if ($item->getObjectId() !== '') { - $item->checkOrigin($item->getObjectId()); + $interface = AP::$activityPub->getInterfaceFromType($type); + $object = $interface->getItemById($item->getObjectId()); + $interface->delete($object); - // TODO: migrate to activity() !! - $types = ['Note', 'Person']; - foreach ($types as $type) { - try { - $item->checkOrigin($item->getObjectId()); - $interface = AP::$activityPub->getInterfaceFromType($type); - $object = $interface->getItemById($item->getObjectId()); - $interface->delete($object); - - return; - } catch (InvalidOriginException $e) { - } catch (ItemNotFoundException $e) { - } catch (ItemUnknownException $e) { - } + return; + } catch (ItemNotFoundException $e) { + } catch (ItemUnknownException $e) { } } @@ -91,11 +85,8 @@ class DeleteInterface implements IActivityPubInterface { $object = $item->getObject(); try { - $item->checkOrigin($object->getId()); - // FIXME: needed ? better use activity() -// $interface = AP::$activityPub->getInterfaceForItem($object); -// $interface->delete($object); - } catch (InvalidOriginException $e) { + $interface = AP::$activityPub->getInterfaceForItem($object); + $interface->activity($item, $object); } catch (ItemUnknownException $e) { } } diff --git a/lib/Interfaces/Actor/PersonInterface.php b/lib/Interfaces/Actor/PersonInterface.php index ef04c1f3..9a0f1c68 100644 --- a/lib/Interfaces/Actor/PersonInterface.php +++ b/lib/Interfaces/Actor/PersonInterface.php @@ -33,6 +33,7 @@ namespace OCA\Social\Interfaces\Actor; use daita\MySmallPhpTools\Traits\TArrayTools; use OCA\Social\Db\CacheActorsRequest; +use OCA\Social\Db\FollowsRequest; use OCA\Social\Db\StreamRequest; use OCA\Social\Exceptions\CacheActorDoesNotExistException; use OCA\Social\Exceptions\InvalidOriginException; @@ -63,6 +64,9 @@ class PersonInterface implements IActivityPubInterface { /** @var StreamRequest */ private $streamRequest; + /** @var FollowsRequest */ + private $followsRequest; + /** @var ActorService */ private $actorService; @@ -78,16 +82,19 @@ class PersonInterface implements IActivityPubInterface { * * @param CacheActorsRequest $cacheActorsRequest * @param StreamRequest $streamRequest + * @param FollowsRequest $followsRequest * @param ActorService $actorService * @param ConfigService $configService * @param MiscService $miscService */ public function __construct( CacheActorsRequest $cacheActorsRequest, StreamRequest $streamRequest, - ActorService $actorService, ConfigService $configService, MiscService $miscService + FollowsRequest $followsRequest, ActorService $actorService, ConfigService $configService, + MiscService $miscService ) { $this->cacheActorsRequest = $cacheActorsRequest; $this->streamRequest = $streamRequest; + $this->followsRequest = $followsRequest; $this->actorService = $actorService; $this->configService = $configService; $this->miscService = $miscService; @@ -180,6 +187,7 @@ class PersonInterface implements IActivityPubInterface { /** @var Person $item */ $this->cacheActorsRequest->deleteFromId($item->getId()); $this->streamRequest->deleteByAuthor($item->getId()); + $this->followsRequest->deleteRelatedId($item->getId()); } diff --git a/lib/Interfaces/Object/NoteInterface.php b/lib/Interfaces/Object/NoteInterface.php index 0da2fca8..1730cac1 100644 --- a/lib/Interfaces/Object/NoteInterface.php +++ b/lib/Interfaces/Object/NoteInterface.php @@ -38,6 +38,7 @@ use OCA\Social\Exceptions\StreamNotFoundException; use OCA\Social\Interfaces\IActivityPubInterface; use OCA\Social\Model\ActivityPub\ACore; use OCA\Social\Model\ActivityPub\Activity\Create; +use OCA\Social\Model\ActivityPub\Activity\Delete; use OCA\Social\Model\ActivityPub\Object\Note; use OCA\Social\Service\ConfigService; use OCA\Social\Service\CurlService; @@ -140,6 +141,11 @@ class NoteInterface implements IActivityPubInterface { $item->setActivityId($activity->getId()); $this->save($item); } + + if ($activity->getType() === Delete::TYPE) { + $activity->checkOrigin($item->getId()); + $this->delete($item); + } } @@ -167,12 +173,8 @@ class NoteInterface implements IActivityPubInterface { /** * @param ACore $item - * - * @throws InvalidOriginException */ public function delete(ACore $item) { - $item->checkOrigin(($item->getId())); - /** @var Note $item */ $this->streamRequest->deleteStreamById($item->getId(), Note::TYPE); }