diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2018-12-27 10:04:03 -0100 |
---|---|---|
committer | Maxence Lange <maxence@artificial-owl.com> | 2018-12-27 10:04:03 -0100 |
commit | 918d595193e7529ca4d0721bd9f3d1a109c66d16 (patch) | |
tree | ced5c9dfcc1f2b8629640b2468f8dcea3460432f | |
parent | 4342d2d51e6448df639230751808c016535609b3 (diff) |
get item by Id and delete it
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
-rw-r--r-- | lib/Interfaces/Activity/DeleteInterface.php | 23 | ||||
-rw-r--r-- | lib/Interfaces/Actor/PersonInterface.php | 15 | ||||
-rw-r--r-- | lib/Interfaces/IActivityPubInterface.php | 3 | ||||
-rw-r--r-- | lib/Interfaces/Object/NoteInterface.php | 16 |
4 files changed, 44 insertions, 13 deletions
diff --git a/lib/Interfaces/Activity/DeleteInterface.php b/lib/Interfaces/Activity/DeleteInterface.php index 9938acf9..1d58c13d 100644 --- a/lib/Interfaces/Activity/DeleteInterface.php +++ b/lib/Interfaces/Activity/DeleteInterface.php @@ -32,6 +32,7 @@ namespace OCA\Social\Interfaces\Activity; use OCA\Social\AP; +use OCA\Social\Exceptions\InvalidOriginException; use OCA\Social\Exceptions\ItemNotFoundException; use OCA\Social\Exceptions\UnknownItemException; use OCA\Social\Interfaces\IActivityPubInterface; @@ -58,15 +59,29 @@ class DeleteInterface implements IActivityPubInterface { /** * @param ACore $item * - * @throws \OCA\Social\Exceptions\InvalidOriginException + * @throws InvalidOriginException */ public function processIncomingRequest(ACore $item) { $item->checkOrigin($item->getId()); if (!$item->gotObject()) { -// // TODO - manage objectId (in case object is missing) -> find the right object and delete it -// if ($item->getObjectId() !== '') { -// } + + if ($item->getObjectId() !== '') { + $item->checkOrigin($item->getObjectId()); + + $types = ['Note', 'Person']; + foreach ($types as $type) { + try { + $interface = AP::$activityPub->getInterfaceForItem($type); + $object = $interface->getItemById($item->getObjectId()); + $interface->delete($object); + + return; + } catch (UnknownItemException $e) { + } catch (ItemNotFoundException $e) { + } + } + } return; } diff --git a/lib/Interfaces/Actor/PersonInterface.php b/lib/Interfaces/Actor/PersonInterface.php index 5585ebdc..9dfe83cd 100644 --- a/lib/Interfaces/Actor/PersonInterface.php +++ b/lib/Interfaces/Actor/PersonInterface.php @@ -33,6 +33,8 @@ namespace OCA\Social\Interfaces\Actor; use daita\MySmallPhpTools\Traits\TArrayTools; use OCA\Social\Db\CacheActorsRequest; +use OCA\Social\Exceptions\CacheActorDoesNotExistException; +use OCA\Social\Exceptions\InvalidOriginException; use OCA\Social\Exceptions\ItemNotFoundException; use OCA\Social\Interfaces\IActivityPubInterface; use OCA\Social\Model\ActivityPub\ACore; @@ -107,7 +109,11 @@ class PersonInterface implements IActivityPubInterface { * @throws ItemNotFoundException */ public function getItemById(string $id): ACore { - throw new ItemNotFoundException(); + try { + return $this->cacheActorsRequest->getFromId($id); + } catch (CacheActorDoesNotExistException $e) { + throw new ItemNotFoundException(); + } } @@ -134,9 +140,16 @@ class PersonInterface implements IActivityPubInterface { /** * @param ACore $item + * + * @throws InvalidOriginException */ public function delete(ACore $item) { + $item->checkOrigin(($item->getId())); + + /** @var Person $item */ + $this->cacheActorsRequest->deleteFromId($item->getId()); } + } diff --git a/lib/Interfaces/IActivityPubInterface.php b/lib/Interfaces/IActivityPubInterface.php index c1599dbd..d0dcc4c1 100644 --- a/lib/Interfaces/IActivityPubInterface.php +++ b/lib/Interfaces/IActivityPubInterface.php @@ -31,6 +31,7 @@ declare(strict_types=1); namespace OCA\Social\Interfaces; +use OCA\Social\Exceptions\ItemNotFoundException; use OCA\Social\Model\ActivityPub\ACore; @@ -61,7 +62,7 @@ interface IActivityPubInterface { /** * @param string $id * - * @throw ItemNotFoundException + * @throws ItemNotFoundException * @return ACore */ public function getItemById(string $id): ACore; diff --git a/lib/Interfaces/Object/NoteInterface.php b/lib/Interfaces/Object/NoteInterface.php index 6abf1f43..7c4b7ae7 100644 --- a/lib/Interfaces/Object/NoteInterface.php +++ b/lib/Interfaces/Object/NoteInterface.php @@ -101,7 +101,11 @@ class NoteInterface implements IActivityPubInterface { * @throws ItemNotFoundException */ public function getItemById(string $id): ACore { - throw new ItemNotFoundException(); + try { + return $this->notesRequest->getNoteById($id); + } catch (NoteNotFoundException $e) { + throw new ItemNotFoundException(); + } } @@ -134,20 +138,18 @@ class NoteInterface implements IActivityPubInterface { $this->save($item); } - if ($activity->getType() === Update::TYPE) { - $activity->checkOrigin($item->getId()); - $activity->checkOrigin($item->getAttributedTo()); - // TODO - check time and update. -// $this->save($item); - } } /** * @param ACore $item + * + * @throws InvalidOriginException */ public function delete(ACore $item) { + $item->checkOrigin(($item->getId())); + /** @var Note $item */ $this->notesRequest->deleteNoteById($item->getId()); } |