2018-11-12 22:57:32 +00:00
|
|
|
<?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;
|
|
|
|
|
|
|
|
|
2018-11-27 16:54:08 +00:00
|
|
|
use Exception;
|
2018-11-12 22:57:32 +00:00
|
|
|
use OC\User\NoUserException;
|
|
|
|
use OCA\Social\Exceptions\ActorDoesNotExistException;
|
2018-11-19 10:34:54 +00:00
|
|
|
use OCA\Social\Exceptions\SocialAppConfigException;
|
2018-11-12 22:57:32 +00:00
|
|
|
use OCA\Social\Model\ActivityPub\ACore;
|
|
|
|
use OCA\Social\Model\Post;
|
|
|
|
use OCA\Social\Service\ActivityPub\NoteService;
|
|
|
|
|
|
|
|
class PostService {
|
|
|
|
|
|
|
|
|
|
|
|
/** @var NoteService */
|
|
|
|
private $noteService;
|
|
|
|
|
2018-11-19 10:34:54 +00:00
|
|
|
/** @var ActorService */
|
|
|
|
private $actorService;
|
|
|
|
|
2018-11-12 22:57:32 +00:00
|
|
|
/** @var ActivityService */
|
|
|
|
private $activityService;
|
|
|
|
|
|
|
|
/** @var MiscService */
|
|
|
|
private $miscService;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PostService constructor.
|
|
|
|
*
|
|
|
|
* @param NoteService $noteService
|
2018-11-19 10:34:54 +00:00
|
|
|
* @param ActorService $actorService
|
2018-11-12 22:57:32 +00:00
|
|
|
* @param ActivityService $activityService
|
|
|
|
* @param MiscService $miscService
|
|
|
|
*/
|
|
|
|
public function __construct(
|
2018-11-19 10:34:54 +00:00
|
|
|
NoteService $noteService, ActorService $actorService, ActivityService $activityService,
|
|
|
|
MiscService $miscService
|
2018-11-12 22:57:32 +00:00
|
|
|
) {
|
|
|
|
$this->noteService = $noteService;
|
2018-11-19 10:34:54 +00:00
|
|
|
$this->actorService = $actorService;
|
2018-11-12 22:57:32 +00:00
|
|
|
$this->activityService = $activityService;
|
|
|
|
$this->miscService = $miscService;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Post $post
|
|
|
|
* @param ACore $activity
|
|
|
|
*
|
2018-11-27 16:54:08 +00:00
|
|
|
* @return string
|
2018-11-12 22:57:32 +00:00
|
|
|
* @throws ActorDoesNotExistException
|
|
|
|
* @throws NoUserException
|
2018-11-19 10:34:54 +00:00
|
|
|
* @throws SocialAppConfigException
|
2018-11-27 16:54:08 +00:00
|
|
|
* @throws Exception
|
2018-11-12 22:57:32 +00:00
|
|
|
*/
|
2018-11-27 16:54:08 +00:00
|
|
|
public function createPost(Post $post, ACore &$activity = null): string {
|
2018-11-12 22:57:32 +00:00
|
|
|
$note =
|
2018-11-13 18:05:58 +00:00
|
|
|
$this->noteService->generateNote(
|
|
|
|
$post->getUserId(), $post->getContent(), $post->getType()
|
|
|
|
);
|
2018-11-12 22:57:32 +00:00
|
|
|
|
|
|
|
$this->noteService->replyTo($note, $post->getReplyTo());
|
2018-11-27 16:54:08 +00:00
|
|
|
$this->noteService->addRecipients($note, $post->getType(), $post->getTo());
|
2018-11-12 22:57:32 +00:00
|
|
|
|
2018-11-19 10:34:54 +00:00
|
|
|
$actor = $this->actorService->getActorFromUserId($post->getUserId());
|
|
|
|
|
2018-11-21 19:22:46 +00:00
|
|
|
return $this->activityService->createActivity($actor, $note, $activity);
|
2018-11-12 22:57:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|