Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
pull/40/head
Maxence Lange 2018-11-20 11:52:24 -01:00
rodzic 62f713f434
commit c52e214614
5 zmienionych plików z 339 dodań i 5 usunięć

Wyświetl plik

@ -0,0 +1,82 @@
<?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\Activity;
use JsonSerializable;
use OCA\Social\Model\ActivityPub\ACore;
/**
* Class Delete
*
* @package OCA\Social\Model\ActivityPub\Activity
*/
class Delete extends ACore implements JsonSerializable {
const TYPE = 'Delete';
/**
* Activity 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);
$this->setActorId($this->get('actor', $data, ''));
}
/**
* @return array
*/
public function jsonSerialize(): array {
return array_merge(
parent::jsonSerialize(),
[
]
);
}
}

Wyświetl plik

@ -0,0 +1,82 @@
<?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\Activity;
use JsonSerializable;
use OCA\Social\Model\ActivityPub\ACore;
/**
* Class Tombstone
*
* @package OCA\Social\Model\ActivityPub\Activity
*/
class Tombstone extends ACore implements JsonSerializable {
const TYPE = 'Tombstone';
/**
* Undo 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);
}
/**
* @return array
*/
public function jsonSerialize(): array {
return array_merge(
parent::jsonSerialize(),
[
]
);
}
}

Wyświetl plik

@ -0,0 +1,127 @@
<?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\Service\ActivityPub;
use Exception;
use OCA\Social\Db\NotesRequest;
use OCA\Social\Exceptions\InvalidResourceException;
use OCA\Social\Exceptions\UnknownItemException;
use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Model\ActivityPub\Activity\Delete;
use OCA\Social\Service\ActivityService;
use OCA\Social\Service\ICoreService;
use OCA\Social\Service\MiscService;
class DeleteService implements ICoreService {
/** @var NotesRequest */
private $notesRequest;
/** @var ActivityService */
private $activityService;
/** @var NoteService */
private $noteService;
/** @var MiscService */
private $miscService;
/**
* UndoService constructor.
*
* @param NotesRequest $notesRequest
* @param ActivityService $activityService
* @param NoteService $noteService
* @param MiscService $miscService
*/
public function __construct(
NotesRequest $notesRequest, ActivityService $activityService, NoteService $noteService,
MiscService $miscService
) {
$this->notesRequest = $notesRequest;
$this->activityService = $activityService;
$this->noteService = $noteService;
$this->miscService = $miscService;
}
/**
* @param ACore $delete
*
* @throws UnknownItemException
*/
public function parse(ACore $delete) {
if ($delete->gotObject()) {
$id = $delete->getObject()
->getId();
} else {
$id = $delete->getObjectId();
}
/** @var Delete $delete */
try {
$item = $this->activityService->getItem($id);
switch ($item->getType()) {
case 'Note':
$service = $this->noteService;
break;
default:
throw new UnknownItemException();
}
try {
$service->delete($item);
} catch (Exception $e) {
$this->miscService->log(
2, 'Cannot delete ' . $delete->getType() . ': ' . $e->getMessage()
);
}
} catch (InvalidResourceException $e) {
}
}
/**
* @param ACore $item
*/
public function delete(ACore $item) {
}
}

Wyświetl plik

@ -27,13 +27,32 @@ declare(strict_types=1);
*
*/
namespace OCA\Social\Service;
use OCA\Social\Model\ActivityPub\ACore;
/**
* Interface ICoreService
*
* @package OCA\Social\Service
*/
interface ICoreService {
public function save(ACore $core);
/**
* @param ACore $item
*/
public function parse(ACore $item);
/**
* @param ACore $item
*/
public function delete(ACore $item);
}

Wyświetl plik

@ -37,10 +37,13 @@ use OCA\Social\Exceptions\UnknownItemException;
use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Model\ActivityPub\Activity\Accept;
use OCA\Social\Model\ActivityPub\Activity\Create;
use OCA\Social\Model\ActivityPub\Activity\Delete;
use OCA\Social\Model\ActivityPub\Activity\Reject;
use OCA\Social\Model\ActivityPub\Activity\Tombstone;
use OCA\Social\Model\ActivityPub\Follow;
use OCA\Social\Model\ActivityPub\Note;
use OCA\Social\Model\ActivityPub\Activity\Undo;
use OCA\Social\Service\ActivityPub\DeleteService;
use OCA\Social\Service\ActivityPub\FollowService;
use OCA\Social\Service\ActivityPub\NoteService;
use OCA\Social\Service\ActivityPub\UndoService;
@ -61,6 +64,9 @@ class ImportService {
/** @var FollowService */
private $followService;
/** @var DeleteService */
private $deleteService;
/** @var MiscService */
private $miscService;
@ -71,15 +77,18 @@ class ImportService {
* @param NoteService $noteService
* @param UndoService $undoService
* @param FollowService $followService
* @param DeleteService $deleteService
* @param MiscService $miscService
*/
public function __construct(
NoteService $noteService, UndoService $undoService, FollowService $followService,
DeleteService $deleteService,
MiscService $miscService
) {
$this->noteService = $noteService;
$this->undoService = $undoService;
$this->followService = $followService;
$this->deleteService = $deleteService;
$this->miscService = $miscService;
}
@ -113,6 +122,14 @@ class ImportService {
$item = new Create($root);
break;
case Delete::TYPE:
$item = new Delete($root);
break;
case Tombstone::TYPE:
$item = new Tombstone($root);
break;
case Note::TYPE:
$item = new Note($root);
break;
@ -155,10 +172,13 @@ class ImportService {
*
* @throws UnknownItemException
*/
public function save(Acore $activity) {
public function parse(Acore $activity) {
if ($activity->gotObject()) {
$this->save($activity->getObject());
try {
$this->parse($activity->getObject());
} catch (UnknownItemException $e) {
}
}
switch ($activity->getType()) {
@ -166,6 +186,10 @@ class ImportService {
// $service = $this;
// break;
case Delete::TYPE:
$service = $this->deleteService;
break;
// case Undo::TYPE:
// $service = $this->undoService;
// break;
@ -191,10 +215,10 @@ class ImportService {
}
try {
$service->save($activity);
$service->parse($activity);
} catch (Exception $e) {
$this->miscService->log(
2, 'Cannot save ' . $activity->getType() . ': ' . $e->getMessage()
2, 'Cannot parse ' . $activity->getType() . ': ' . $e->getMessage()
);
}
}