kopia lustrzana https://github.com/nextcloud/social
Merge pull request #280 from nextcloud/bugfix/noid/delete-on-object-id
get item by Id and delete itpull/273/head
commit
9be2302834
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
|
|
|
|||
Ładowanie…
Reference in New Issue