kopia lustrzana https://github.com/nextcloud/social
Service as Actor
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>pull/595/head
rodzic
e499140035
commit
9411cf6046
30
lib/AP.php
30
lib/AP.php
|
@ -41,6 +41,7 @@ use OCA\Social\Interfaces\Activity\AddInterface;
|
|||
use OCA\Social\Interfaces\Activity\BlockInterface;
|
||||
use OCA\Social\Interfaces\Activity\CreateInterface;
|
||||
use OCA\Social\Interfaces\Activity\DeleteInterface;
|
||||
use OCA\Social\Interfaces\Actor\ServiceInterface;
|
||||
use OCA\Social\Interfaces\Object\FollowInterface;
|
||||
use OCA\Social\Interfaces\Activity\LikeInterface;
|
||||
use OCA\Social\Interfaces\Activity\RejectInterface;
|
||||
|
@ -60,6 +61,7 @@ use OCA\Social\Model\ActivityPub\Activity\Add;
|
|||
use OCA\Social\Model\ActivityPub\Activity\Block;
|
||||
use OCA\Social\Model\ActivityPub\Activity\Create;
|
||||
use OCA\Social\Model\ActivityPub\Activity\Delete;
|
||||
use OCA\Social\Model\ActivityPub\Actor\Service;
|
||||
use OCA\Social\Model\ActivityPub\Object\Follow;
|
||||
use OCA\Social\Model\ActivityPub\Activity\Like;
|
||||
use OCA\Social\Model\ActivityPub\Activity\Reject;
|
||||
|
@ -134,6 +136,9 @@ class AP {
|
|||
/** @var RemoveInterface */
|
||||
public $removeInterface;
|
||||
|
||||
/** @var ServiceInterface */
|
||||
public $serviceInterface;
|
||||
|
||||
/** @var UndoInterface */
|
||||
public $undoInterface;
|
||||
|
||||
|
@ -177,6 +182,7 @@ class AP {
|
|||
$ap->noteInterface = OC::$server->query(NoteInterface::class);
|
||||
$ap->notificationInterface = OC::$server->query(SocialAppNotificationInterface::class);
|
||||
$ap->personInterface = OC::$server->query(PersonInterface::class);
|
||||
$ap->serviceInterface = OC::$server->query(ServiceInterface::class);
|
||||
$ap->rejectInterface = OC::$server->query(RejectInterface::class);
|
||||
$ap->removeInterface = OC::$server->query(RemoveInterface::class);
|
||||
$ap->undoInterface = OC::$server->query(UndoInterface::class);
|
||||
|
@ -334,6 +340,10 @@ class AP {
|
|||
$item = new Remove();
|
||||
break;
|
||||
|
||||
case Service::TYPE:
|
||||
$item = new Service();
|
||||
break;
|
||||
|
||||
case Tombstone::TYPE:
|
||||
$item = new Tombstone();
|
||||
break;
|
||||
|
@ -435,6 +445,10 @@ class AP {
|
|||
$interface = $this->removeInterface;
|
||||
break;
|
||||
|
||||
case Service::TYPE:
|
||||
$interface = $this->serviceInterface;
|
||||
break;
|
||||
|
||||
case Undo::TYPE:
|
||||
$interface = $this->undoInterface;
|
||||
break;
|
||||
|
@ -450,6 +464,22 @@ class AP {
|
|||
return $interface;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param ACore $item
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isActor(ACore $item): bool {
|
||||
$types =
|
||||
[
|
||||
Person::TYPE,
|
||||
Service::TYPE
|
||||
];
|
||||
|
||||
return (in_array($item->getType(), $types));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@ use DateInterval;
|
|||
use DateTime;
|
||||
use Doctrine\DBAL\Query\QueryBuilder;
|
||||
use Exception;
|
||||
use OCA\Social\AP;
|
||||
use OCA\Social\Exceptions\DateTimeException;
|
||||
use OCA\Social\Exceptions\InvalidResourceException;
|
||||
use OCA\Social\Model\ActivityPub\Actor\Person;
|
||||
|
@ -706,7 +707,7 @@ class CoreRequestBuilder {
|
|||
$actor = new Person();
|
||||
$actor->importFromDatabase($new);
|
||||
|
||||
if ($actor->getType() !== Person::TYPE) {
|
||||
if (!AP::$activityPub->isActor($actor)) {
|
||||
throw new InvalidResourceException();
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* Nextcloud - Social Support
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
namespace OCA\Social\Interfaces\Actor;
|
||||
|
||||
|
||||
use OCA\Social\Interfaces\IActivityPubInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Class ServiceInterface
|
||||
*
|
||||
* @package OCA\Social\Service\ActivityPub
|
||||
*/
|
||||
class ServiceInterface extends PersonInterface implements IActivityPubInterface {
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* Nextcloud - Social Support
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
namespace OCA\Social\Model\ActivityPub\Actor;
|
||||
|
||||
|
||||
use JsonSerializable;
|
||||
|
||||
|
||||
/**
|
||||
* Class Service
|
||||
*
|
||||
* @package OCA\Social\Model\ActivityPub
|
||||
*/
|
||||
class Service extends Person implements JsonSerializable {
|
||||
|
||||
|
||||
const TYPE = 'Service';
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -139,7 +139,7 @@ class CacheActorService {
|
|||
|
||||
/** @var Person $actor */
|
||||
$actor = AP::$activityPub->getItemFromData($object);
|
||||
if ($actor->getType() !== Person::TYPE) {
|
||||
if (!AP::$activityPub->isActor($actor)) {
|
||||
throw new InvalidResourceException();
|
||||
}
|
||||
|
||||
|
@ -273,7 +273,7 @@ class CacheActorService {
|
|||
*/
|
||||
private function save(Person $actor) {
|
||||
try {
|
||||
$interface = AP::$activityPub->getInterfaceFromType(Person::TYPE);
|
||||
$interface = AP::$activityPub->getInterfaceFromType($actor->getType());
|
||||
$interface->save($actor);
|
||||
} catch (ItemUnknownException $e) {
|
||||
}
|
||||
|
|
|
@ -51,6 +51,7 @@ use OCA\Social\Exceptions\SocialAppConfigException;
|
|||
use OCA\Social\Exceptions\ItemUnknownException;
|
||||
use OCA\Social\Exceptions\UnauthorizedFediverseException;
|
||||
use OCA\Social\Model\ActivityPub\Actor\Person;
|
||||
use OCA\Social\Model\ActivityPub\Actor\Service;
|
||||
|
||||
class CurlService {
|
||||
|
||||
|
@ -209,7 +210,7 @@ class CurlService {
|
|||
|
||||
/** @var Person $actor */
|
||||
$actor = AP::$activityPub->getItemFromData($data);
|
||||
if ($actor->getType() !== Person::TYPE) {
|
||||
if (!AP::$activityPub->isActor($actor)) {
|
||||
throw new ItemUnknownException();
|
||||
}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue