kopia lustrzana https://github.com/nextcloud/social
Notes -> Stream
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>pull/524/head
rodzic
7d5ea91b58
commit
d16537b403
|
@ -35,6 +35,7 @@ use DateInterval;
|
|||
use DateTime;
|
||||
use Doctrine\DBAL\Query\QueryBuilder;
|
||||
use Exception;
|
||||
use OCA\Social\Exceptions\DateTimeException;
|
||||
use OCA\Social\Exceptions\InvalidResourceException;
|
||||
use OCA\Social\Model\ActivityPub\Actor\Person;
|
||||
use OCA\Social\Model\ActivityPub\Object\Document;
|
||||
|
@ -587,10 +588,15 @@ class CoreRequestBuilder {
|
|||
* @param int $timestamp
|
||||
* @param string $field
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws DateTimeException
|
||||
*/
|
||||
protected function limitToSince(IQueryBuilder $qb, int $timestamp, string $field) {
|
||||
$dTime = new DateTime();
|
||||
try {
|
||||
$dTime = new DateTime();
|
||||
} catch (Exception $e) {
|
||||
throw new DateTimeException();
|
||||
}
|
||||
|
||||
$dTime->setTimestamp($timestamp);
|
||||
|
||||
$expr = $qb->expr();
|
||||
|
|
|
@ -34,7 +34,8 @@ use daita\MySmallPhpTools\Model\Cache;
|
|||
use DateTime;
|
||||
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
|
||||
use Exception;
|
||||
use OCA\Social\Exceptions\NoteNotFoundException;
|
||||
use OCA\Social\Exceptions\DateTimeException;
|
||||
use OCA\Social\Exceptions\StreamNotFoundException;
|
||||
use OCA\Social\Model\ActivityPub\ACore;
|
||||
use OCA\Social\Model\ActivityPub\Actor\Person;
|
||||
use OCA\Social\Model\ActivityPub\Object\Note;
|
||||
|
@ -44,11 +45,17 @@ use OCA\Social\Service\MiscService;
|
|||
use OCP\DB\QueryBuilder\IQueryBuilder;
|
||||
use OCP\IDBConnection;
|
||||
|
||||
class NotesRequest extends NotesRequestBuilder {
|
||||
|
||||
/**
|
||||
* Class StreamRequest
|
||||
*
|
||||
* @package OCA\Social\Db
|
||||
*/
|
||||
class StreamRequest extends StreamRequestBuilder {
|
||||
|
||||
|
||||
/**
|
||||
* NotesRequest constructor.
|
||||
* StreamRequest constructor.
|
||||
*
|
||||
* @param IDBConnection $connection
|
||||
* @param ConfigService $configService
|
||||
|
@ -63,8 +70,6 @@ class NotesRequest extends NotesRequestBuilder {
|
|||
|
||||
/**
|
||||
* @param Stream $stream
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function save(Stream $stream) {
|
||||
$qb = $this->saveStream($stream);
|
||||
|
@ -85,51 +90,12 @@ class NotesRequest extends NotesRequestBuilder {
|
|||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * Insert a new Note in the database.
|
||||
// *
|
||||
// * @param SocialAppNotification $notification
|
||||
// *
|
||||
// * @throws Exception
|
||||
// */
|
||||
// public function saveNotification(SocialAppNotification $notification) {
|
||||
// $qb = $this->getNotesInsertSql();
|
||||
// $qb->setValue('id', $qb->createNamedParameter($notification->getId()))
|
||||
// ->setValue('type', $qb->createNamedParameter($notification->getType()))
|
||||
// ->setValue('to', $qb->createNamedParameter($notification->getTo()))
|
||||
// ->setValue('to_array', $qb->createNamedParameter(''))
|
||||
// ->setValue('cc', $qb->createNamedParameter(''))
|
||||
// ->setValue('bcc', $qb->createNamedParameter(''))
|
||||
// ->setValue('content', $qb->createNamedParameter(''))
|
||||
// ->setValue('summary', $qb->createNamedParameter($notification->getSummary()))
|
||||
// ->setValue('published', $qb->createNamedParameter($notification->getPublished()))
|
||||
// ->setValue(
|
||||
// 'published_time',
|
||||
// $qb->createNamedParameter(new DateTime('now'), IQueryBuilder::PARAM_DATE)
|
||||
// )
|
||||
// ->setValue('attributed_to', $qb->createNamedParameter($notification->getAttributedTo()))
|
||||
// ->setValue('in_reply_to', $qb->createNamedParameter(''))
|
||||
// ->setValue('source', $qb->createNamedParameter($notification->getSource()))
|
||||
// ->setValue('instances', $qb->createNamedParameter(''))
|
||||
// ->setValue('local', $qb->createNamedParameter(($notification->isLocal()) ? '1' : '0'))
|
||||
// ->setValue(
|
||||
// 'creation',
|
||||
// $qb->createNamedParameter(new DateTime('now'), IQueryBuilder::PARAM_DATE)
|
||||
// );
|
||||
//
|
||||
// $qb->execute();
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* @param Stream $stream
|
||||
* @param Cache $cache
|
||||
*/
|
||||
public function updateCache(Stream $stream, Cache $cache) {
|
||||
$qb = $this->getNotesUpdateSql();
|
||||
$qb = $this->getStreamUpdateSql();
|
||||
$qb->set('cache', $qb->createNamedParameter(json_encode($cache, JSON_UNESCAPED_SLASHES)));
|
||||
|
||||
$this->limitToIdString($qb, $stream->getId());
|
||||
|
@ -146,14 +112,14 @@ class NotesRequest extends NotesRequestBuilder {
|
|||
* @param bool $asViewer
|
||||
*
|
||||
* @return Stream
|
||||
* @throws NoteNotFoundException
|
||||
* @throws StreamNotFoundException
|
||||
*/
|
||||
public function getNoteById(string $id, bool $asViewer = false): Stream {
|
||||
public function getStreamById(string $id, bool $asViewer = false): Stream {
|
||||
if ($id === '') {
|
||||
throw new NoteNotFoundException();
|
||||
throw new StreamNotFoundException();
|
||||
};
|
||||
|
||||
$qb = $this->getNotesSelectSql();
|
||||
$qb = $this->getStreamSelectSql();
|
||||
$this->limitToIdString($qb, $id);
|
||||
$this->leftJoinCacheActors($qb, 'attributed_to');
|
||||
|
||||
|
@ -167,17 +133,16 @@ class NotesRequest extends NotesRequestBuilder {
|
|||
$cursor->closeCursor();
|
||||
|
||||
if ($data === false) {
|
||||
throw new NoteNotFoundException('Post not found');
|
||||
throw new StreamNotFoundException('Stream not found');
|
||||
}
|
||||
|
||||
try {
|
||||
/** @var Note $note */
|
||||
$note = $this->parseNotesSelectSql($data);
|
||||
$stream = $this->parseStreamSelectSql($data);
|
||||
} catch (Exception $e) {
|
||||
throw new NoteNotFoundException('Malformed Post');
|
||||
throw new StreamNotFoundException('Malformed Stream');
|
||||
}
|
||||
|
||||
return $note;
|
||||
return $stream;
|
||||
}
|
||||
|
||||
|
||||
|
@ -185,15 +150,15 @@ class NotesRequest extends NotesRequestBuilder {
|
|||
* @param string $id
|
||||
*
|
||||
* @return Stream
|
||||
* @throws NoteNotFoundException
|
||||
* @throws StreamNotFoundException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getNoteByActivityId(string $id): Stream {
|
||||
public function getStreamByActivityId(string $id): Stream {
|
||||
if ($id === '') {
|
||||
throw new NoteNotFoundException();
|
||||
throw new StreamNotFoundException();
|
||||
};
|
||||
|
||||
$qb = $this->getNotesSelectSql();
|
||||
$qb = $this->getStreamSelectSql();
|
||||
$this->limitToActivityId($qb, $id);
|
||||
|
||||
$cursor = $qb->execute();
|
||||
|
@ -201,10 +166,10 @@ class NotesRequest extends NotesRequestBuilder {
|
|||
$cursor->closeCursor();
|
||||
|
||||
if ($data === false) {
|
||||
throw new NoteNotFoundException('Post not found');
|
||||
throw new StreamNotFoundException('Stream not found');
|
||||
}
|
||||
|
||||
return $this->parseNotesSelectSql($data);
|
||||
return $this->parseStreamSelectSql($data);
|
||||
}
|
||||
|
||||
|
||||
|
@ -215,14 +180,14 @@ class NotesRequest extends NotesRequestBuilder {
|
|||
* @param string $objectId
|
||||
*
|
||||
* @return Stream
|
||||
* @throws NoteNotFoundException
|
||||
* @throws StreamNotFoundException
|
||||
*/
|
||||
public function getNoteByObjectId(Person $actor, string $type, string $objectId): Stream {
|
||||
public function getStreamByObjectId(Person $actor, string $type, string $objectId): Stream {
|
||||
if ($objectId === '') {
|
||||
throw new NoteNotFoundException('missing objectId');
|
||||
throw new StreamNotFoundException('missing objectId');
|
||||
};
|
||||
|
||||
$qb = $this->getNotesSelectSql();
|
||||
$qb = $this->getStreamSelectSql();
|
||||
$this->limitToObjectId($qb, $objectId);
|
||||
$this->limitToType($qb, $type);
|
||||
$this->limitToAttributedTo($qb, $actor->getId());
|
||||
|
@ -232,13 +197,13 @@ class NotesRequest extends NotesRequestBuilder {
|
|||
$cursor->closeCursor();
|
||||
|
||||
if ($data === false) {
|
||||
throw new NoteNotFoundException(
|
||||
throw new StreamNotFoundException(
|
||||
'StreamByObjectId not found - ' . $actor->getId() . ' - ' . $type . ' - '
|
||||
. $objectId
|
||||
);
|
||||
}
|
||||
|
||||
return $this->parseNotesSelectSql($data);
|
||||
return $this->parseStreamSelectSql($data);
|
||||
}
|
||||
|
||||
|
||||
|
@ -273,25 +238,24 @@ class NotesRequest extends NotesRequestBuilder {
|
|||
* @throws Exception
|
||||
*/
|
||||
public function getStreamHome(Person $actor, int $since = 0, int $limit = 5): array {
|
||||
$qb = $this->getNotesSelectSql();
|
||||
$qb = $this->getStreamSelectSql();
|
||||
|
||||
$this->joinFollowing($qb, $actor);
|
||||
// $this->limitToType($qb, Note::TYPE);
|
||||
$this->limitPaginate($qb, $since, $limit);
|
||||
$this->leftJoinCacheActors($qb, 'attributed_to');
|
||||
$this->leftJoinStreamAction($qb);
|
||||
|
||||
$notes = [];
|
||||
$streams = [];
|
||||
$cursor = $qb->execute();
|
||||
while ($data = $cursor->fetch()) {
|
||||
try {
|
||||
$notes[] = $this->parseNotesSelectSql($data);
|
||||
$streams[] = $this->parseStreamSelectSql($data);
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
}
|
||||
$cursor->closeCursor();
|
||||
|
||||
return $notes;
|
||||
return $streams;
|
||||
}
|
||||
|
||||
|
||||
|
@ -311,24 +275,24 @@ class NotesRequest extends NotesRequestBuilder {
|
|||
* @throws Exception
|
||||
*/
|
||||
public function getStreamNotifications(Person $actor, int $since = 0, int $limit = 5): array {
|
||||
$qb = $this->getNotesSelectSql();
|
||||
$qb = $this->getStreamSelectSql();
|
||||
|
||||
$this->limitPaginate($qb, $since, $limit);
|
||||
$this->limitToRecipient($qb, $actor->getId(), false);
|
||||
$this->leftJoinCacheActors($qb, 'attributed_to');
|
||||
$this->leftJoinStreamAction($qb);
|
||||
|
||||
$notes = [];
|
||||
$streams = [];
|
||||
$cursor = $qb->execute();
|
||||
while ($data = $cursor->fetch()) {
|
||||
try {
|
||||
$notes[] = $this->parseNotesSelectSql($data);
|
||||
$streams[] = $this->parseStreamSelectSql($data);
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
}
|
||||
$cursor->closeCursor();
|
||||
|
||||
return $notes;
|
||||
return $streams;
|
||||
}
|
||||
|
||||
|
||||
|
@ -345,26 +309,25 @@ class NotesRequest extends NotesRequestBuilder {
|
|||
* @throws Exception
|
||||
*/
|
||||
public function getStreamAccount(string $actorId, int $since = 0, int $limit = 5): array {
|
||||
$qb = $this->getNotesSelectSql();
|
||||
$qb = $this->getStreamSelectSql();
|
||||
$this->limitPaginate($qb, $since, $limit);
|
||||
// $this->limitToType($qb, Note::TYPE);
|
||||
|
||||
$this->limitToAttributedTo($qb, $actorId);
|
||||
$this->leftJoinCacheActors($qb, 'attributed_to');
|
||||
$this->limitToRecipient($qb, ACore::CONTEXT_PUBLIC);
|
||||
$this->leftJoinStreamAction($qb);
|
||||
|
||||
$notes = [];
|
||||
$streams = [];
|
||||
$cursor = $qb->execute();
|
||||
while ($data = $cursor->fetch()) {
|
||||
try {
|
||||
$notes[] = $this->parseNotesSelectSql($data);
|
||||
$streams[] = $this->parseStreamSelectSql($data);
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
}
|
||||
$cursor->closeCursor();
|
||||
|
||||
return $notes;
|
||||
return $streams;
|
||||
}
|
||||
|
||||
|
||||
|
@ -381,27 +344,26 @@ class NotesRequest extends NotesRequestBuilder {
|
|||
* @throws Exception
|
||||
*/
|
||||
public function getStreamDirect(Person $actor, int $since = 0, int $limit = 5): array {
|
||||
$qb = $this->getNotesSelectSql();
|
||||
$qb = $this->getStreamSelectSql();
|
||||
$this->limitPaginate($qb, $since, $limit);
|
||||
|
||||
// $this->limitToType($qb, Note::TYPE);
|
||||
$this->limitToRecipient($qb, $actor->getId(), true);
|
||||
$this->filterToRecipient($qb, ACore::CONTEXT_PUBLIC);
|
||||
$this->filterToRecipient($qb, $actor->getFollowers());
|
||||
|
||||
$this->leftJoinCacheActors($qb, 'attributed_to');
|
||||
|
||||
$notes = [];
|
||||
$streams = [];
|
||||
$cursor = $qb->execute();
|
||||
while ($data = $cursor->fetch()) {
|
||||
try {
|
||||
$notes[] = $this->parseNotesSelectSql($data);
|
||||
$streams[] = $this->parseStreamSelectSql($data);
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
}
|
||||
$cursor->closeCursor();
|
||||
|
||||
return $notes;
|
||||
return $streams;
|
||||
}
|
||||
|
||||
|
||||
|
@ -418,9 +380,8 @@ class NotesRequest extends NotesRequestBuilder {
|
|||
*/
|
||||
public function getStreamTimeline(int $since = 0, int $limit = 5, bool $localOnly = true
|
||||
): array {
|
||||
$qb = $this->getNotesSelectSql();
|
||||
$qb = $this->getStreamSelectSql();
|
||||
$this->limitPaginate($qb, $since, $limit);
|
||||
// $this->limitToType($qb, Note::TYPE);
|
||||
|
||||
if ($localOnly) {
|
||||
$this->limitToLocal($qb, true);
|
||||
|
@ -432,17 +393,17 @@ class NotesRequest extends NotesRequestBuilder {
|
|||
// TODO: to: = real public, cc: = unlisted !?
|
||||
$this->limitToRecipient($qb, ACore::CONTEXT_PUBLIC, true, ['to']);
|
||||
|
||||
$notes = [];
|
||||
$streams = [];
|
||||
$cursor = $qb->execute();
|
||||
while ($data = $cursor->fetch()) {
|
||||
try {
|
||||
$notes[] = $this->parseNotesSelectSql($data);
|
||||
$streams[] = $this->parseStreamSelectSql($data);
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
}
|
||||
$cursor->closeCursor();
|
||||
|
||||
return $notes;
|
||||
return $streams;
|
||||
}
|
||||
|
||||
|
||||
|
@ -462,7 +423,7 @@ class NotesRequest extends NotesRequestBuilder {
|
|||
*/
|
||||
public function getStreamTag(Person $actor, string $hashtag, int $since = 0, int $limit = 5
|
||||
): array {
|
||||
$qb = $this->getNotesSelectSql();
|
||||
$qb = $this->getStreamSelectSql();
|
||||
|
||||
$on = $this->exprJoinFollowing($qb, $actor);
|
||||
$on->add($this->exprLimitToRecipient($qb, ACore::CONTEXT_PUBLIC, false));
|
||||
|
@ -475,36 +436,37 @@ class NotesRequest extends NotesRequestBuilder {
|
|||
$this->leftJoinCacheActors($qb, 'attributed_to');
|
||||
$this->leftJoinStreamAction($qb);
|
||||
|
||||
$notes = [];
|
||||
$streams = [];
|
||||
$cursor = $qb->execute();
|
||||
while ($data = $cursor->fetch()) {
|
||||
$notes[] = $this->parseNotesSelectSql($data);
|
||||
$streams[] = $this->parseStreamSelectSql($data);
|
||||
}
|
||||
$cursor->closeCursor();
|
||||
|
||||
return $notes;
|
||||
return $streams;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param int $since
|
||||
*
|
||||
* @return Note[]
|
||||
* @throws Exception
|
||||
* @return Stream[]
|
||||
* @throws DateTimeException
|
||||
*/
|
||||
public function getNotesSince(int $since): array {
|
||||
$qb = $this->getNotesSelectSql();
|
||||
public function getNoteSince(int $since): array {
|
||||
$qb = $this->getStreamSelectSql();
|
||||
$this->limitToSince($qb, $since, 'published_time');
|
||||
$this->limitToType($qb, Note::TYPE);
|
||||
$this->leftJoinStreamAction($qb);
|
||||
|
||||
$notes = [];
|
||||
$streams = [];
|
||||
$cursor = $qb->execute();
|
||||
while ($data = $cursor->fetch()) {
|
||||
$notes[] = $this->parseNotesSelectSql($data);
|
||||
$streams[] = $this->parseStreamSelectSql($data);
|
||||
}
|
||||
$cursor->closeCursor();
|
||||
|
||||
return $notes;
|
||||
return $streams;
|
||||
}
|
||||
|
||||
|
||||
|
@ -512,8 +474,8 @@ class NotesRequest extends NotesRequestBuilder {
|
|||
* @param string $id
|
||||
* @param string $type
|
||||
*/
|
||||
public function deleteNoteById(string $id, string $type = '') {
|
||||
$qb = $this->getNotesDeleteSql();
|
||||
public function deleteStreamById(string $id, string $type = '') {
|
||||
$qb = $this->getStreamDeleteSql();
|
||||
|
||||
$this->limitToIdString($qb, $id);
|
||||
if ($type !== '') {
|
||||
|
@ -528,7 +490,7 @@ class NotesRequest extends NotesRequestBuilder {
|
|||
* @param string $actorId
|
||||
*/
|
||||
public function deleteByAuthor(string $actorId) {
|
||||
$qb = $this->getNotesDeleteSql();
|
||||
$qb = $this->getStreamDeleteSql();
|
||||
$this->limitToAttributedTo($qb, $actorId);
|
||||
|
||||
$qb->execute();
|
||||
|
@ -536,68 +498,69 @@ class NotesRequest extends NotesRequestBuilder {
|
|||
|
||||
|
||||
/**
|
||||
* Insert a new Note in the database.
|
||||
* Insert a new Stream in the database.
|
||||
*
|
||||
* @param Stream $note
|
||||
* @param Stream $stream
|
||||
*
|
||||
* @return IQueryBuilder
|
||||
*/
|
||||
public function saveStream(Stream $note): IQueryBuilder {
|
||||
public function saveStream(Stream $stream): IQueryBuilder {
|
||||
|
||||
try {
|
||||
$dTime = new DateTime();
|
||||
$dTime->setTimestamp($note->getPublishedTime());
|
||||
$dTime->setTimestamp($stream->getPublishedTime());
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
|
||||
$cache = '[]';
|
||||
if ($note->gotCache()) {
|
||||
$cache = json_encode($note->getCache(), JSON_UNESCAPED_SLASHES);
|
||||
if ($stream->gotCache()) {
|
||||
$cache = json_encode($stream->getCache(), JSON_UNESCAPED_SLASHES);
|
||||
}
|
||||
|
||||
$attributedTo = $note->getAttributedTo();
|
||||
if ($attributedTo === '' && $note->isLocal()) {
|
||||
$attributedTo = $note->getActor()
|
||||
->getId();
|
||||
$attributedTo = $stream->getAttributedTo();
|
||||
if ($attributedTo === '' && $stream->isLocal()) {
|
||||
$attributedTo = $stream->getActor()
|
||||
->getId();
|
||||
}
|
||||
|
||||
$qb = $this->getNotesInsertSql();
|
||||
$qb->setValue('id', $qb->createNamedParameter($note->getId()))
|
||||
->setValue('type', $qb->createNamedParameter($note->getType()))
|
||||
->setValue('to', $qb->createNamedParameter($note->getTo()))
|
||||
$qb = $this->getStreamInsertSql();
|
||||
$qb->setValue('id', $qb->createNamedParameter($stream->getId()))
|
||||
->setValue('type', $qb->createNamedParameter($stream->getType()))
|
||||
->setValue('to', $qb->createNamedParameter($stream->getTo()))
|
||||
->setValue(
|
||||
'to_array', $qb->createNamedParameter(
|
||||
json_encode($note->getToArray(), JSON_UNESCAPED_SLASHES)
|
||||
json_encode($stream->getToArray(), JSON_UNESCAPED_SLASHES)
|
||||
)
|
||||
)
|
||||
->setValue(
|
||||
'cc', $qb->createNamedParameter(
|
||||
json_encode($note->getCcArray(), JSON_UNESCAPED_SLASHES)
|
||||
json_encode($stream->getCcArray(), JSON_UNESCAPED_SLASHES)
|
||||
)
|
||||
)
|
||||
->setValue(
|
||||
'bcc', $qb->createNamedParameter(
|
||||
json_encode($note->getBccArray()), JSON_UNESCAPED_SLASHES
|
||||
json_encode($stream->getBccArray()), JSON_UNESCAPED_SLASHES
|
||||
)
|
||||
)
|
||||
->setValue('content', $qb->createNamedParameter($note->getContent()))
|
||||
->setValue('summary', $qb->createNamedParameter($note->getSummary()))
|
||||
->setValue('published', $qb->createNamedParameter($note->getPublished()))
|
||||
->setValue('content', $qb->createNamedParameter($stream->getContent()))
|
||||
->setValue('summary', $qb->createNamedParameter($stream->getSummary()))
|
||||
->setValue('published', $qb->createNamedParameter($stream->getPublished()))
|
||||
->setValue('attributed_to', $qb->createNamedParameter($attributedTo))
|
||||
->setValue('in_reply_to', $qb->createNamedParameter($note->getInReplyTo()))
|
||||
->setValue('source', $qb->createNamedParameter($note->getSource()))
|
||||
->setValue('object_id', $qb->createNamedParameter($note->getObjectId()))
|
||||
->setValue('in_reply_to', $qb->createNamedParameter($stream->getInReplyTo()))
|
||||
->setValue('source', $qb->createNamedParameter($stream->getSource()))
|
||||
->setValue('activity_id', $qb->createNamedParameter($stream->getActivityId()))
|
||||
->setValue('object_id', $qb->createNamedParameter($stream->getObjectId()))
|
||||
->setValue('cache', $qb->createNamedParameter($cache))
|
||||
->setValue(
|
||||
'instances', $qb->createNamedParameter(
|
||||
json_encode($note->getInstancePaths(), JSON_UNESCAPED_SLASHES)
|
||||
json_encode($stream->getInstancePaths(), JSON_UNESCAPED_SLASHES)
|
||||
)
|
||||
)
|
||||
->setValue('local', $qb->createNamedParameter(($note->isLocal()) ? '1' : '0'));
|
||||
->setValue('local', $qb->createNamedParameter(($stream->isLocal()) ? '1' : '0'));
|
||||
|
||||
try {
|
||||
$dTime = new DateTime();
|
||||
$dTime->setTimestamp($note->getPublishedTime());
|
||||
$dTime->setTimestamp($stream->getPublishedTime());
|
||||
$qb->setValue(
|
||||
'published_time', $qb->createNamedParameter($dTime, IQueryBuilder::PARAM_DATE)
|
||||
)
|
||||
|
@ -608,7 +571,7 @@ class NotesRequest extends NotesRequestBuilder {
|
|||
} catch (Exception $e) {
|
||||
}
|
||||
|
||||
$this->generatePrimaryKey($qb, $note->getId());
|
||||
$this->generatePrimaryKey($qb, $stream->getId());
|
||||
|
||||
return $qb;
|
||||
}
|
|
@ -35,6 +35,7 @@ use Doctrine\DBAL\Query\QueryBuilder;
|
|||
use OCA\Social\Exceptions\InvalidResourceException;
|
||||
use OCA\Social\Model\ActivityPub\ACore;
|
||||
use OCA\Social\Model\ActivityPub\Actor\Person;
|
||||
use OCA\Social\Model\ActivityPub\Object\Note;
|
||||
use OCA\Social\Model\ActivityPub\Stream;
|
||||
use OCA\Social\Model\InstancePath;
|
||||
use OCP\DB\QueryBuilder\ICompositeExpression;
|
||||
|
@ -42,11 +43,11 @@ use OCP\DB\QueryBuilder\IQueryBuilder;
|
|||
|
||||
|
||||
/**
|
||||
* Class NotesRequestBuilder
|
||||
* Class StreamRequestBuilder
|
||||
*
|
||||
* @package OCA\Social\Db
|
||||
*/
|
||||
class NotesRequestBuilder extends CoreRequestBuilder {
|
||||
class StreamRequestBuilder extends CoreRequestBuilder {
|
||||
|
||||
|
||||
use TArrayTools;
|
||||
|
@ -57,7 +58,7 @@ class NotesRequestBuilder extends CoreRequestBuilder {
|
|||
*
|
||||
* @return IQueryBuilder
|
||||
*/
|
||||
protected function getNotesInsertSql(): IQueryBuilder {
|
||||
protected function getStreamInsertSql(): IQueryBuilder {
|
||||
$qb = $this->dbConnection->getQueryBuilder();
|
||||
$qb->insert(self::TABLE_STREAMS);
|
||||
|
||||
|
@ -70,7 +71,7 @@ class NotesRequestBuilder extends CoreRequestBuilder {
|
|||
*
|
||||
* @return IQueryBuilder
|
||||
*/
|
||||
protected function getNotesUpdateSql(): IQueryBuilder {
|
||||
protected function getStreamUpdateSql(): IQueryBuilder {
|
||||
$qb = $this->dbConnection->getQueryBuilder();
|
||||
$qb->update(self::TABLE_STREAMS);
|
||||
|
||||
|
@ -83,21 +84,21 @@ class NotesRequestBuilder extends CoreRequestBuilder {
|
|||
*
|
||||
* @return IQueryBuilder
|
||||
*/
|
||||
protected function getNotesSelectSql(): IQueryBuilder {
|
||||
protected function getStreamSelectSql(): IQueryBuilder {
|
||||
$qb = $this->dbConnection->getQueryBuilder();
|
||||
|
||||
/** @noinspection PhpMethodParametersCountMismatchInspection */
|
||||
$qb->selectDistinct('sn.id')
|
||||
$qb->selectDistinct('s.id')
|
||||
->addSelect(
|
||||
'sn.type', 'sn.to', 'sn.to_array', 'sn.cc', 'sn.bcc', 'sn.content',
|
||||
'sn.summary', 'sn.attachments', 'sn.published', 'sn.published_time', 'sn.cache',
|
||||
'sn.object_id',
|
||||
'sn.attributed_to', 'sn.in_reply_to', 'sn.source', 'sn.local', 'sn.instances',
|
||||
'sn.creation'
|
||||
's.type', 's.to', 's.to_array', 's.cc', 's.bcc', 's.content',
|
||||
's.summary', 's.attachments', 's.published', 's.published_time', 's.cache',
|
||||
's.object_id',
|
||||
's.attributed_to', 's.in_reply_to', 's.source', 's.local', 's.instances',
|
||||
's.creation'
|
||||
)
|
||||
->from(self::TABLE_STREAMS, 'sn');
|
||||
->from(self::TABLE_STREAMS, 's');
|
||||
|
||||
$this->defaultSelectAlias = 'sn';
|
||||
$this->defaultSelectAlias = 's';
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
@ -111,9 +112,11 @@ class NotesRequestBuilder extends CoreRequestBuilder {
|
|||
protected function countNotesSelectSql(): IQueryBuilder {
|
||||
$qb = $this->dbConnection->getQueryBuilder();
|
||||
$qb->selectAlias($qb->createFunction('COUNT(*)'), 'count')
|
||||
->from(self::TABLE_STREAMS, 'sn');
|
||||
->from(self::TABLE_STREAMS, 's');
|
||||
|
||||
$this->defaultSelectAlias = 'sn';
|
||||
$this->limitToType($qb, Note::TYPE);
|
||||
|
||||
$this->defaultSelectAlias = 's';
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
@ -124,7 +127,7 @@ class NotesRequestBuilder extends CoreRequestBuilder {
|
|||
*
|
||||
* @return IQueryBuilder
|
||||
*/
|
||||
protected function getNotesDeleteSql(): IQueryBuilder {
|
||||
protected function getStreamDeleteSql(): IQueryBuilder {
|
||||
$qb = $this->dbConnection->getQueryBuilder();
|
||||
$qb->delete(self::TABLE_STREAMS);
|
||||
|
||||
|
@ -155,7 +158,6 @@ class NotesRequestBuilder extends CoreRequestBuilder {
|
|||
}
|
||||
|
||||
$on = $this->exprJoinFollowing($qb, $actor);
|
||||
|
||||
$qb->join($this->defaultSelectAlias, CoreRequestBuilder::TABLE_FOLLOWS, 'f', $on);
|
||||
}
|
||||
|
||||
|
@ -163,7 +165,6 @@ class NotesRequestBuilder extends CoreRequestBuilder {
|
|||
/**
|
||||
* @param IQueryBuilder $qb
|
||||
* @param Person $actor
|
||||
*
|
||||
* @param bool $followers
|
||||
*
|
||||
* @return ICompositeExpression
|
||||
|
@ -362,7 +363,7 @@ class NotesRequestBuilder extends CoreRequestBuilder {
|
|||
*
|
||||
* @return Stream
|
||||
*/
|
||||
protected function parseNotesSelectSql($data): Stream {
|
||||
protected function parseStreamSelectSql($data): Stream {
|
||||
$item = new Stream();
|
||||
$item->importFromDatabase($data);
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\Social\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class DateTimeException extends Exception {
|
||||
|
||||
}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\Social\Exceptions;
|
||||
|
||||
class NoteNotFoundException extends \Exception {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\Social\Exceptions;
|
||||
|
||||
class StreamNotFoundException extends \Exception {
|
||||
|
||||
}
|
||||
|
|
@ -33,7 +33,7 @@ namespace OCA\Social\Interfaces\Actor;
|
|||
|
||||
use daita\MySmallPhpTools\Traits\TArrayTools;
|
||||
use OCA\Social\Db\CacheActorsRequest;
|
||||
use OCA\Social\Db\NotesRequest;
|
||||
use OCA\Social\Db\StreamRequest;
|
||||
use OCA\Social\Exceptions\CacheActorDoesNotExistException;
|
||||
use OCA\Social\Exceptions\InvalidOriginException;
|
||||
use OCA\Social\Exceptions\ItemNotFoundException;
|
||||
|
@ -60,8 +60,8 @@ class PersonInterface implements IActivityPubInterface {
|
|||
/** @var CacheActorsRequest */
|
||||
private $cacheActorsRequest;
|
||||
|
||||
/** @var NotesRequest */
|
||||
private $notesRequest;
|
||||
/** @var StreamRequest */
|
||||
private $streamRequest;
|
||||
|
||||
/** @var ActorService */
|
||||
private $actorService;
|
||||
|
@ -77,17 +77,17 @@ class PersonInterface implements IActivityPubInterface {
|
|||
* UndoService constructor.
|
||||
*
|
||||
* @param CacheActorsRequest $cacheActorsRequest
|
||||
* @param NotesRequest $notesRequest
|
||||
* @param StreamRequest $streamRequest
|
||||
* @param ActorService $actorService
|
||||
* @param ConfigService $configService
|
||||
* @param MiscService $miscService
|
||||
*/
|
||||
public function __construct(
|
||||
CacheActorsRequest $cacheActorsRequest, NotesRequest $notesRequest,
|
||||
CacheActorsRequest $cacheActorsRequest, StreamRequest $streamRequest,
|
||||
ActorService $actorService, ConfigService $configService, MiscService $miscService
|
||||
) {
|
||||
$this->cacheActorsRequest = $cacheActorsRequest;
|
||||
$this->notesRequest = $notesRequest;
|
||||
$this->streamRequest = $streamRequest;
|
||||
$this->actorService = $actorService;
|
||||
$this->configService = $configService;
|
||||
$this->miscService = $miscService;
|
||||
|
@ -161,7 +161,7 @@ class PersonInterface implements IActivityPubInterface {
|
|||
public function delete(ACore $item) {
|
||||
/** @var Person $item */
|
||||
$this->cacheActorsRequest->deleteFromId($item->getId());
|
||||
$this->notesRequest->deleteByAuthor($item->getId());
|
||||
$this->streamRequest->deleteByAuthor($item->getId());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ declare(strict_types=1);
|
|||
namespace OCA\Social\Interfaces\Internal;
|
||||
|
||||
|
||||
use OCA\Social\Db\NotesRequest;
|
||||
use OCA\Social\Db\StreamRequest;
|
||||
use OCA\Social\Exceptions\ItemNotFoundException;
|
||||
use OCA\Social\Interfaces\IActivityPubInterface;
|
||||
use OCA\Social\Model\ActivityPub\ACore;
|
||||
|
@ -44,8 +44,8 @@ use OCA\Social\Service\MiscService;
|
|||
class SocialAppNotificationInterface implements IActivityPubInterface {
|
||||
|
||||
|
||||
/** @var NotesRequest */
|
||||
private $notesRequest;
|
||||
/** @var StreamRequest */
|
||||
private $streamRequest;
|
||||
|
||||
/** @var CurlService */
|
||||
private $curlService;
|
||||
|
@ -60,16 +60,16 @@ class SocialAppNotificationInterface implements IActivityPubInterface {
|
|||
/**
|
||||
* NoteInterface constructor.
|
||||
*
|
||||
* @param NotesRequest $notesRequest
|
||||
* @param StreamRequest $streamRequest
|
||||
* @param CurlService $curlService
|
||||
* @param ConfigService $configService
|
||||
* @param MiscService $miscService
|
||||
*/
|
||||
public function __construct(
|
||||
NotesRequest $notesRequest, CurlService $curlService, ConfigService $configService,
|
||||
StreamRequest $streamRequest, CurlService $curlService, ConfigService $configService,
|
||||
MiscService $miscService
|
||||
) {
|
||||
$this->notesRequest = $notesRequest;
|
||||
$this->streamRequest = $streamRequest;
|
||||
$this->curlService = $curlService;
|
||||
$this->configService = $configService;
|
||||
$this->miscService = $miscService;
|
||||
|
@ -111,7 +111,7 @@ class SocialAppNotificationInterface implements IActivityPubInterface {
|
|||
}
|
||||
|
||||
$this->miscService->log('Generating notification: ' . json_encode($notification, JSON_UNESCAPED_SLASHES), 1);
|
||||
$this->notesRequest->save($notification);
|
||||
$this->streamRequest->save($notification);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -32,10 +32,10 @@ namespace OCA\Social\Interfaces\Object;
|
|||
|
||||
|
||||
use Exception;
|
||||
use OCA\Social\Db\NotesRequest;
|
||||
use OCA\Social\Db\StreamRequest;
|
||||
use OCA\Social\Exceptions\InvalidOriginException;
|
||||
use OCA\Social\Exceptions\ItemNotFoundException;
|
||||
use OCA\Social\Exceptions\NoteNotFoundException;
|
||||
use OCA\Social\Exceptions\StreamNotFoundException;
|
||||
use OCA\Social\Interfaces\IActivityPubInterface;
|
||||
use OCA\Social\Model\ActivityPub\ACore;
|
||||
use OCA\Social\Model\ActivityPub\Activity\Undo;
|
||||
|
@ -54,8 +54,8 @@ use OCA\Social\Service\StreamQueueService;
|
|||
class AnnounceInterface implements IActivityPubInterface {
|
||||
|
||||
|
||||
/** @var NotesRequest */
|
||||
private $notesRequest;
|
||||
/** @var StreamRequest */
|
||||
private $streamRequest;
|
||||
|
||||
/** @var StreamQueueService */
|
||||
private $streamQueueService;
|
||||
|
@ -67,14 +67,15 @@ class AnnounceInterface implements IActivityPubInterface {
|
|||
/**
|
||||
* AnnounceInterface constructor.
|
||||
*
|
||||
* @param NotesRequest $notesRequest
|
||||
* @param StreamRequest $streamRequest
|
||||
* @param StreamQueueService $streamQueueService
|
||||
* @param MiscService $miscService
|
||||
*/
|
||||
public function __construct(
|
||||
NotesRequest $notesRequest, StreamQueueService $streamQueueService, MiscService $miscService
|
||||
StreamRequest $streamRequest, StreamQueueService $streamQueueService,
|
||||
MiscService $miscService
|
||||
) {
|
||||
$this->notesRequest = $notesRequest;
|
||||
$this->streamRequest = $streamRequest;
|
||||
$this->streamQueueService = $streamQueueService;
|
||||
$this->miscService = $miscService;
|
||||
}
|
||||
|
@ -136,11 +137,11 @@ class AnnounceInterface implements IActivityPubInterface {
|
|||
public function save(ACore $item) {
|
||||
/** @var Announce $item */
|
||||
try {
|
||||
$this->notesRequest->getNoteById($item->getId());
|
||||
} catch (NoteNotFoundException $e) {
|
||||
$this->streamRequest->getStreamById($item->getId());
|
||||
} catch (StreamNotFoundException $e) {
|
||||
$objectId = $item->getObjectId();
|
||||
$item->addCacheItem($objectId);
|
||||
$this->notesRequest->save($item);
|
||||
$this->streamRequest->save($item);
|
||||
|
||||
$this->streamQueueService->generateStreamQueue(
|
||||
$item->getRequestToken(), StreamQueue::TYPE_CACHE, $item->getId()
|
||||
|
@ -153,13 +154,7 @@ class AnnounceInterface implements IActivityPubInterface {
|
|||
* @param ACore $item
|
||||
*/
|
||||
public function delete(ACore $item) {
|
||||
try {
|
||||
// $stream = $this->notesRequest->getNoteById($item->getId());
|
||||
// if ($stream->getType() === Announce::TYPE) {
|
||||
$this->notesRequest->deleteNoteById($item->getId(), Announce::TYPE);
|
||||
// }
|
||||
} catch (NoteNotFoundException $e) {
|
||||
}
|
||||
$this->streamRequest->deleteStreamById($item->getId(), Announce::TYPE);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -31,10 +31,10 @@ declare(strict_types=1);
|
|||
namespace OCA\Social\Interfaces\Object;
|
||||
|
||||
|
||||
use OCA\Social\Db\NotesRequest;
|
||||
use OCA\Social\Db\StreamRequest;
|
||||
use OCA\Social\Exceptions\InvalidOriginException;
|
||||
use OCA\Social\Exceptions\ItemNotFoundException;
|
||||
use OCA\Social\Exceptions\NoteNotFoundException;
|
||||
use OCA\Social\Exceptions\StreamNotFoundException;
|
||||
use OCA\Social\Interfaces\IActivityPubInterface;
|
||||
use OCA\Social\Model\ActivityPub\ACore;
|
||||
use OCA\Social\Model\ActivityPub\Activity\Create;
|
||||
|
@ -47,8 +47,8 @@ use OCA\Social\Service\MiscService;
|
|||
class NoteInterface implements IActivityPubInterface {
|
||||
|
||||
|
||||
/** @var NotesRequest */
|
||||
private $notesRequest;
|
||||
/** @var StreamRequest */
|
||||
private $streamRequest;
|
||||
|
||||
/** @var CurlService */
|
||||
private $curlService;
|
||||
|
@ -63,16 +63,16 @@ class NoteInterface implements IActivityPubInterface {
|
|||
/**
|
||||
* NoteInterface constructor.
|
||||
*
|
||||
* @param NotesRequest $notesRequest
|
||||
* @param StreamRequest $streamRequest
|
||||
* @param CurlService $curlService
|
||||
* @param ConfigService $configService
|
||||
* @param MiscService $miscService
|
||||
*/
|
||||
public function __construct(
|
||||
NotesRequest $notesRequest, CurlService $curlService, ConfigService $configService,
|
||||
StreamRequest $streamRequest, CurlService $curlService, ConfigService $configService,
|
||||
MiscService $miscService
|
||||
) {
|
||||
$this->notesRequest = $notesRequest;
|
||||
$this->streamRequest = $streamRequest;
|
||||
$this->curlService = $curlService;
|
||||
$this->configService = $configService;
|
||||
$this->miscService = $miscService;
|
||||
|
@ -101,8 +101,8 @@ class NoteInterface implements IActivityPubInterface {
|
|||
*/
|
||||
public function getItemById(string $id): ACore {
|
||||
try {
|
||||
return $this->notesRequest->getNoteById($id);
|
||||
} catch (NoteNotFoundException $e) {
|
||||
return $this->streamRequest->getStreamById($id);
|
||||
} catch (StreamNotFoundException $e) {
|
||||
throw new ItemNotFoundException();
|
||||
}
|
||||
}
|
||||
|
@ -115,9 +115,9 @@ class NoteInterface implements IActivityPubInterface {
|
|||
/** @var Note $note */
|
||||
|
||||
try {
|
||||
$this->notesRequest->getNoteById($note->getId());
|
||||
} catch (NoteNotFoundException $e) {
|
||||
$this->notesRequest->save($note);
|
||||
$this->streamRequest->getStreamById($note->getId());
|
||||
} catch (StreamNotFoundException $e) {
|
||||
$this->streamRequest->save($note);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -149,7 +149,7 @@ class NoteInterface implements IActivityPubInterface {
|
|||
$item->checkOrigin(($item->getId()));
|
||||
|
||||
/** @var Note $item */
|
||||
$this->notesRequest->deleteNoteById($item->getId(), Note::TYPE);
|
||||
$this->streamRequest->deleteStreamById($item->getId(), Note::TYPE);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ use Exception;
|
|||
use OC\User\NoUserException;
|
||||
use OCA\Social\Db\ActorsRequest;
|
||||
use OCA\Social\Db\FollowsRequest;
|
||||
use OCA\Social\Db\NotesRequest;
|
||||
use OCA\Social\Db\StreamRequest;
|
||||
use OCA\Social\Exceptions\AccountAlreadyExistsException;
|
||||
use OCA\Social\Exceptions\ActorDoesNotExistException;
|
||||
use OCA\Social\Exceptions\ItemUnknownException;
|
||||
|
@ -72,8 +72,8 @@ class AccountService {
|
|||
/** @var FollowsRequest */
|
||||
private $followsRequest;
|
||||
|
||||
/** @var NotesRequest */
|
||||
private $notesRequest;
|
||||
/** @var StreamRequest */
|
||||
private $streamRequest;
|
||||
|
||||
/** @var ActorService */
|
||||
private $actorService;
|
||||
|
@ -98,7 +98,7 @@ class AccountService {
|
|||
* @param IAccountManager $accountManager
|
||||
* @param ActorsRequest $actorsRequest
|
||||
* @param FollowsRequest $followsRequest
|
||||
* @param NotesRequest $notesRequest
|
||||
* @param StreamRequest $streamRequest
|
||||
* @param ActorService $actorService
|
||||
* @param DocumentService $documentService
|
||||
* @param SignatureService $signatureService
|
||||
|
@ -107,7 +107,7 @@ class AccountService {
|
|||
*/
|
||||
public function __construct(
|
||||
IUserManager $userManager, IAccountManager $accountManager, ActorsRequest $actorsRequest,
|
||||
FollowsRequest $followsRequest, NotesRequest $notesRequest, ActorService $actorService,
|
||||
FollowsRequest $followsRequest, StreamRequest $streamRequest, ActorService $actorService,
|
||||
DocumentService $documentService, SignatureService $signatureService,
|
||||
ConfigService $configService, MiscService $miscService
|
||||
) {
|
||||
|
@ -115,7 +115,7 @@ class AccountService {
|
|||
$this->accountManager = $accountManager;
|
||||
$this->actorsRequest = $actorsRequest;
|
||||
$this->followsRequest = $followsRequest;
|
||||
$this->notesRequest = $notesRequest;
|
||||
$this->streamRequest = $streamRequest;
|
||||
$this->actorService = $actorService;
|
||||
$this->documentService = $documentService;
|
||||
$this->signatureService = $signatureService;
|
||||
|
@ -280,7 +280,7 @@ class AccountService {
|
|||
$count = [
|
||||
'followers' => $this->followsRequest->countFollowers($actor->getId()),
|
||||
'following' => $this->followsRequest->countFollowing($actor->getId()),
|
||||
'post' => $this->notesRequest->countNotesFromActorId($actor->getId())
|
||||
'post' => $this->streamRequest->countNotesFromActorId($actor->getId())
|
||||
];
|
||||
$actor->addDetailArray('count', $count);
|
||||
}
|
||||
|
|
|
@ -33,10 +33,9 @@ namespace OCA\Social\Service;
|
|||
use daita\MySmallPhpTools\Model\Request;
|
||||
use daita\MySmallPhpTools\Traits\TArrayTools;
|
||||
use Exception;
|
||||
use OCA\ShareByMail\Activity;
|
||||
use OCA\Social\AP;
|
||||
use OCA\Social\Db\FollowsRequest;
|
||||
use OCA\Social\Db\NotesRequest;
|
||||
use OCA\Social\Db\StreamRequest;
|
||||
use OCA\Social\Exceptions\ActorDoesNotExistException;
|
||||
use OCA\Social\Exceptions\EmptyQueueException;
|
||||
use OCA\Social\Exceptions\InvalidResourceException;
|
||||
|
@ -53,11 +52,16 @@ use OCA\Social\Model\ActivityPub\ACore;
|
|||
use OCA\Social\Model\ActivityPub\Activity\Create;
|
||||
use OCA\Social\Model\ActivityPub\Activity\Delete;
|
||||
use OCA\Social\Model\ActivityPub\Actor\Person;
|
||||
use OCA\Social\Model\ActivityPub\Object\Announce;
|
||||
use OCA\Social\Model\ActivityPub\Object\Tombstone;
|
||||
use OCA\Social\Model\InstancePath;
|
||||
use OCA\Social\Model\RequestQueue;
|
||||
|
||||
|
||||
/**
|
||||
* Class ActivityService
|
||||
*
|
||||
* @package OCA\Social\Service
|
||||
*/
|
||||
class ActivityService {
|
||||
|
||||
|
||||
|
@ -69,8 +73,8 @@ class ActivityService {
|
|||
const TIMEOUT_SERVICE = 30;
|
||||
|
||||
|
||||
/** @var NotesRequest */
|
||||
private $notesRequest;
|
||||
/** @var StreamRequest */
|
||||
private $streamRequest;
|
||||
|
||||
/** @var FollowsRequest */
|
||||
private $followsRequest;
|
||||
|
@ -101,7 +105,7 @@ class ActivityService {
|
|||
/**
|
||||
* ActivityService constructor.
|
||||
*
|
||||
* @param NotesRequest $notesRequest
|
||||
* @param StreamRequest $streamRequest
|
||||
* @param FollowsRequest $followsRequest
|
||||
* @param SignatureService $signatureService
|
||||
* @param RequestQueueService $requestQueueService
|
||||
|
@ -111,12 +115,12 @@ class ActivityService {
|
|||
* @param MiscService $miscService
|
||||
*/
|
||||
public function __construct(
|
||||
NotesRequest $notesRequest, FollowsRequest $followsRequest,
|
||||
StreamRequest $streamRequest, FollowsRequest $followsRequest,
|
||||
SignatureService $signatureService, RequestQueueService $requestQueueService,
|
||||
AccountService $accountService, CurlService $curlService, ConfigService $configService,
|
||||
MiscService $miscService
|
||||
) {
|
||||
$this->notesRequest = $notesRequest;
|
||||
$this->streamRequest = $streamRequest;
|
||||
$this->followsRequest = $followsRequest;
|
||||
$this->requestQueueService = $requestQueueService;
|
||||
$this->accountService = $accountService;
|
||||
|
|
|
@ -33,9 +33,9 @@ namespace OCA\Social\Service;
|
|||
use daita\MySmallPhpTools\Traits\TStringTools;
|
||||
use Exception;
|
||||
use OCA\Social\AP;
|
||||
use OCA\Social\Db\NotesRequest;
|
||||
use OCA\Social\Db\StreamRequest;
|
||||
use OCA\Social\Exceptions\ItemUnknownException;
|
||||
use OCA\Social\Exceptions\NoteNotFoundException;
|
||||
use OCA\Social\Exceptions\StreamNotFoundException;
|
||||
use OCA\Social\Exceptions\RedundancyLimitException;
|
||||
use OCA\Social\Exceptions\SocialAppConfigException;
|
||||
use OCA\Social\Model\ActivityPub\ACore;
|
||||
|
@ -56,8 +56,8 @@ class BoostService {
|
|||
use TStringTools;
|
||||
|
||||
|
||||
/** @var NotesRequest */
|
||||
private $notesRequest;
|
||||
/** @var StreamRequest */
|
||||
private $streamRequest;
|
||||
|
||||
/** @var NoteService */
|
||||
private $noteService;
|
||||
|
@ -81,7 +81,7 @@ class BoostService {
|
|||
/**
|
||||
* BoostService constructor.
|
||||
*
|
||||
* @param NotesRequest $notesRequest
|
||||
* @param StreamRequest $streamRequest
|
||||
* @param NoteService $noteService
|
||||
* @param SignatureService $signatureService
|
||||
* @param ActivityService $activityService
|
||||
|
@ -90,11 +90,11 @@ class BoostService {
|
|||
* @param MiscService $miscService
|
||||
*/
|
||||
public function __construct(
|
||||
NotesRequest $notesRequest, NoteService $noteService, SignatureService $signatureService,
|
||||
StreamRequest $streamRequest, NoteService $noteService, SignatureService $signatureService,
|
||||
ActivityService $activityService, StreamActionService $streamActionService,
|
||||
StreamQueueService $streamQueueService, MiscService $miscService
|
||||
) {
|
||||
$this->notesRequest = $notesRequest;
|
||||
$this->streamRequest = $streamRequest;
|
||||
$this->noteService = $noteService;
|
||||
$this->signatureService = $signatureService;
|
||||
$this->activityService = $activityService;
|
||||
|
@ -110,7 +110,7 @@ class BoostService {
|
|||
* @param string $token
|
||||
*
|
||||
* @return ACore
|
||||
* @throws NoteNotFoundException
|
||||
* @throws StreamNotFoundException
|
||||
* @throws SocialAppConfigException
|
||||
* @throws Exception
|
||||
*/
|
||||
|
@ -118,7 +118,7 @@ class BoostService {
|
|||
|
||||
try {
|
||||
return $this->get($actor, $postId);
|
||||
} catch (NoteNotFoundException $e) {
|
||||
} catch (StreamNotFoundException $e) {
|
||||
}
|
||||
|
||||
$announce = new Announce();
|
||||
|
@ -127,7 +127,7 @@ class BoostService {
|
|||
|
||||
$note = $this->noteService->getNoteById($postId, true);
|
||||
if ($note->getType() !== Note::TYPE) {
|
||||
throw new NoteNotFoundException('Stream is not a Note');
|
||||
throw new StreamNotFoundException('Stream is not a Note');
|
||||
}
|
||||
|
||||
$announce->addCc($note->getAttributedTo());
|
||||
|
@ -153,13 +153,13 @@ class BoostService {
|
|||
* @param string $postId
|
||||
*
|
||||
* @return Stream
|
||||
* @throws NoteNotFoundException
|
||||
* @throws StreamNotFoundException
|
||||
* @throws SocialAppConfigException
|
||||
* @throws ItemUnknownException
|
||||
* @throws RedundancyLimitException
|
||||
*/
|
||||
public function get(Person $actor, string $postId): Stream {
|
||||
$stream = $this->notesRequest->getNoteByObjectId($actor, Announce::TYPE, $postId);
|
||||
$stream = $this->streamRequest->getStreamByObjectId($actor, Announce::TYPE, $postId);
|
||||
|
||||
return $stream;
|
||||
}
|
||||
|
@ -171,7 +171,7 @@ class BoostService {
|
|||
* @param string $token
|
||||
*
|
||||
* @return ACore
|
||||
* @throws NoteNotFoundException
|
||||
* @throws StreamNotFoundException
|
||||
* @throws SocialAppConfigException
|
||||
*/
|
||||
public function delete(Person $actor, string $postId, &$token = ''): ACore {
|
||||
|
@ -181,15 +181,15 @@ class BoostService {
|
|||
|
||||
$note = $this->noteService->getNoteById($postId, true);
|
||||
if ($note->getType() !== Note::TYPE) {
|
||||
throw new NoteNotFoundException('Stream is not a Note');
|
||||
throw new StreamNotFoundException('Stream is not a Note');
|
||||
}
|
||||
|
||||
$announce = $this->notesRequest->getNoteByObjectId($actor, Announce::TYPE, $postId);
|
||||
$announce = $this->streamRequest->getStreamByObjectId($actor, Announce::TYPE, $postId);
|
||||
|
||||
$undo->setObject($announce);
|
||||
$undo->setCcArray($announce->getCcArray());
|
||||
|
||||
$this->notesRequest->deleteNoteById($announce->getId(), Announce::TYPE);
|
||||
$this->streamRequest->deleteStreamById($announce->getId(), Announce::TYPE);
|
||||
$this->streamActionService->setActionBool($actor->getId(), $postId, 'boosted', false);
|
||||
$this->signatureService->signObject($actor, $undo);
|
||||
|
||||
|
|
|
@ -33,8 +33,11 @@ namespace OCA\Social\Service;
|
|||
|
||||
use daita\MySmallPhpTools\Traits\TArrayTools;
|
||||
use OCA\Social\Db\HashtagsRequest;
|
||||
use OCA\Social\Db\NotesRequest;
|
||||
use OCA\Social\Db\StreamRequest;
|
||||
use OCA\Social\Exceptions\DateTimeException;
|
||||
use OCA\Social\Exceptions\HashtagDoesNotExistException;
|
||||
use OCA\Social\Model\ActivityPub\Object\Note;
|
||||
use OCA\Social\Model\ActivityPub\Stream;
|
||||
|
||||
|
||||
class HashtagService {
|
||||
|
@ -53,8 +56,8 @@ class HashtagService {
|
|||
/** @var HashtagsRequest */
|
||||
private $hashtagsRequest;
|
||||
|
||||
/** @var NotesRequest */
|
||||
private $notesRequest;
|
||||
/** @var StreamRequest */
|
||||
private $streamRequest;
|
||||
|
||||
/** @var ConfigService */
|
||||
private $configService;
|
||||
|
@ -67,16 +70,17 @@ class HashtagService {
|
|||
* ImportService constructor.
|
||||
*
|
||||
* @param HashtagsRequest $hashtagsRequest
|
||||
* @param NotesRequest $notesRequest
|
||||
* @param StreamRequest $streamRequest
|
||||
* @param ConfigService $configService
|
||||
* @param MiscService $miscService
|
||||
*/
|
||||
public function __construct(
|
||||
HashtagsRequest $hashtagsRequest, NotesRequest $notesRequest, ConfigService $configService,
|
||||
HashtagsRequest $hashtagsRequest, StreamRequest $streamRequest,
|
||||
ConfigService $configService,
|
||||
MiscService $miscService
|
||||
) {
|
||||
$this->hashtagsRequest = $hashtagsRequest;
|
||||
$this->notesRequest = $notesRequest;
|
||||
$this->streamRequest = $streamRequest;
|
||||
$this->configService = $configService;
|
||||
$this->miscService = $miscService;
|
||||
}
|
||||
|
@ -92,8 +96,10 @@ class HashtagService {
|
|||
* ]
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @return int
|
||||
* @throws DateTimeException
|
||||
*/
|
||||
public function manageHashtags(): int {
|
||||
$current = $this->hashtagsRequest->getAll();
|
||||
|
@ -151,14 +157,15 @@ class HashtagService {
|
|||
/**
|
||||
* @param int $timestamp
|
||||
*
|
||||
* @return array
|
||||
* @return Stream[]
|
||||
* @throws DateTimeException
|
||||
*/
|
||||
private function getTrendSince(int $timestamp): array {
|
||||
$result = [];
|
||||
|
||||
$notes = $this->notesRequest->getNotesSince($timestamp);
|
||||
$notes = $this->streamRequest->getNoteSince($timestamp);
|
||||
foreach ($notes as $note) {
|
||||
|
||||
/** @var Note $note */
|
||||
foreach ($note->getHashtags() as $hashtag) {
|
||||
if (array_key_exists($hashtag, $result)) {
|
||||
$result[$hashtag]++;
|
||||
|
|
|
@ -32,11 +32,11 @@ namespace OCA\Social\Service;
|
|||
|
||||
use daita\MySmallPhpTools\Exceptions\MalformedArrayException;
|
||||
use Exception;
|
||||
use OCA\Social\Db\NotesRequest;
|
||||
use OCA\Social\Db\StreamRequest;
|
||||
use OCA\Social\Exceptions\InvalidOriginException;
|
||||
use OCA\Social\Exceptions\InvalidResourceException;
|
||||
use OCA\Social\Exceptions\ItemUnknownException;
|
||||
use OCA\Social\Exceptions\NoteNotFoundException;
|
||||
use OCA\Social\Exceptions\StreamNotFoundException;
|
||||
use OCA\Social\Exceptions\RedundancyLimitException;
|
||||
use OCA\Social\Exceptions\RequestContentException;
|
||||
use OCA\Social\Exceptions\RequestNetworkException;
|
||||
|
@ -53,8 +53,8 @@ use OCA\Social\Model\InstancePath;
|
|||
class NoteService {
|
||||
|
||||
|
||||
/** @var NotesRequest */
|
||||
private $notesRequest;
|
||||
/** @var StreamRequest */
|
||||
private $streamRequest;
|
||||
|
||||
/** @var ActivityService */
|
||||
private $activityService;
|
||||
|
@ -85,7 +85,7 @@ class NoteService {
|
|||
/**
|
||||
* NoteService constructor.
|
||||
*
|
||||
* @param NotesRequest $notesRequest
|
||||
* @param StreamRequest $streamRequest
|
||||
* @param ActivityService $activityService
|
||||
* @param AccountService $accountService
|
||||
* @param SignatureService $signatureService
|
||||
|
@ -95,12 +95,12 @@ class NoteService {
|
|||
* @param MiscService $miscService
|
||||
*/
|
||||
public function __construct(
|
||||
NotesRequest $notesRequest, ActivityService $activityService,
|
||||
StreamRequest $streamRequest, ActivityService $activityService,
|
||||
AccountService $accountService, SignatureService $signatureService,
|
||||
StreamQueueService $streamQueueService, CacheActorService $cacheActorService,
|
||||
ConfigService $configService, MiscService $miscService
|
||||
) {
|
||||
$this->notesRequest = $notesRequest;
|
||||
$this->streamRequest = $streamRequest;
|
||||
$this->activityService = $activityService;
|
||||
$this->accountService = $accountService;
|
||||
$this->signatureService = $signatureService;
|
||||
|
@ -116,7 +116,7 @@ class NoteService {
|
|||
*/
|
||||
public function setViewer(Person $viewer) {
|
||||
$this->viewer = $viewer;
|
||||
$this->notesRequest->setViewer($viewer);
|
||||
$this->streamRequest->setViewer($viewer);
|
||||
}
|
||||
|
||||
|
||||
|
@ -285,7 +285,7 @@ class NoteService {
|
|||
* @throws InvalidOriginException
|
||||
* @throws InvalidResourceException
|
||||
* @throws MalformedArrayException
|
||||
* @throws NoteNotFoundException
|
||||
* @throws StreamNotFoundException
|
||||
* @throws RedundancyLimitException
|
||||
* @throws RequestContentException
|
||||
* @throws RequestNetworkException
|
||||
|
@ -324,7 +324,7 @@ class NoteService {
|
|||
|
||||
$item->setActorId($item->getAttributedTo());
|
||||
$this->activityService->deleteActivity($item);
|
||||
$this->notesRequest->deleteNoteById($item->getId(), $type);
|
||||
$this->streamRequest->deleteStreamById($item->getId(), $type);
|
||||
}
|
||||
|
||||
|
||||
|
@ -333,10 +333,10 @@ class NoteService {
|
|||
* @param bool $asViewer
|
||||
*
|
||||
* @return Stream
|
||||
* @throws NoteNotFoundException
|
||||
* @throws StreamNotFoundException
|
||||
*/
|
||||
public function getNoteById(string $id, bool $asViewer = false): Stream {
|
||||
return $this->notesRequest->getNoteById($id, $asViewer);
|
||||
return $this->streamRequest->getStreamById($id, $asViewer);
|
||||
}
|
||||
|
||||
|
||||
|
@ -349,7 +349,7 @@ class NoteService {
|
|||
* @throws Exception
|
||||
*/
|
||||
public function getStreamHome(Person $actor, int $since = 0, int $limit = 5): array {
|
||||
return $this->notesRequest->getStreamHome($actor, $since, $limit);
|
||||
return $this->streamRequest->getStreamHome($actor, $since, $limit);
|
||||
}
|
||||
|
||||
|
||||
|
@ -362,7 +362,7 @@ class NoteService {
|
|||
* @throws Exception
|
||||
*/
|
||||
public function getStreamNotifications(Person $actor, int $since = 0, int $limit = 5): array {
|
||||
return $this->notesRequest->getStreamNotifications($actor, $since, $limit);
|
||||
return $this->streamRequest->getStreamNotifications($actor, $since, $limit);
|
||||
}
|
||||
|
||||
|
||||
|
@ -375,7 +375,7 @@ class NoteService {
|
|||
* @throws Exception
|
||||
*/
|
||||
public function getStreamAccount(string $actorId, int $since = 0, int $limit = 5): array {
|
||||
return $this->notesRequest->getStreamAccount($actorId, $since, $limit);
|
||||
return $this->streamRequest->getStreamAccount($actorId, $since, $limit);
|
||||
}
|
||||
|
||||
|
||||
|
@ -388,7 +388,7 @@ class NoteService {
|
|||
* @throws Exception
|
||||
*/
|
||||
public function getStreamDirect(Person $actor, int $since = 0, int $limit = 5): array {
|
||||
return $this->notesRequest->getStreamDirect($actor, $since, $limit);
|
||||
return $this->streamRequest->getStreamDirect($actor, $since, $limit);
|
||||
}
|
||||
|
||||
|
||||
|
@ -400,7 +400,7 @@ class NoteService {
|
|||
* @throws Exception
|
||||
*/
|
||||
public function getStreamLocalTimeline(int $since = 0, int $limit = 5): array {
|
||||
return $this->notesRequest->getStreamTimeline($since, $limit, true);
|
||||
return $this->streamRequest->getStreamTimeline($since, $limit, true);
|
||||
}
|
||||
|
||||
|
||||
|
@ -415,7 +415,7 @@ class NoteService {
|
|||
*/
|
||||
public function getStreamLocalTag(Person $actor, string $hashtag, int $since = 0, int $limit = 5
|
||||
): array {
|
||||
return $this->notesRequest->getStreamTag($actor, $hashtag, $since, $limit);
|
||||
return $this->streamRequest->getStreamTag($actor, $hashtag, $since, $limit);
|
||||
}
|
||||
|
||||
|
||||
|
@ -440,7 +440,7 @@ class NoteService {
|
|||
* @throws Exception
|
||||
*/
|
||||
public function getStreamGlobalTimeline(int $since = 0, int $limit = 5): array {
|
||||
return $this->notesRequest->getStreamTimeline($since, $limit, false);
|
||||
return $this->streamRequest->getStreamTimeline($since, $limit, false);
|
||||
}
|
||||
|
||||
|
||||
|
@ -451,7 +451,7 @@ class NoteService {
|
|||
* @throws InvalidOriginException
|
||||
* @throws InvalidResourceException
|
||||
* @throws MalformedArrayException
|
||||
* @throws NoteNotFoundException
|
||||
* @throws StreamNotFoundException
|
||||
* @throws RedundancyLimitException
|
||||
* @throws SocialAppConfigException
|
||||
* @throws ItemUnknownException
|
||||
|
@ -462,7 +462,7 @@ class NoteService {
|
|||
* @throws RequestResultNotJsonException
|
||||
*/
|
||||
public function getAuthorFromPostId($noteId) {
|
||||
$note = $this->notesRequest->getNoteById($noteId);
|
||||
$note = $this->streamRequest->getStreamById($noteId);
|
||||
|
||||
return $this->cacheActorService->getFromId($note->getAttributedTo());
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ use daita\MySmallPhpTools\Exceptions\MalformedArrayException;
|
|||
use OCA\Social\Exceptions\InvalidOriginException;
|
||||
use OCA\Social\Exceptions\InvalidResourceException;
|
||||
use OCA\Social\Exceptions\ItemUnknownException;
|
||||
use OCA\Social\Exceptions\NoteNotFoundException;
|
||||
use OCA\Social\Exceptions\StreamNotFoundException;
|
||||
use OCA\Social\Exceptions\RedundancyLimitException;
|
||||
use OCA\Social\Exceptions\RequestContentException;
|
||||
use OCA\Social\Exceptions\RequestNetworkException;
|
||||
|
@ -95,7 +95,7 @@ class PostService {
|
|||
* @throws InvalidResourceException
|
||||
* @throws ItemUnknownException
|
||||
* @throws MalformedArrayException
|
||||
* @throws NoteNotFoundException
|
||||
* @throws StreamNotFoundException
|
||||
* @throws RedundancyLimitException
|
||||
* @throws RequestContentException
|
||||
* @throws RequestNetworkException
|
||||
|
|
|
@ -34,12 +34,12 @@ use daita\MySmallPhpTools\Exceptions\MalformedArrayException;
|
|||
use daita\MySmallPhpTools\Model\Cache;
|
||||
use daita\MySmallPhpTools\Model\CacheItem;
|
||||
use OCA\Social\AP;
|
||||
use OCA\Social\Db\NotesRequest;
|
||||
use OCA\Social\Db\StreamRequest;
|
||||
use OCA\Social\Db\StreamQueueRequest;
|
||||
use OCA\Social\Exceptions\InvalidOriginException;
|
||||
use OCA\Social\Exceptions\InvalidResourceException;
|
||||
use OCA\Social\Exceptions\ItemUnknownException;
|
||||
use OCA\Social\Exceptions\NoteNotFoundException;
|
||||
use OCA\Social\Exceptions\StreamNotFoundException;
|
||||
use OCA\Social\Exceptions\QueueStatusException;
|
||||
use OCA\Social\Exceptions\RedundancyLimitException;
|
||||
use OCA\Social\Exceptions\RequestContentException;
|
||||
|
@ -61,8 +61,8 @@ use OCA\Social\Model\StreamQueue;
|
|||
class StreamQueueService {
|
||||
|
||||
|
||||
/** @var NotesRequest */
|
||||
private $notesRequest;
|
||||
/** @var StreamRequest */
|
||||
private $streamRequest;
|
||||
|
||||
/** @var StreamQueueRequest */
|
||||
private $streamQueueRequest;
|
||||
|
@ -79,17 +79,17 @@ class StreamQueueService {
|
|||
/**
|
||||
* StreamQueueService constructor.
|
||||
*
|
||||
* @param NotesRequest $notesRequest
|
||||
* @param StreamRequest $streamRequest
|
||||
* @param StreamQueueRequest $streamQueueRequest
|
||||
* @param ImportService $importService
|
||||
* @param CurlService $curlService
|
||||
* @param MiscService $miscService
|
||||
*/
|
||||
public function __construct(
|
||||
NotesRequest $notesRequest, StreamQueueRequest $streamQueueRequest,
|
||||
StreamRequest $streamRequest, StreamQueueRequest $streamQueueRequest,
|
||||
ImportService $importService, CurlService $curlService, MiscService $miscService
|
||||
) {
|
||||
$this->notesRequest = $notesRequest;
|
||||
$this->streamRequest = $streamRequest;
|
||||
$this->streamQueueRequest = $streamQueueRequest;
|
||||
$this->importService = $importService;
|
||||
$this->curlService = $curlService;
|
||||
|
@ -170,8 +170,8 @@ class StreamQueueService {
|
|||
*/
|
||||
private function manageStreamQueueCache(StreamQueue $queue) {
|
||||
try {
|
||||
$stream = $this->notesRequest->getNoteById($queue->getStreamId());
|
||||
} catch (NoteNotFoundException $e) {
|
||||
$stream = $this->streamRequest->getStreamById($queue->getStreamId());
|
||||
} catch (StreamNotFoundException $e) {
|
||||
$this->deleteCache($queue);
|
||||
|
||||
return;
|
||||
|
@ -211,7 +211,7 @@ class StreamQueueService {
|
|||
$this->cacheItem($item);
|
||||
$item->setStatus(StreamQueue::STATUS_SUCCESS);
|
||||
$cache->updateItem($item);
|
||||
} catch (NoteNotFoundException $e) {
|
||||
} catch (StreamNotFoundException $e) {
|
||||
$this->miscService->log(
|
||||
'Error caching stream: ' . json_encode($item) . ' ' . get_class($e) . ' '
|
||||
. $e->getMessage(), 1
|
||||
|
@ -291,7 +291,7 @@ class StreamQueueService {
|
|||
* @throws InvalidResourceException
|
||||
* @throws ItemUnknownException
|
||||
* @throws MalformedArrayException
|
||||
* @throws NoteNotFoundException
|
||||
* @throws StreamNotFoundException
|
||||
* @throws RedundancyLimitException
|
||||
* @throws RequestContentException
|
||||
* @throws RequestNetworkException
|
||||
|
@ -303,8 +303,8 @@ class StreamQueueService {
|
|||
private function cacheItem(CacheItem &$item) {
|
||||
|
||||
try {
|
||||
$object = $this->notesRequest->getNoteById($item->getUrl());
|
||||
} catch (NoteNotFoundException $e) {
|
||||
$object = $this->streamRequest->getStreamById($item->getUrl());
|
||||
} catch (StreamNotFoundException $e) {
|
||||
$data = $this->curlService->retrieveObject($item->getUrl());
|
||||
$object = AP::$activityPub->getItemFromData($data);
|
||||
|
||||
|
@ -323,7 +323,7 @@ class StreamQueueService {
|
|||
$interface->save($object);
|
||||
}
|
||||
|
||||
$note = $this->notesRequest->getNoteById($object->getId());
|
||||
$note = $this->streamRequest->getStreamById($object->getId());
|
||||
$item->setContent(json_encode($note, JSON_UNESCAPED_SLASHES));
|
||||
}
|
||||
|
||||
|
@ -335,7 +335,7 @@ class StreamQueueService {
|
|||
* @return bool
|
||||
*/
|
||||
private function updateCache(Stream $stream, Cache $cache): bool {
|
||||
$this->notesRequest->updateCache($stream, $cache);
|
||||
$this->streamRequest->updateCache($stream, $cache);
|
||||
|
||||
$done = true;
|
||||
foreach ($cache->getItems() as $item) {
|
||||
|
|
Ładowanie…
Reference in New Issue