diff --git a/lib/Interfaces/Activity/FollowInterface.php b/lib/Interfaces/Activity/FollowInterface.php index 21564345..9de551b0 100644 --- a/lib/Interfaces/Activity/FollowInterface.php +++ b/lib/Interfaces/Activity/FollowInterface.php @@ -111,10 +111,11 @@ class FollowInterface implements IActivityPubInterface { $remoteActor = $this->cacheActorService->getFromId($follow->getActorId()); $accept = new Accept(); -// $accept->setUrlCloud($this->configService->getCloudAddress()); + $accept->setUrlCloud($this->configService->getCloudAddress()); $accept->generateUniqueId('#accept/follows'); $accept->setActorId($follow->getObjectId()); $accept->setObject($follow); + $follow->setParent($accept); $accept->addInstancePath( new InstancePath( @@ -122,8 +123,6 @@ class FollowInterface implements IActivityPubInterface { ) ); - $follow->setParent($accept); - $this->activityService->request($accept); $this->followsRequest->accepted($follow); } catch (Exception $e) { @@ -159,6 +158,7 @@ class FollowInterface implements IActivityPubInterface { } } catch (FollowDoesNotExistException $e) { $actor = $this->cacheActorService->getFromId($follow->getObjectId()); + if ($actor->isLocal()) { $follow->setFollowId($actor->getFollowers()); $this->followsRequest->save($follow); @@ -189,13 +189,14 @@ class FollowInterface implements IActivityPubInterface { public function activity(Acore $activity, ACore $item) { /** @var Follow $item */ if ($activity->getType() === Undo::TYPE) { + $activity->checkOrigin($item->getId()); $activity->checkOrigin($item->getActorId()); - $this->followsRequest->deleteByPersons($item); + $this->followsRequest->delete($item); } if ($activity->getType() === Reject::TYPE) { $activity->checkOrigin($item->getObjectId()); - $this->followsRequest->deleteByPersons($item); + $this->followsRequest->delete($item); } if ($activity->getType() === Accept::TYPE) { diff --git a/lib/Interfaces/Activity/UndoInterface.php b/lib/Interfaces/Activity/UndoInterface.php index 83e32afb..174feb4e 100644 --- a/lib/Interfaces/Activity/UndoInterface.php +++ b/lib/Interfaces/Activity/UndoInterface.php @@ -63,11 +63,12 @@ class UndoInterface implements IActivityPubInterface { if (!$item->gotObject()) { return; } + $object = $item->getObject(); try { - $service = AP::$activityPub->getInterfaceForItem($item->getObject()); - $service->activity($item, $object); + $interface = AP::$activityPub->getInterfaceForItem($item->getObject()); + $interface->activity($item, $object); } catch (UnknownItemException $e) { } } diff --git a/lib/Interfaces/Actor/PersonInterface.php b/lib/Interfaces/Actor/PersonInterface.php index 5c84dc9c..5585ebdc 100644 --- a/lib/Interfaces/Actor/PersonInterface.php +++ b/lib/Interfaces/Actor/PersonInterface.php @@ -127,7 +127,7 @@ class PersonInterface implements IActivityPubInterface { public function activity(Acore $activity, ACore $item) { /** @var Person $item */ if ($activity->getType() === Update::TYPE) { -// $this->miscService->log('### UPDATE PERSON !' . json_encode($item)); + // TODO - check time and update. } } diff --git a/lib/Interfaces/Object/NoteInterface.php b/lib/Interfaces/Object/NoteInterface.php index 12174c6c..6abf1f43 100644 --- a/lib/Interfaces/Object/NoteInterface.php +++ b/lib/Interfaces/Object/NoteInterface.php @@ -38,6 +38,7 @@ use OCA\Social\Exceptions\NoteNotFoundException; use OCA\Social\Interfaces\IActivityPubInterface; use OCA\Social\Model\ActivityPub\ACore; use OCA\Social\Model\ActivityPub\Activity\Create; +use OCA\Social\Model\ActivityPub\Activity\Update; use OCA\Social\Model\ActivityPub\Object\Note; use OCA\Social\Service\ConfigService; use OCA\Social\Service\CurlService; @@ -128,9 +129,18 @@ class NoteInterface implements IActivityPubInterface { /** @var Note $item */ if ($activity->getType() === Create::TYPE) { + $activity->checkOrigin($item->getId()); $activity->checkOrigin($item->getAttributedTo()); $this->save($item); } + + if ($activity->getType() === Update::TYPE) { + $activity->checkOrigin($item->getId()); + $activity->checkOrigin($item->getAttributedTo()); + // TODO - check time and update. +// $this->save($item); + } + } diff --git a/lib/Service/ImportService.php b/lib/Service/ImportService.php index aeb854ce..a93b00bd 100644 --- a/lib/Service/ImportService.php +++ b/lib/Service/ImportService.php @@ -35,6 +35,7 @@ use daita\MySmallPhpTools\Traits\TArrayTools; use Exception; use OCA\Social\AP; use OCA\Social\Exceptions\ActivityPubFormatException; +use OCA\Social\Exceptions\InvalidOriginException; use OCA\Social\Exceptions\RedundancyLimitException; use OCA\Social\Exceptions\SocialAppConfigException; use OCA\Social\Exceptions\UnknownItemException; @@ -88,10 +89,12 @@ class ImportService { * @param ACore $activity * * @throws UnknownItemException + * @throws InvalidOriginException */ public function parseIncomingRequest(ACore $activity) { - $interface = AP::$activityPub->getInterfaceForItem($activity); + $activity->checkOrigin($activity->getId()); + $interface = AP::$activityPub->getInterfaceForItem($activity); try { $interface->processIncomingRequest($activity); } catch (Exception $e) {