From 823773fbbeca8740a510bf132b56838e32ecde35 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Sat, 26 Jan 2019 10:57:07 -0100 Subject: [PATCH] object returned in the stream Signed-off-by: Maxence Lange --- lib/Db/NotesRequest.php | 1 + lib/Db/NotesRequestBuilder.php | 5 +++-- lib/Interfaces/Object/AnnounceInterface.php | 25 ++++++++++----------- lib/Model/ActivityPub/Stream.php | 6 +++-- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/lib/Db/NotesRequest.php b/lib/Db/NotesRequest.php index 343fc1c2..e5757336 100644 --- a/lib/Db/NotesRequest.php +++ b/lib/Db/NotesRequest.php @@ -101,6 +101,7 @@ class NotesRequest extends NotesRequestBuilder { ->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( diff --git a/lib/Db/NotesRequestBuilder.php b/lib/Db/NotesRequestBuilder.php index 6719ad59..8da3989c 100644 --- a/lib/Db/NotesRequestBuilder.php +++ b/lib/Db/NotesRequestBuilder.php @@ -82,8 +82,9 @@ class NotesRequestBuilder extends CoreRequestBuilder { /** @noinspection PhpMethodParametersCountMismatchInspection */ $qb->select( 'sn.id', 'sn.type', 'sn.to', 'sn.to_array', 'sn.cc', 'sn.bcc', 'sn.content', - 'sn.summary', 'sn.published', 'sn.published_time', 'sn.cache', 'sn.attributed_to', - 'sn.in_reply_to', 'sn.source', 'sn.local', 'sn.instances', 'sn.creation' + 'sn.summary', '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' ) ->from(self::TABLE_SERVER_NOTES, 'sn'); diff --git a/lib/Interfaces/Object/AnnounceInterface.php b/lib/Interfaces/Object/AnnounceInterface.php index 829452d1..a7a49910 100644 --- a/lib/Interfaces/Object/AnnounceInterface.php +++ b/lib/Interfaces/Object/AnnounceInterface.php @@ -98,17 +98,7 @@ class AnnounceInterface implements IActivityPubInterface { /** @var Stream $item */ $item->checkOrigin($item->getId()); - try { - $this->notesRequest->getNoteById($item->getId()); - } catch (NoteNotFoundException $e) { - $objectId = $item->getObjectId(); - $item->addCacheItem($objectId); - $this->notesRequest->save($item); - - $this->streamQueueService->generateStreamQueue( - $item->getRequestToken(), StreamQueue::TYPE_CACHE, $item->getId() - ); - } + $this->save($item); } @@ -134,7 +124,17 @@ class AnnounceInterface implements IActivityPubInterface { */ public function save(ACore $item) { /** @var Announce $item */ -// $this->cacheDocumentsRequest->save($item); + try { + $this->notesRequest->getNoteById($item->getId()); + } catch (NoteNotFoundException $e) { + $objectId = $item->getObjectId(); + $item->addCacheItem($objectId); + $this->notesRequest->save($item); + + $this->streamQueueService->generateStreamQueue( + $item->getRequestToken(), StreamQueue::TYPE_CACHE, $item->getId() + ); + } } @@ -142,7 +142,6 @@ class AnnounceInterface implements IActivityPubInterface { * @param ACore $item */ public function delete(ACore $item) { -// $this->cacheDocumentsRequest->delete($item); } diff --git a/lib/Model/ActivityPub/Stream.php b/lib/Model/ActivityPub/Stream.php index 486fccf6..c24e4fb2 100644 --- a/lib/Model/ActivityPub/Stream.php +++ b/lib/Model/ActivityPub/Stream.php @@ -261,6 +261,7 @@ class Stream extends ACore implements JsonSerializable { $this->setInReplyTo($this->validate(self::AS_ID, 'inReplyTo', $data, '')); $this->setAttributedTo($this->validate(self::AS_ID, 'attributedTo', $data, '')); $this->setSensitive($this->getBool('sensitive', $data, false)); + $this->setObjectId($this->get('object', $data, '')); $this->setConversation($this->validate(self::AS_ID, 'conversation', $data, '')); $this->setContent($this->get('content', $data, '')); $this->convertPublished(); @@ -276,8 +277,9 @@ class Stream extends ACore implements JsonSerializable { $dTime = new DateTime($this->get('published_time', $data, 'yesterday')); $this->setActivityId($this->validate(self::AS_ID, 'activity_id', $data, '')); - $this->setContent($this->validate(self::AS_STRING, 'content', $data, ''));; + $this->setContent($this->validate(self::AS_STRING, 'content', $data, '')); $this->setPublishedTime($dTime->getTimestamp()); + $this->setObjectId($this->validate(self::AS_ID, 'object_id', $data, '')); $this->setAttributedTo($this->validate(self::AS_ID, 'attributed_to', $data, '')); $this->setInReplyTo($this->validate(self::AS_ID, 'in_reply_to', $data)); @@ -305,7 +307,7 @@ class Stream extends ACore implements JsonSerializable { ); if ($this->isCompleteDetails()) { - array_merge( + $result = array_merge( $result, [ 'cache' => $this->getCache()