Image and document interfaces

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
pull/352/head
Maxence Lange 2019-01-18 15:51:43 -01:00
rodzic 059711f28a
commit 5236dd4ae8
3 zmienionych plików z 158 dodań i 17 usunięć

Wyświetl plik

@ -48,6 +48,8 @@ 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\DocumentInterface;
use OCA\Social\Interfaces\Object\ImageInterface;
use OCA\Social\Interfaces\Object\NoteInterface;
use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Model\ActivityPub\Activity\Accept;
@ -99,9 +101,15 @@ class AP {
/** @var DeleteInterface */
public $deleteInterface;
/** @var DocumentInterface */
public $documentInterface;
/** @var FollowInterface */
public $followInterface;
/** @var ImageInterface */
public $imageInterface;
/** @var LikeInterface */
public $likeInterface;
@ -149,7 +157,9 @@ class AP {
$ap->blockInterface = \OC::$server->query(BlockInterface::class);
$ap->createInterface = \OC::$server->query(CreateInterface::class);
$ap->deleteInterface = \OC::$server->query(DeleteInterface::class);
$ap->documentInterface = \OC::$server->query(DocumentInterface::class);
$ap->followInterface = \OC::$server->query(FollowInterface::class);
$ap->imageInterface = \OC::$server->query(ImageInterface::class);
$ap->likeInterface = \OC::$server->query(LikeInterface::class);
$ap->rejectInterface = \OC::$server->query(RejectInterface::class);
$ap->removeInterface = \OC::$server->query(RemoveInterface::class);
@ -193,6 +203,7 @@ class AP {
}
try {
// TODO: move to Model/Person if 'icon' is specific to Person object ?
/** @var Document $icon */
$icon = $this->getItemFromData($this->getArray('icon', $data, []), $item, $level);
$item->setIcon($icon);
@ -248,6 +259,10 @@ class AP {
$item = new Delete();
break;
case Document::TYPE:
$item = new Document();
break;
case Follow::TYPE:
$item = new Follow();
break;
@ -318,62 +333,70 @@ class AP {
public function getInterfaceFromType(string $type): IActivityPubInterface {
switch ($type) {
case Accept::TYPE:
$service = $this->acceptInterface;
$interface = $this->acceptInterface;
break;
case Add::TYPE:
$service = $this->addInterface;
$interface = $this->addInterface;
break;
case Block::TYPE:
$service = $this->blockInterface;
$interface = $this->blockInterface;
break;
case Create::TYPE:
$service = $this->createInterface;
$interface = $this->createInterface;
break;
case Delete::TYPE:
$service = $this->deleteInterface;
$interface = $this->deleteInterface;
break;
case Document::TYPE:
$interface = $this->documentInterface;
break;
case Follow::TYPE:
$service = $this->followInterface;
$interface = $this->followInterface;
break;
case Image::TYPE:
$interface = $this->imageInterface;
break;
case Like::TYPE:
$service = $this->likeInterface;
$interface = $this->likeInterface;
break;
case Note::TYPE:
$service = $this->noteInterface;
$interface = $this->noteInterface;
break;
case Person::TYPE:
$service = $this->personInterface;
$interface = $this->personInterface;
break;
case Reject::TYPE:
$service = $this->rejectInterface;
$interface = $this->rejectInterface;
break;
case Remove::TYPE:
$service = $this->removeInterface;
$interface = $this->removeInterface;
break;
case Undo::TYPE:
$service = $this->undoInterface;
$interface = $this->undoInterface;
break;
case Update::TYPE:
$service = $this->updateInterface;
$interface = $this->updateInterface;
break;
default:
throw new ItemUnknownException();
}
return $service;
return $interface;
}
}

Wyświetl plik

@ -32,6 +32,7 @@ namespace OCA\Social\Interfaces\Object;
use OCA\Social\Db\CacheDocumentsRequest;
use OCA\Social\Exceptions\CacheDocumentDoesNotExistException;
use OCA\Social\Exceptions\ItemNotFoundException;
use OCA\Social\Interfaces\IActivityPubInterface;
use OCA\Social\Model\ActivityPub\ACore;
@ -43,10 +44,10 @@ class DocumentInterface implements IActivityPubInterface {
/** @var CacheDocumentsRequest */
private $cacheDocumentsRequest;
protected $cacheDocumentsRequest;
/** @var MiscService */
private $miscService;
protected $miscService;
/**
@ -107,7 +108,14 @@ class DocumentInterface implements IActivityPubInterface {
);
}
$this->cacheDocumentsRequest->save($item);
try {
$this->cacheDocumentsRequest->getById($item->getId());
$this->cacheDocumentsRequest->update($item);
} catch (CacheDocumentDoesNotExistException $e) {
if (!$this->cacheDocumentsRequest->isDuplicate($item)) {
$this->cacheDocumentsRequest->save($item);
}
}
}

Wyświetl plik

@ -0,0 +1,110 @@
<?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\Db\CacheDocumentsRequest;
use OCA\Social\Exceptions\ItemNotFoundException;
use OCA\Social\Interfaces\IActivityPubInterface;
use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Model\ActivityPub\Object\Document;
use OCA\Social\Service\MiscService;
class ImageInterface extends DocumentInterface implements IActivityPubInterface {
/**
* DocumentInterface constructor.
*
* @param CacheDocumentsRequest $cacheDocumentsRequest
* @param MiscService $miscService
*/
public function __construct(
CacheDocumentsRequest $cacheDocumentsRequest, MiscService $miscService
) {
parent::__construct($cacheDocumentsRequest, $miscService);
}
/**
* @param ACore $activity
* @param ACore $item
*/
public function activity(Acore $activity, ACore $item) {
parent::activity($activity, $item);
}
/**
* @param ACore $item
*/
public function processIncomingRequest(ACore $item) {
parent::processIncomingRequest($item);
}
/**
* @param ACore $item
*/
public function processResult(ACore $item) {
parent::processResult($item);
}
/**
* @param string $id
*
* @return ACore
* @throws ItemNotFoundException
*/
public function getItemById(string $id): ACore {
return parent::getItemById($id);
}
/**
* @param ACore $item
*/
public function save(ACore $item) {
parent::save($item);
}
/**
* @param ACore $item
*/
public function delete(ACore $item) {
parent::delete($item);
}
}