kopia lustrzana https://github.com/nextcloud/social
Model and Interface: Announce
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>pull/374/head
rodzic
393e73f7e2
commit
2081e9b3a5
lib
46
lib/AP.php
46
lib/AP.php
|
@ -48,6 +48,7 @@ use OCA\Social\Interfaces\Activity\UndoInterface;
|
|||
use OCA\Social\Interfaces\Activity\UpdateInterface;
|
||||
use OCA\Social\Interfaces\Actor\PersonInterface;
|
||||
use OCA\Social\Interfaces\IActivityPubInterface;
|
||||
use OCA\Social\Interfaces\Object\AnnounceInterface;
|
||||
use OCA\Social\Interfaces\Object\NoteInterface;
|
||||
use OCA\Social\Model\ActivityPub\ACore;
|
||||
use OCA\Social\Model\ActivityPub\Activity\Accept;
|
||||
|
@ -62,6 +63,7 @@ use OCA\Social\Model\ActivityPub\Activity\Remove;
|
|||
use OCA\Social\Model\ActivityPub\Activity\Undo;
|
||||
use OCA\Social\Model\ActivityPub\Activity\Update;
|
||||
use OCA\Social\Model\ActivityPub\Actor\Person;
|
||||
use OCA\Social\Model\ActivityPub\Object\Announce;
|
||||
use OCA\Social\Model\ActivityPub\Object\Document;
|
||||
use OCA\Social\Model\ActivityPub\Object\Image;
|
||||
use OCA\Social\Model\ActivityPub\Object\Note;
|
||||
|
@ -90,6 +92,9 @@ class AP {
|
|||
/** @var AddInterface */
|
||||
public $addInterface;
|
||||
|
||||
/** @var AnnounceInterface */
|
||||
public $announceInterface;
|
||||
|
||||
/** @var BlockInterface */
|
||||
public $blockInterface;
|
||||
|
||||
|
@ -146,6 +151,7 @@ class AP {
|
|||
try {
|
||||
$ap->acceptInterface = \OC::$server->query(AcceptInterface::class);
|
||||
$ap->addInterface = \OC::$server->query(AddInterface::class);
|
||||
$ap->announceInterface = \OC::$server->query(AnnounceInterface::class);
|
||||
$ap->blockInterface = \OC::$server->query(BlockInterface::class);
|
||||
$ap->createInterface = \OC::$server->query(CreateInterface::class);
|
||||
$ap->deleteInterface = \OC::$server->query(DeleteInterface::class);
|
||||
|
@ -186,11 +192,7 @@ class AP {
|
|||
$item->setParent($parent);
|
||||
}
|
||||
|
||||
try {
|
||||
$object = $this->getItemFromData($this->getArray('object', $data, []), $item, $level);
|
||||
$item->setObject($object);
|
||||
} catch (ItemUnknownException $e) {
|
||||
}
|
||||
$this->getObjectFromData($data, $item, $level);
|
||||
|
||||
try {
|
||||
/** @var Document $icon */
|
||||
|
@ -203,6 +205,32 @@ class AP {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param ACore $item
|
||||
* @param int $level
|
||||
*
|
||||
* @throws RedundancyLimitException
|
||||
* @throws SocialAppConfigException
|
||||
*/
|
||||
public function getObjectFromData(array $data, ACore &$item, int $level) {
|
||||
try {
|
||||
$objectData = $this->getArray('object', $data, []);
|
||||
if (empty($objectData)) {
|
||||
$objectId = $this->get('object', $data, '');
|
||||
if ($objectId !== '') {
|
||||
// TODO: validate AS_URL
|
||||
$item->setObjectId($objectId);
|
||||
}
|
||||
} else {
|
||||
$object = $this->getItemFromData($objectData, $item, $level);
|
||||
$item->setObject($object);
|
||||
}
|
||||
} catch (ItemUnknownException $e) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
|
@ -236,6 +264,10 @@ class AP {
|
|||
$item = new Add();
|
||||
break;
|
||||
|
||||
case Announce::TYPE:
|
||||
$item = new Announce();
|
||||
break;
|
||||
|
||||
case Block::TYPE:
|
||||
$item = new Block();
|
||||
break;
|
||||
|
@ -325,6 +357,10 @@ class AP {
|
|||
$service = $this->addInterface;
|
||||
break;
|
||||
|
||||
case Announce::TYPE:
|
||||
$service = $this->announceInterface;
|
||||
break;
|
||||
|
||||
case Block::TYPE:
|
||||
$service = $this->blockInterface;
|
||||
break;
|
||||
|
|
|
@ -0,0 +1,120 @@
|
|||
<?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\Object;
|
||||
|
||||
|
||||
use OCA\Social\Exceptions\ItemNotFoundException;
|
||||
use OCA\Social\Interfaces\IActivityPubInterface;
|
||||
use OCA\Social\Model\ActivityPub\ACore;
|
||||
use OCA\Social\Model\ActivityPub\Object\Announce;
|
||||
use OCA\Social\Service\MiscService;
|
||||
|
||||
|
||||
class AnnounceInterface implements IActivityPubInterface {
|
||||
|
||||
|
||||
/** @var MiscService */
|
||||
private $miscService;
|
||||
|
||||
|
||||
/**
|
||||
* AnnounceInterface constructor.
|
||||
*
|
||||
* @param MiscService $miscService
|
||||
*/
|
||||
public function __construct(MiscService $miscService) {
|
||||
$this->miscService = $miscService;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param ACore $activity
|
||||
* @param ACore $item
|
||||
*/
|
||||
public function activity(Acore $activity, ACore $item) {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param ACore $item
|
||||
*/
|
||||
public function processIncomingRequest(ACore $item) {
|
||||
// if (!$item->gotObject()) {
|
||||
// return;
|
||||
// }
|
||||
$object = $item->getObjectId();
|
||||
$this->miscService->log('___' . json_encode($object));
|
||||
//
|
||||
// try {
|
||||
// $service = AP::$activityPub->getInterfaceForItem($item->getObject());
|
||||
// $service->activity($item, $object);
|
||||
// } catch (ItemUnknownException $e) {
|
||||
// }
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param ACore $item
|
||||
*/
|
||||
public function processResult(ACore $item) {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
*
|
||||
* @return ACore
|
||||
* @throws ItemNotFoundException
|
||||
*/
|
||||
public function getItemById(string $id): ACore {
|
||||
throw new ItemNotFoundException();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ACore $item
|
||||
*/
|
||||
public function save(ACore $item) {
|
||||
/** @var Announce $item */
|
||||
// $this->cacheDocumentsRequest->save($item);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param ACore $item
|
||||
*/
|
||||
public function delete(ACore $item) {
|
||||
// $this->cacheDocumentsRequest->delete($item);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,96 @@
|
|||
<?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\Object;
|
||||
|
||||
|
||||
use JsonSerializable;
|
||||
use OCA\Social\Model\ActivityPub\ACore;
|
||||
|
||||
|
||||
/**
|
||||
* Class Follow
|
||||
*
|
||||
* @package OCA\Social\Model\ActivityPub\Object
|
||||
*/
|
||||
class Announce extends ACore implements JsonSerializable {
|
||||
|
||||
|
||||
const TYPE = 'Announce';
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Follow constructor.
|
||||
*
|
||||
* @param ACore $parent
|
||||
*/
|
||||
public function __construct($parent = null) {
|
||||
parent::__construct($parent);
|
||||
|
||||
$this->setType(self::TYPE);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*/
|
||||
public function import(array $data) {
|
||||
parent::import($data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*/
|
||||
public function importFromDatabase(array $data) {
|
||||
parent::importFromDatabase($data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function jsonSerialize(): array {
|
||||
$result = parent::jsonSerialize();
|
||||
|
||||
if ($this->isCompleteDetails()) {
|
||||
array_merge(
|
||||
$result,
|
||||
[]
|
||||
);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
|
Ładowanie…
Reference in New Issue