kopia lustrzana https://github.com/nextcloud/social
boost creation
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>pull/374/head
rodzic
8a92d5680a
commit
9ac8eb965b
|
@ -47,6 +47,7 @@
|
||||||
<commands>
|
<commands>
|
||||||
<command>OCA\Social\Command\CacheRefresh</command>
|
<command>OCA\Social\Command\CacheRefresh</command>
|
||||||
<command>OCA\Social\Command\NoteCreate</command>
|
<command>OCA\Social\Command\NoteCreate</command>
|
||||||
|
<command>OCA\Social\Command\NoteBoost</command>
|
||||||
<command>OCA\Social\Command\Reset</command>
|
<command>OCA\Social\Command\Reset</command>
|
||||||
<command>OCA\Social\Command\QueueStatus</command>
|
<command>OCA\Social\Command\QueueStatus</command>
|
||||||
<command>OCA\Social\Command\QueueProcess</command>
|
<command>OCA\Social\Command\QueueProcess</command>
|
||||||
|
|
|
@ -0,0 +1,136 @@
|
||||||
|
<?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\Command;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use OC\Core\Command\Base;
|
||||||
|
use OCA\Social\Model\ActivityPub\ACore;
|
||||||
|
use OCA\Social\Model\ActivityPub\Object\Announce;
|
||||||
|
use OCA\Social\Model\ActivityPub\Stream;
|
||||||
|
use OCA\Social\Model\Post;
|
||||||
|
use OCA\Social\Service\AccountService;
|
||||||
|
use OCA\Social\Service\ActivityService;
|
||||||
|
use OCA\Social\Service\ConfigService;
|
||||||
|
use OCA\Social\Service\CurlService;
|
||||||
|
use OCA\Social\Service\MiscService;
|
||||||
|
use OCA\Social\Service\NoteService;
|
||||||
|
use OCA\Social\Service\PostService;
|
||||||
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
|
|
||||||
|
class NoteBoost extends Base {
|
||||||
|
|
||||||
|
|
||||||
|
/** @var ConfigService */
|
||||||
|
private $configService;
|
||||||
|
|
||||||
|
/** @var ActivityService */
|
||||||
|
private $activityService;
|
||||||
|
|
||||||
|
/** @var NoteService */
|
||||||
|
private $noteService;
|
||||||
|
|
||||||
|
/** @var AccountService */
|
||||||
|
private $accountService;
|
||||||
|
|
||||||
|
/** @var PostService */
|
||||||
|
private $postService;
|
||||||
|
|
||||||
|
/** @var CurlService */
|
||||||
|
private $curlService;
|
||||||
|
|
||||||
|
/** @var MiscService */
|
||||||
|
private $miscService;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* NoteCreate constructor.
|
||||||
|
*
|
||||||
|
* @param ActivityService $activityService
|
||||||
|
* @param AccountService $accountService
|
||||||
|
* @param NoteService $noteService
|
||||||
|
* @param PostService $postService
|
||||||
|
* @param CurlService $curlService
|
||||||
|
* @param ConfigService $configService
|
||||||
|
* @param MiscService $miscService
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
ActivityService $activityService, AccountService $accountService,
|
||||||
|
NoteService $noteService, PostService $postService, CurlService $curlService,
|
||||||
|
ConfigService $configService, MiscService $miscService
|
||||||
|
) {
|
||||||
|
parent::__construct();
|
||||||
|
|
||||||
|
$this->activityService = $activityService;
|
||||||
|
$this->noteService = $noteService;
|
||||||
|
$this->accountService = $accountService;
|
||||||
|
$this->postService = $postService;
|
||||||
|
$this->curlService = $curlService;
|
||||||
|
$this->configService = $configService;
|
||||||
|
$this->miscService = $miscService;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
protected function configure() {
|
||||||
|
parent::configure();
|
||||||
|
$this->setName('social:note:boost')
|
||||||
|
->addArgument('userid', InputArgument::REQUIRED, 'userId of the author')
|
||||||
|
->addArgument('note', InputArgument::REQUIRED, 'Note to boost')
|
||||||
|
->setDescription('Boost a note');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param InputInterface $input
|
||||||
|
* @param OutputInterface $output
|
||||||
|
*
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
protected function execute(InputInterface $input, OutputInterface $output) {
|
||||||
|
$userId = $input->getArgument('userid');
|
||||||
|
$noteId = $input->getArgument('note');
|
||||||
|
|
||||||
|
$actor = $this->accountService->getActorFromUserId($userId);
|
||||||
|
$this->noteService->setViewer($actor);
|
||||||
|
$token = $this->noteService->createBoost($actor, $noteId, $activity);
|
||||||
|
|
||||||
|
echo 'object: ' . json_encode($activity, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "\n";
|
||||||
|
echo 'token: ' . $token . "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -47,6 +47,7 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
class NoteCreate extends Base {
|
class NoteCreate extends Base {
|
||||||
|
|
||||||
|
|
||||||
/** @var ConfigService */
|
/** @var ConfigService */
|
||||||
private $configService;
|
private $configService;
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,6 @@ use OCA\Social\Exceptions\AccountDoesNotExistException;
|
||||||
use OCA\Social\Exceptions\InvalidResourceException;
|
use OCA\Social\Exceptions\InvalidResourceException;
|
||||||
use OCA\Social\Model\ActivityPub\ACore;
|
use OCA\Social\Model\ActivityPub\ACore;
|
||||||
use OCA\Social\Model\ActivityPub\Actor\Person;
|
use OCA\Social\Model\ActivityPub\Actor\Person;
|
||||||
use OCA\Social\Model\ActivityPub\Object\Note;
|
|
||||||
use OCA\Social\Model\ActivityPub\Stream;
|
use OCA\Social\Model\ActivityPub\Stream;
|
||||||
use OCA\Social\Model\Post;
|
use OCA\Social\Model\Post;
|
||||||
use OCA\Social\Service\AccountService;
|
use OCA\Social\Service\AccountService;
|
||||||
|
@ -198,6 +197,35 @@ class LocalController extends Controller {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Create a new boost.
|
||||||
|
*
|
||||||
|
* @NoAdminRequired
|
||||||
|
*
|
||||||
|
* @param array $data
|
||||||
|
*
|
||||||
|
* @return DataResponse
|
||||||
|
*/
|
||||||
|
public function boostPost(array $data): DataResponse {
|
||||||
|
try {
|
||||||
|
$this->initViewer(true);
|
||||||
|
|
||||||
|
$postId = $this->get('postId', $data, '');
|
||||||
|
$token = $this->noteService->createBoost($this->viewer, $postId, $announce);
|
||||||
|
|
||||||
|
return $this->success(
|
||||||
|
[
|
||||||
|
'boost' => $announce,
|
||||||
|
'token' => $token
|
||||||
|
]
|
||||||
|
);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return $this->fail($e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @NoCSRFRequired
|
||||||
* @NoAdminRequired
|
* @NoAdminRequired
|
||||||
*
|
*
|
||||||
* @param int $since
|
* @param int $since
|
||||||
|
@ -669,13 +697,19 @@ class LocalController extends Controller {
|
||||||
*/
|
*/
|
||||||
private function initViewer(bool $exception = false) {
|
private function initViewer(bool $exception = false) {
|
||||||
if (!isset($this->userId)) {
|
if (!isset($this->userId)) {
|
||||||
|
if ($exception) {
|
||||||
|
throw new AccountDoesNotExistException('userId not defined');
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$this->viewer = $this->accountService->getActorFromUserId($this->userId, true);
|
$this->viewer = $this->accountService->getActorFromUserId($this->userId, true);
|
||||||
|
|
||||||
$this->followService->setViewerId($this->viewer->getId());
|
$this->noteService->setViewer($this->viewer);
|
||||||
$this->cacheActorService->setViewerId($this->viewer->getId());
|
$this->followService->setViewer($this->viewer);
|
||||||
|
$this->cacheActorService->setViewer($this->viewer);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
if ($exception) {
|
if ($exception) {
|
||||||
throw new AccountDoesNotExistException();
|
throw new AccountDoesNotExistException();
|
||||||
|
|
|
@ -79,8 +79,8 @@ class CoreRequestBuilder {
|
||||||
/** @var string */
|
/** @var string */
|
||||||
protected $defaultSelectAlias;
|
protected $defaultSelectAlias;
|
||||||
|
|
||||||
/** @var string */
|
/** @var Person */
|
||||||
private $viewerId = '';
|
protected $viewer = null;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -100,17 +100,10 @@ class CoreRequestBuilder {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @param Person $viewer
|
||||||
*/
|
*/
|
||||||
public function getViewerId(): string {
|
public function setViewer(Person $viewer) {
|
||||||
return $this->viewerId;
|
$this->viewer = $viewer;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $viewerId
|
|
||||||
*/
|
|
||||||
public function setViewerId(string $viewerId) {
|
|
||||||
$this->viewerId = $viewerId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -722,8 +715,7 @@ class CoreRequestBuilder {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$viewerId = $this->getViewerId();
|
if ($this->viewer === null) {
|
||||||
if ($viewerId === '') {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -744,7 +736,7 @@ class CoreRequestBuilder {
|
||||||
$andX->add(
|
$andX->add(
|
||||||
$expr->eq(
|
$expr->eq(
|
||||||
$func->lower($prefix . '_f.actor_id'),
|
$func->lower($prefix . '_f.actor_id'),
|
||||||
$func->lower($qb->createNamedParameter($viewerId))
|
$func->lower($qb->createNamedParameter($this->viewer->getId()))
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
@ -756,7 +748,7 @@ class CoreRequestBuilder {
|
||||||
$andX->add(
|
$andX->add(
|
||||||
$expr->eq(
|
$expr->eq(
|
||||||
$func->lower($prefix . '_f.object_id'),
|
$func->lower($prefix . '_f.object_id'),
|
||||||
$func->lower($qb->createNamedParameter($viewerId))
|
$func->lower($qb->createNamedParameter($this->viewer->getId()))
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -820,7 +812,9 @@ class CoreRequestBuilder {
|
||||||
* @param array $data
|
* @param array $data
|
||||||
*/
|
*/
|
||||||
protected function assignDetails(Person $actor, array $data) {
|
protected function assignDetails(Person $actor, array $data) {
|
||||||
if ($this->getViewerId() !== '') {
|
if ($this->viewer === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$this->parseFollowLeftJoin($data, 'as_follower');
|
$this->parseFollowLeftJoin($data, 'as_follower');
|
||||||
|
@ -838,7 +832,6 @@ class CoreRequestBuilder {
|
||||||
|
|
||||||
$actor->setCompleteDetails(true);
|
$actor->setCompleteDetails(true);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -60,60 +60,17 @@ class NotesRequest extends NotesRequestBuilder {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Insert a new Note in the database.
|
* @param Stream $stream
|
||||||
*
|
|
||||||
* @param Stream $note
|
|
||||||
*/
|
*/
|
||||||
public function save(Stream $note) {
|
public function save(Stream $stream) {
|
||||||
$dTime = new DateTime();
|
$qb = $this->saveStream($stream);
|
||||||
$dTime->setTimestamp($note->getPublishedTime());
|
|
||||||
|
|
||||||
$cache = '[]';
|
if ($stream->getType() === Note::TYPE) {
|
||||||
if ($note->gotCache()) {
|
/** @var Note $stream */
|
||||||
$cache = json_encode($note->getCache(), JSON_UNESCAPED_SLASHES);
|
$qb->setValue(
|
||||||
}
|
'hashtags', $qb->createNamedParameter(json_encode($stream->getHashtags()))
|
||||||
|
|
||||||
$qb = $this->getNotesInsertSql();
|
|
||||||
$qb->setValue('id', $qb->createNamedParameter($note->getId()))
|
|
||||||
->setValue('type', $qb->createNamedParameter($note->getType()))
|
|
||||||
->setValue('to', $qb->createNamedParameter($note->getTo()))
|
|
||||||
->setValue(
|
|
||||||
'to_array', $qb->createNamedParameter(
|
|
||||||
json_encode($note->getToArray(), JSON_UNESCAPED_SLASHES)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
->setValue(
|
|
||||||
'cc', $qb->createNamedParameter(
|
|
||||||
json_encode($note->getCcArray(), JSON_UNESCAPED_SLASHES)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
->setValue(
|
|
||||||
'bcc', $qb->createNamedParameter(
|
|
||||||
json_encode($note->getBccArray()), JSON_UNESCAPED_SLASHES
|
|
||||||
)
|
|
||||||
)
|
|
||||||
->setValue('content', $qb->createNamedParameter($note->getContent()))
|
|
||||||
->setValue('summary', $qb->createNamedParameter($note->getSummary()))
|
|
||||||
->setValue('hashtags', $qb->createNamedParameter(json_encode($note->getHashtags())))
|
|
||||||
->setValue('published', $qb->createNamedParameter($note->getPublished()))
|
|
||||||
->setValue(
|
|
||||||
'published_time', $qb->createNamedParameter($dTime, IQueryBuilder::PARAM_DATE)
|
|
||||||
)
|
|
||||||
->setValue('attributed_to', $qb->createNamedParameter($note->getAttributedTo()))
|
|
||||||
->setValue('in_reply_to', $qb->createNamedParameter($note->getInReplyTo()))
|
|
||||||
->setValue('source', $qb->createNamedParameter($note->getSource()))
|
|
||||||
->setValue('object_id', $qb->createNamedParameter($note->getObjectId()))
|
|
||||||
->setValue('cache', $qb->createNamedParameter($cache))
|
|
||||||
->setValue(
|
|
||||||
'instances', $qb->createNamedParameter(
|
|
||||||
json_encode($note->getInstancePaths(), JSON_UNESCAPED_SLASHES)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
->setValue('local', $qb->createNamedParameter(($note->isLocal()) ? '1' : '0'))
|
|
||||||
->setValue(
|
|
||||||
'creation',
|
|
||||||
$qb->createNamedParameter(new DateTime('now'), IQueryBuilder::PARAM_DATE)
|
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$qb->execute();
|
$qb->execute();
|
||||||
}
|
}
|
||||||
|
@ -135,11 +92,12 @@ class NotesRequest extends NotesRequestBuilder {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $id
|
* @param string $id
|
||||||
|
* @param bool $asViewer
|
||||||
*
|
*
|
||||||
* @return Note
|
* @return Note
|
||||||
* @throws NoteNotFoundException
|
* @throws NoteNotFoundException
|
||||||
*/
|
*/
|
||||||
public function getNoteById(string $id): Note {
|
public function getNoteById(string $id, bool $asViewer = false): Note {
|
||||||
if ($id === '') {
|
if ($id === '') {
|
||||||
throw new NoteNotFoundException();
|
throw new NoteNotFoundException();
|
||||||
};
|
};
|
||||||
|
@ -147,6 +105,10 @@ class NotesRequest extends NotesRequestBuilder {
|
||||||
$qb = $this->getNotesSelectSql();
|
$qb = $this->getNotesSelectSql();
|
||||||
$this->limitToIdString($qb, $id);
|
$this->limitToIdString($qb, $id);
|
||||||
|
|
||||||
|
if ($asViewer) {
|
||||||
|
$this->limitToViewer($qb);
|
||||||
|
}
|
||||||
|
|
||||||
$cursor = $qb->execute();
|
$cursor = $qb->execute();
|
||||||
$data = $cursor->fetch();
|
$data = $cursor->fetch();
|
||||||
$cursor->closeCursor();
|
$cursor->closeCursor();
|
||||||
|
@ -435,5 +397,66 @@ class NotesRequest extends NotesRequestBuilder {
|
||||||
$qb->execute();
|
$qb->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Insert a new Note in the database.
|
||||||
|
*
|
||||||
|
* @param Stream $note
|
||||||
|
*
|
||||||
|
* @return IQueryBuilder
|
||||||
|
*/
|
||||||
|
public function saveStream(Stream $note): IQueryBuilder {
|
||||||
|
$dTime = new DateTime();
|
||||||
|
$dTime->setTimestamp($note->getPublishedTime());
|
||||||
|
|
||||||
|
$cache = '[]';
|
||||||
|
if ($note->gotCache()) {
|
||||||
|
$cache = json_encode($note->getCache(), JSON_UNESCAPED_SLASHES);
|
||||||
|
}
|
||||||
|
|
||||||
|
$qb = $this->getNotesInsertSql();
|
||||||
|
$qb->setValue('id', $qb->createNamedParameter($note->getId()))
|
||||||
|
->setValue('type', $qb->createNamedParameter($note->getType()))
|
||||||
|
->setValue('to', $qb->createNamedParameter($note->getTo()))
|
||||||
|
->setValue(
|
||||||
|
'to_array', $qb->createNamedParameter(
|
||||||
|
json_encode($note->getToArray(), JSON_UNESCAPED_SLASHES)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
->setValue(
|
||||||
|
'cc', $qb->createNamedParameter(
|
||||||
|
json_encode($note->getCcArray(), JSON_UNESCAPED_SLASHES)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
->setValue(
|
||||||
|
'bcc', $qb->createNamedParameter(
|
||||||
|
json_encode($note->getBccArray()), JSON_UNESCAPED_SLASHES
|
||||||
|
)
|
||||||
|
)
|
||||||
|
->setValue('content', $qb->createNamedParameter($note->getContent()))
|
||||||
|
->setValue('summary', $qb->createNamedParameter($note->getSummary()))
|
||||||
|
->setValue('published', $qb->createNamedParameter($note->getPublished()))
|
||||||
|
->setValue(
|
||||||
|
'published_time', $qb->createNamedParameter($dTime, IQueryBuilder::PARAM_DATE)
|
||||||
|
)
|
||||||
|
->setValue('attributed_to', $qb->createNamedParameter($note->getAttributedTo()))
|
||||||
|
->setValue('in_reply_to', $qb->createNamedParameter($note->getInReplyTo()))
|
||||||
|
->setValue('source', $qb->createNamedParameter($note->getSource()))
|
||||||
|
->setValue('object_id', $qb->createNamedParameter($note->getObjectId()))
|
||||||
|
->setValue('cache', $qb->createNamedParameter($cache))
|
||||||
|
->setValue(
|
||||||
|
'instances', $qb->createNamedParameter(
|
||||||
|
json_encode($note->getInstancePaths(), JSON_UNESCAPED_SLASHES)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
->setValue('local', $qb->createNamedParameter(($note->isLocal()) ? '1' : '0'))
|
||||||
|
->setValue(
|
||||||
|
'creation',
|
||||||
|
$qb->createNamedParameter(new DateTime('now'), IQueryBuilder::PARAM_DATE)
|
||||||
|
);
|
||||||
|
|
||||||
|
return $qb;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ namespace OCA\Social\Db;
|
||||||
use daita\MySmallPhpTools\Traits\TArrayTools;
|
use daita\MySmallPhpTools\Traits\TArrayTools;
|
||||||
use Doctrine\DBAL\Query\QueryBuilder;
|
use Doctrine\DBAL\Query\QueryBuilder;
|
||||||
use OCA\Social\Exceptions\InvalidResourceException;
|
use OCA\Social\Exceptions\InvalidResourceException;
|
||||||
|
use OCA\Social\Model\ActivityPub\ACore;
|
||||||
use OCA\Social\Model\ActivityPub\Actor\Person;
|
use OCA\Social\Model\ActivityPub\Actor\Person;
|
||||||
use OCA\Social\Model\ActivityPub\Object\Note;
|
use OCA\Social\Model\ActivityPub\Object\Note;
|
||||||
use OCA\Social\Model\InstancePath;
|
use OCA\Social\Model\InstancePath;
|
||||||
|
@ -124,6 +125,19 @@ class NotesRequestBuilder extends CoreRequestBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param IQueryBuilder $qb
|
||||||
|
*/
|
||||||
|
protected function limitToViewer(IQueryBuilder $qb) {
|
||||||
|
$actor = $this->viewer;
|
||||||
|
|
||||||
|
$on = $this->exprJoinFollowing($qb, $actor, false);
|
||||||
|
$on->add($this->exprLimitToRecipient($qb, ACore::CONTEXT_PUBLIC, false));
|
||||||
|
$on->add($this->exprLimitToRecipient($qb, $actor->getId(), true));
|
||||||
|
$qb->join($this->defaultSelectAlias, CoreRequestBuilder::TABLE_SERVER_FOLLOWS, 'f', $on);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param IQueryBuilder $qb
|
* @param IQueryBuilder $qb
|
||||||
* @param Person $actor
|
* @param Person $actor
|
||||||
|
@ -143,15 +157,19 @@ class NotesRequestBuilder extends CoreRequestBuilder {
|
||||||
* @param IQueryBuilder $qb
|
* @param IQueryBuilder $qb
|
||||||
* @param Person $actor
|
* @param Person $actor
|
||||||
*
|
*
|
||||||
|
* @param bool $followers
|
||||||
|
*
|
||||||
* @return ICompositeExpression
|
* @return ICompositeExpression
|
||||||
*/
|
*/
|
||||||
protected function exprJoinFollowing(IQueryBuilder $qb, Person $actor) {
|
protected function exprJoinFollowing(IQueryBuilder $qb, Person $actor, bool $followers = true) {
|
||||||
$expr = $qb->expr();
|
$expr = $qb->expr();
|
||||||
$func = $qb->func();
|
$func = $qb->func();
|
||||||
$pf = $this->defaultSelectAlias . '.';
|
$pf = $this->defaultSelectAlias . '.';
|
||||||
|
|
||||||
$on = $expr->orX();
|
$on = $expr->orX();
|
||||||
|
if ($followers) {
|
||||||
$on->add($this->exprLimitToRecipient($qb, $actor->getFollowers(), false));
|
$on->add($this->exprLimitToRecipient($qb, $actor->getFollowers(), false));
|
||||||
|
}
|
||||||
|
|
||||||
// list of possible recipient as a follower (to, to_array, cc, ...)
|
// list of possible recipient as a follower (to, to_array, cc, ...)
|
||||||
$recipientFields = $expr->orX();
|
$recipientFields = $expr->orX();
|
||||||
|
|
|
@ -669,7 +669,10 @@ class ACore extends Item implements JsonSerializable {
|
||||||
$this->addEntryBool('local', $this->isLocal());
|
$this->addEntryBool('local', $this->isLocal());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->getEntries();
|
$result = $this->getEntries();
|
||||||
|
$this->cleanArray($result);
|
||||||
|
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,8 +64,6 @@ class Announce extends Stream implements JsonSerializable {
|
||||||
*/
|
*/
|
||||||
public function import(array $data) {
|
public function import(array $data) {
|
||||||
parent::import($data);
|
parent::import($data);
|
||||||
|
|
||||||
$this->setAttributedTo($this->getActorId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -121,6 +121,8 @@ class Note extends Stream implements JsonSerializable {
|
||||||
$result['hashtags'] = $this->getHashtags();
|
$result['hashtags'] = $this->getHashtags();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->cleanArray($result);
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -293,13 +293,13 @@ class Stream extends ACore implements JsonSerializable {
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function jsonSerialize(): array {
|
public function jsonSerialize(): array {
|
||||||
$this->addEntryInt('publishedTime', $this->getPublishedTime());
|
|
||||||
|
|
||||||
$result = array_merge(
|
$result = array_merge(
|
||||||
parent::jsonSerialize(),
|
parent::jsonSerialize(),
|
||||||
[
|
[
|
||||||
'content' => $this->getContent(),
|
'content' => $this->getContent(),
|
||||||
'attributedTo' => $this->getUrlSocial() . $this->getAttributedTo(),
|
'attributedTo' => ($this->getAttributedTo() !== '') ? $this->getUrlSocial()
|
||||||
|
. $this->getAttributedTo(
|
||||||
|
) : '',
|
||||||
'inReplyTo' => $this->getInReplyTo(),
|
'inReplyTo' => $this->getInReplyTo(),
|
||||||
'sensitive' => $this->isSensitive(),
|
'sensitive' => $this->isSensitive(),
|
||||||
'conversation' => $this->getConversation()
|
'conversation' => $this->getConversation()
|
||||||
|
@ -310,11 +310,14 @@ class Stream extends ACore implements JsonSerializable {
|
||||||
$result = array_merge(
|
$result = array_merge(
|
||||||
$result,
|
$result,
|
||||||
[
|
[
|
||||||
'cache' => $this->getCache()
|
'cache' => ($this->gotCache()) ? $this->getCache() : '',
|
||||||
|
'publishedTime' => $this->getPublishedTime()
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->cleanArray($result);
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -293,12 +293,7 @@ class LinkedDataSignature implements JsonSerializable {
|
||||||
*/
|
*/
|
||||||
private function hashedCanonicalize(array $data, bool $removeEmptyValue = false): string {
|
private function hashedCanonicalize(array $data, bool $removeEmptyValue = false): string {
|
||||||
if ($removeEmptyValue) {
|
if ($removeEmptyValue) {
|
||||||
$data = array_filter(
|
$this->cleanArray($data);
|
||||||
$data,
|
|
||||||
function($v) {
|
|
||||||
return ($v !== '');
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$object = json_decode(json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
|
$object = json_decode(json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
|
||||||
|
|
|
@ -65,10 +65,6 @@ class ActorService {
|
||||||
private $miscService;
|
private $miscService;
|
||||||
|
|
||||||
|
|
||||||
/** @var string */
|
|
||||||
private $viewerId = '';
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ActorService constructor.
|
* ActorService constructor.
|
||||||
*
|
*
|
||||||
|
@ -92,19 +88,6 @@ class ActorService {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $viewerId
|
|
||||||
*/
|
|
||||||
public function setViewerId(string $viewerId) {
|
|
||||||
$this->viewerId = $viewerId;
|
|
||||||
$this->cacheActorsRequest->setViewerId($viewerId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getViewerId(): string {
|
|
||||||
return $this->viewerId;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Person $actor
|
* @param Person $actor
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -69,8 +69,8 @@ class CacheActorService {
|
||||||
private $miscService;
|
private $miscService;
|
||||||
|
|
||||||
|
|
||||||
/** @var string */
|
/** @var Person */
|
||||||
private $viewerId;
|
private $viewer = null;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -93,15 +93,11 @@ class CacheActorService {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $viewerId
|
* @param Person $viewer
|
||||||
*/
|
*/
|
||||||
public function setViewerId(string $viewerId) {
|
public function setViewer(Person $viewer) {
|
||||||
$this->viewerId = $viewerId;
|
$this->viewer = $viewer;
|
||||||
$this->cacheActorsRequest->setViewerId($viewerId);
|
$this->cacheActorsRequest->setViewer($viewer);
|
||||||
}
|
|
||||||
|
|
||||||
public function getViewerId(): string {
|
|
||||||
return $this->viewerId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -171,6 +167,7 @@ class CacheActorService {
|
||||||
if (strrpos($account, '@')) {
|
if (strrpos($account, '@')) {
|
||||||
$account = substr($account, 0, strrpos($account, '@'));
|
$account = substr($account, 0, strrpos($account, '@'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->cacheActorsRequest->getFromLocalAccount($account);
|
return $this->cacheActorsRequest->getFromLocalAccount($account);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,8 +77,8 @@ class FollowService {
|
||||||
private $miscService;
|
private $miscService;
|
||||||
|
|
||||||
|
|
||||||
/** @var string */
|
/** @var Person */
|
||||||
private $viewerId = '';
|
private $viewer = null;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -104,15 +104,11 @@ class FollowService {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $viewerId
|
* @param Person $viewer
|
||||||
*/
|
*/
|
||||||
public function setViewerId(string $viewerId) {
|
public function setViewer(Person $viewer) {
|
||||||
$this->viewerId = $viewerId;
|
$this->viewer = $viewer;
|
||||||
$this->followsRequest->setViewerId($viewerId);
|
$this->followsRequest->setViewer($viewer);
|
||||||
}
|
|
||||||
|
|
||||||
public function getViewerId(): string {
|
|
||||||
return $this->viewerId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,9 @@ use OCA\Social\Exceptions\RequestServerException;
|
||||||
use OCA\Social\Exceptions\SocialAppConfigException;
|
use OCA\Social\Exceptions\SocialAppConfigException;
|
||||||
use OCA\Social\Model\ActivityPub\ACore;
|
use OCA\Social\Model\ActivityPub\ACore;
|
||||||
use OCA\Social\Model\ActivityPub\Actor\Person;
|
use OCA\Social\Model\ActivityPub\Actor\Person;
|
||||||
|
use OCA\Social\Model\ActivityPub\Object\Announce;
|
||||||
use OCA\Social\Model\ActivityPub\Object\Note;
|
use OCA\Social\Model\ActivityPub\Object\Note;
|
||||||
|
use OCA\Social\Model\ActivityPub\Stream;
|
||||||
use OCA\Social\Model\InstancePath;
|
use OCA\Social\Model\InstancePath;
|
||||||
|
|
||||||
class NoteService {
|
class NoteService {
|
||||||
|
@ -61,6 +63,9 @@ class NoteService {
|
||||||
/** @var AccountService */
|
/** @var AccountService */
|
||||||
private $accountService;
|
private $accountService;
|
||||||
|
|
||||||
|
/** @var SignatureService */
|
||||||
|
private $signatureService;
|
||||||
|
|
||||||
/** @var CacheActorService */
|
/** @var CacheActorService */
|
||||||
private $cacheActorService;
|
private $cacheActorService;
|
||||||
|
|
||||||
|
@ -71,8 +76,8 @@ class NoteService {
|
||||||
private $miscService;
|
private $miscService;
|
||||||
|
|
||||||
|
|
||||||
/** @var string */
|
/** @var Person */
|
||||||
private $viewerId = '';
|
private $viewer = null;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -81,18 +86,20 @@ class NoteService {
|
||||||
* @param NotesRequest $notesRequest
|
* @param NotesRequest $notesRequest
|
||||||
* @param ActivityService $activityService
|
* @param ActivityService $activityService
|
||||||
* @param AccountService $accountService
|
* @param AccountService $accountService
|
||||||
|
* @param SignatureService $signatureService
|
||||||
* @param CacheActorService $cacheActorService
|
* @param CacheActorService $cacheActorService
|
||||||
* @param ConfigService $configService
|
* @param ConfigService $configService
|
||||||
* @param MiscService $miscService
|
* @param MiscService $miscService
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
NotesRequest $notesRequest, ActivityService $activityService,
|
NotesRequest $notesRequest, ActivityService $activityService,
|
||||||
AccountService $accountService, CacheActorService $cacheActorService,
|
AccountService $accountService, SignatureService $signatureService,
|
||||||
ConfigService $configService, MiscService $miscService
|
CacheActorService $cacheActorService, ConfigService $configService, MiscService $miscService
|
||||||
) {
|
) {
|
||||||
$this->notesRequest = $notesRequest;
|
$this->notesRequest = $notesRequest;
|
||||||
$this->activityService = $activityService;
|
$this->activityService = $activityService;
|
||||||
$this->accountService = $accountService;
|
$this->accountService = $accountService;
|
||||||
|
$this->signatureService = $signatureService;
|
||||||
$this->cacheActorService = $cacheActorService;
|
$this->cacheActorService = $cacheActorService;
|
||||||
$this->configService = $configService;
|
$this->configService = $configService;
|
||||||
$this->miscService = $miscService;
|
$this->miscService = $miscService;
|
||||||
|
@ -100,65 +107,84 @@ class NoteService {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $viewerId
|
* @param Person $viewer
|
||||||
*/
|
*/
|
||||||
public function setViewerId(string $viewerId) {
|
public function setViewer(Person $viewer) {
|
||||||
$this->viewerId = $viewerId;
|
$this->viewer = $viewer;
|
||||||
$this->notesRequest->setViewerId($viewerId);
|
$this->notesRequest->setViewer($viewer);
|
||||||
}
|
|
||||||
|
|
||||||
public function getViewerId(): string {
|
|
||||||
return $this->viewerId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Person $actor
|
* @param Person $actor
|
||||||
* @param string $content
|
* @param string $postId
|
||||||
|
* @param ACore|null $announce
|
||||||
*
|
*
|
||||||
* @param string $type
|
* @return string
|
||||||
*
|
* @throws NoteNotFoundException
|
||||||
* @return Note
|
|
||||||
* @throws SocialAppConfigException
|
* @throws SocialAppConfigException
|
||||||
*/
|
*/
|
||||||
public function generateNote(Person $actor, string $content, string $type) {
|
public function createBoost(Person $actor, string $postId, ACore &$announce = null): string {
|
||||||
$note = new Note();
|
|
||||||
$note->setId($this->configService->generateId('@' . $actor->getPreferredUsername()));
|
|
||||||
$note->setPublished(date("c"));
|
|
||||||
$note->setAttributedTo(
|
|
||||||
$this->configService->getUrlSocial() . '@' . $actor->getPreferredUsername()
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->setRecipient($note, $actor, $type);
|
$announce = new Announce();
|
||||||
$note->setContent($content);
|
$this->assignStream($announce, $actor, Stream::TYPE_PUBLIC);
|
||||||
$note->convertPublished();
|
|
||||||
$note->setLocal(true);
|
|
||||||
|
|
||||||
return $note;
|
$announce->setActor($actor);
|
||||||
|
$note = $this->getNoteById($postId, true);
|
||||||
|
|
||||||
|
$announce->addCc($note->getAttributedTo());
|
||||||
|
if ($note->isLocal()) {
|
||||||
|
$announce->setObject($note);
|
||||||
|
} else {
|
||||||
|
$announce->setObjectId($note->getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->signatureService->signObject($actor, $announce);
|
||||||
|
$this->notesRequest->save($announce);
|
||||||
|
$token = $this->activityService->request($announce);
|
||||||
|
|
||||||
|
return $token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Note $note
|
* @param Stream $stream
|
||||||
|
* @param Person $actor
|
||||||
|
* @param string $type
|
||||||
|
*
|
||||||
|
* @throws SocialAppConfigException
|
||||||
|
*/
|
||||||
|
public function assignStream(Stream &$stream, Person $actor, string $type) {
|
||||||
|
$stream->setId($this->configService->generateId('@' . $actor->getPreferredUsername()));
|
||||||
|
$stream->setPublished(date("c"));
|
||||||
|
|
||||||
|
$this->setRecipient($stream, $actor, $type);
|
||||||
|
$stream->convertPublished();
|
||||||
|
$stream->setLocal(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Stream $stream
|
||||||
* @param Person $actor
|
* @param Person $actor
|
||||||
* @param string $type
|
* @param string $type
|
||||||
*/
|
*/
|
||||||
private function setRecipient(Note $note, Person $actor, string $type) {
|
private function setRecipient(Stream $stream, Person $actor, string $type) {
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case Note::TYPE_UNLISTED:
|
case Note::TYPE_UNLISTED:
|
||||||
$note->setTo($actor->getFollowers());
|
$stream->setTo($actor->getFollowers());
|
||||||
$note->addInstancePath(
|
$stream->addInstancePath(
|
||||||
new InstancePath(
|
new InstancePath(
|
||||||
$actor->getFollowers(), InstancePath::TYPE_FOLLOWERS,
|
$actor->getFollowers(), InstancePath::TYPE_FOLLOWERS,
|
||||||
InstancePath::PRIORITY_LOW
|
InstancePath::PRIORITY_LOW
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$note->addCc(ACore::CONTEXT_PUBLIC);
|
$stream->addCc(ACore::CONTEXT_PUBLIC);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Note::TYPE_FOLLOWERS:
|
case Note::TYPE_FOLLOWERS:
|
||||||
$note->setTo($actor->getFollowers());
|
$stream->setTo($actor->getFollowers());
|
||||||
$note->addInstancePath(
|
$stream->addInstancePath(
|
||||||
new InstancePath(
|
new InstancePath(
|
||||||
$actor->getFollowers(), InstancePath::TYPE_FOLLOWERS,
|
$actor->getFollowers(), InstancePath::TYPE_FOLLOWERS,
|
||||||
InstancePath::PRIORITY_LOW
|
InstancePath::PRIORITY_LOW
|
||||||
|
@ -170,9 +196,9 @@ class NoteService {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
$note->setTo(ACore::CONTEXT_PUBLIC);
|
$stream->setTo(ACore::CONTEXT_PUBLIC);
|
||||||
$note->addCc($actor->getFollowers());
|
$stream->addCc($actor->getFollowers());
|
||||||
$note->addInstancePath(
|
$stream->addInstancePath(
|
||||||
new InstancePath(
|
new InstancePath(
|
||||||
$actor->getFollowers(), InstancePath::TYPE_FOLLOWERS,
|
$actor->getFollowers(), InstancePath::TYPE_FOLLOWERS,
|
||||||
InstancePath::PRIORITY_LOW
|
InstancePath::PRIORITY_LOW
|
||||||
|
@ -184,11 +210,11 @@ class NoteService {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Note $note
|
* @param Stream $stream
|
||||||
* @param string $type
|
* @param string $type
|
||||||
* @param string $account
|
* @param string $account
|
||||||
*/
|
*/
|
||||||
public function addRecipient(Note $note, string $type, string $account) {
|
public function addRecipient(Stream $stream, string $type, string $account) {
|
||||||
if ($account === '') {
|
if ($account === '') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -204,12 +230,12 @@ class NoteService {
|
||||||
);
|
);
|
||||||
if ($type === Note::TYPE_DIRECT) {
|
if ($type === Note::TYPE_DIRECT) {
|
||||||
$instancePath->setPriority(InstancePath::PRIORITY_HIGH);
|
$instancePath->setPriority(InstancePath::PRIORITY_HIGH);
|
||||||
$note->addToArray($actor->getId());
|
$stream->addToArray($actor->getId());
|
||||||
} else {
|
} else {
|
||||||
$note->addCc($actor->getId());
|
$stream->addCc($actor->getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
$note->addTag(
|
$stream->addTag(
|
||||||
[
|
[
|
||||||
'type' => 'Mention',
|
'type' => 'Mention',
|
||||||
'href' => $actor->getId(),
|
'href' => $actor->getId(),
|
||||||
|
@ -217,7 +243,7 @@ class NoteService {
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
$note->addInstancePath($instancePath);
|
$stream->addInstancePath($instancePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -242,13 +268,13 @@ class NoteService {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Note $note
|
* @param Stream $stream
|
||||||
* @param string $type
|
* @param string $type
|
||||||
* @param array $accounts
|
* @param array $accounts
|
||||||
*/
|
*/
|
||||||
public function addRecipients(Note $note, string $type, array $accounts) {
|
public function addRecipients(Stream $stream, string $type, array $accounts) {
|
||||||
foreach ($accounts as $account) {
|
foreach ($accounts as $account) {
|
||||||
$this->addRecipient($note, $type, $account);
|
$this->addRecipient($stream, $type, $account);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -316,12 +342,13 @@ class NoteService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $id
|
* @param string $id
|
||||||
|
* @param bool $asViewer
|
||||||
*
|
*
|
||||||
* @return Note
|
* @return Note
|
||||||
* @throws NoteNotFoundException
|
* @throws NoteNotFoundException
|
||||||
*/
|
*/
|
||||||
public function getNoteById(string $id): Note {
|
public function getNoteById(string $id, bool $asViewer = false): Note {
|
||||||
return $this->notesRequest->getNoteById($id);
|
return $this->notesRequest->getNoteById($id, $asViewer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -392,7 +419,8 @@ class NoteService {
|
||||||
*
|
*
|
||||||
* @return Note[]
|
* @return Note[]
|
||||||
*/
|
*/
|
||||||
public function getStreamLocalTag(Person $actor, string $hashtag, int $since = 0, int $limit = 5): array {
|
public function getStreamLocalTag(Person $actor, string $hashtag, int $since = 0, int $limit = 5
|
||||||
|
): array {
|
||||||
return $this->notesRequest->getStreamTag($actor, $hashtag, $since, $limit);
|
return $this->notesRequest->getStreamTag($actor, $hashtag, $since, $limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -409,7 +437,8 @@ class NoteService {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**m
|
||||||
|
*
|
||||||
* @param int $since
|
* @param int $since
|
||||||
* @param int $limit
|
* @param int $limit
|
||||||
*
|
*
|
||||||
|
@ -443,5 +472,6 @@ class NoteService {
|
||||||
return $this->cacheActorService->getFromId($note->getAttributedTo());
|
return $this->cacheActorService->getFromId($note->getAttributedTo());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,10 +38,12 @@ use OCA\Social\Exceptions\NoteNotFoundException;
|
||||||
use OCA\Social\Exceptions\RedundancyLimitException;
|
use OCA\Social\Exceptions\RedundancyLimitException;
|
||||||
use OCA\Social\Exceptions\RequestContentException;
|
use OCA\Social\Exceptions\RequestContentException;
|
||||||
use OCA\Social\Exceptions\RequestNetworkException;
|
use OCA\Social\Exceptions\RequestNetworkException;
|
||||||
|
use OCA\Social\Exceptions\RequestResultNotJsonException;
|
||||||
use OCA\Social\Exceptions\RequestResultSizeException;
|
use OCA\Social\Exceptions\RequestResultSizeException;
|
||||||
use OCA\Social\Exceptions\RequestServerException;
|
use OCA\Social\Exceptions\RequestServerException;
|
||||||
use OCA\Social\Exceptions\SocialAppConfigException;
|
use OCA\Social\Exceptions\SocialAppConfigException;
|
||||||
use OCA\Social\Model\ActivityPub\ACore;
|
use OCA\Social\Model\ActivityPub\ACore;
|
||||||
|
use OCA\Social\Model\ActivityPub\Object\Note;
|
||||||
use OCA\Social\Model\Post;
|
use OCA\Social\Model\Post;
|
||||||
|
|
||||||
class PostService {
|
class PostService {
|
||||||
|
@ -56,6 +58,9 @@ class PostService {
|
||||||
/** @var ActivityService */
|
/** @var ActivityService */
|
||||||
private $activityService;
|
private $activityService;
|
||||||
|
|
||||||
|
/** @var ConfigService */
|
||||||
|
private $configService;
|
||||||
|
|
||||||
/** @var MiscService */
|
/** @var MiscService */
|
||||||
private $miscService;
|
private $miscService;
|
||||||
|
|
||||||
|
@ -66,15 +71,17 @@ class PostService {
|
||||||
* @param NoteService $noteService
|
* @param NoteService $noteService
|
||||||
* @param AccountService $accountService
|
* @param AccountService $accountService
|
||||||
* @param ActivityService $activityService
|
* @param ActivityService $activityService
|
||||||
|
* @param ConfigService $configService
|
||||||
* @param MiscService $miscService
|
* @param MiscService $miscService
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
NoteService $noteService, AccountService $accountService, ActivityService $activityService,
|
NoteService $noteService, AccountService $accountService, ActivityService $activityService,
|
||||||
MiscService $miscService
|
ConfigService $configService, MiscService $miscService
|
||||||
) {
|
) {
|
||||||
$this->noteService = $noteService;
|
$this->noteService = $noteService;
|
||||||
$this->accountService = $accountService;
|
$this->accountService = $accountService;
|
||||||
$this->activityService = $activityService;
|
$this->activityService = $activityService;
|
||||||
|
$this->configService = $configService;
|
||||||
$this->miscService = $miscService;
|
$this->miscService = $miscService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,13 +102,17 @@ class PostService {
|
||||||
* @throws RequestResultSizeException
|
* @throws RequestResultSizeException
|
||||||
* @throws RequestServerException
|
* @throws RequestServerException
|
||||||
* @throws MalformedArrayException
|
* @throws MalformedArrayException
|
||||||
|
* @throws RequestResultNotJsonException
|
||||||
*/
|
*/
|
||||||
public function createPost(Post $post, ACore &$activity = null): string {
|
public function createPost(Post $post, ACore &$activity = null): string {
|
||||||
$note =
|
$note = new Note();
|
||||||
$this->noteService->generateNote(
|
$this->noteService->assignStream($note, $post->getActor(), $post->getType());
|
||||||
$post->getActor(), htmlentities($post->getContent(), ENT_QUOTES), $post->getType()
|
$note->setAttributedTo(
|
||||||
|
$this->configService->getUrlSocial() . '@' . $actor->getPreferredUsername()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$note->setContent(htmlentities($post->getContent(), ENT_QUOTES));
|
||||||
|
|
||||||
$this->noteService->replyTo($note, $post->getReplyTo());
|
$this->noteService->replyTo($note, $post->getReplyTo());
|
||||||
$this->noteService->addRecipients($note, $post->getType(), $post->getTo());
|
$this->noteService->addRecipients($note, $post->getType(), $post->getTo());
|
||||||
$this->noteService->addHashtags($note, $post->getHashtags());
|
$this->noteService->addHashtags($note, $post->getHashtags());
|
||||||
|
|
Ładowanie…
Reference in New Issue