diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2018-12-12 11:44:40 -0100 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2018-12-18 18:46:39 +0100 |
commit | 840326aab7eabf8a05ae3fc83ecc4eedad635a11 (patch) | |
tree | 0d9d1512a131153f764d9859f813af78ed6edfc0 /lib | |
parent | c470f7f6d15e0eed2ab713376cf7172ffcb5a7ee (diff) |
fixing replyTo and @context generation
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Db/NotesRequest.php | 2 | ||||
-rw-r--r-- | lib/Model/ActivityPub/ACore.php | 11 | ||||
-rw-r--r-- | lib/Model/ActivityPub/Note.php | 3 | ||||
-rw-r--r-- | lib/Service/ActivityPub/NoteService.php | 35 | ||||
-rw-r--r-- | lib/Service/ActivityService.php | 1 |
5 files changed, 48 insertions, 4 deletions
diff --git a/lib/Db/NotesRequest.php b/lib/Db/NotesRequest.php index 8d2a6ea1..2bf2ef77 100644 --- a/lib/Db/NotesRequest.php +++ b/lib/Db/NotesRequest.php @@ -133,7 +133,7 @@ class NotesRequest extends NotesRequestBuilder { $cursor->closeCursor(); if ($data === false) { - throw new NoteNotFoundException(); + throw new NoteNotFoundException('Post not found'); } return $this->parseNotesSelectSql($data); diff --git a/lib/Model/ActivityPub/ACore.php b/lib/Model/ActivityPub/ACore.php index 1790718b..e0967c9c 100644 --- a/lib/Model/ActivityPub/ACore.php +++ b/lib/Model/ActivityPub/ACore.php @@ -538,13 +538,20 @@ abstract class ACore extends Item implements JsonSerializable { * @return array */ public function jsonSerialize(): array { - $context = [self::CONTEXT_ACTIVITYSTREAMS]; + if ($this->gotSignature()) { $this->entries['signature'] = $this->getSignature(); - array_push($context, self::CONTEXT_SECURITY); } if ($this->isRoot()) { + $context = [self::CONTEXT_ACTIVITYSTREAMS]; + + if ($this->gotObject() + && $this->getObject() + ->gotSignature()) { + array_push($context, self::CONTEXT_SECURITY); + } + $this->addEntryArray('@context', $context); } diff --git a/lib/Model/ActivityPub/Note.php b/lib/Model/ActivityPub/Note.php index 7598305e..03345ac3 100644 --- a/lib/Model/ActivityPub/Note.php +++ b/lib/Model/ActivityPub/Note.php @@ -32,6 +32,7 @@ namespace OCA\Social\Model\ActivityPub; use DateTime; use JsonSerializable; +use OCA\Social\Exceptions\InvalidResourceEntryException; use OCA\Social\Service\ActivityService; class Note extends ACore implements JsonSerializable { @@ -195,6 +196,8 @@ class Note extends ACore implements JsonSerializable { /** * @param array $data + * + * @throws InvalidResourceEntryException */ public function import(array $data) { parent::import($data); diff --git a/lib/Service/ActivityPub/NoteService.php b/lib/Service/ActivityPub/NoteService.php index af0257f9..98ae3552 100644 --- a/lib/Service/ActivityPub/NoteService.php +++ b/lib/Service/ActivityPub/NoteService.php @@ -31,14 +31,18 @@ declare(strict_types=1); namespace OCA\Social\Service\ActivityPub; +use daita\MySmallPhpTools\Exceptions\MalformedArrayException; use Exception; use OC\User\NoUserException; use OCA\Social\Db\NotesRequest; use OCA\Social\Exceptions\ActorDoesNotExistException; use OCA\Social\Exceptions\InvalidOriginException; +use OCA\Social\Exceptions\InvalidResourceException; use OCA\Social\Exceptions\NoteNotFoundException; +use OCA\Social\Exceptions\Request410Exception; use OCA\Social\Exceptions\RequestException; use OCA\Social\Exceptions\SocialAppConfigException; +use OCA\Social\Exceptions\UrlCloudException; use OCA\Social\Model\ActivityPub\ACore; use OCA\Social\Model\ActivityPub\Activity\Create; use OCA\Social\Model\ActivityPub\Note; @@ -258,16 +262,27 @@ class NoteService implements ICoreService { /** * @param Note $note * @param string $replyTo + * + * @throws InvalidResourceException + * @throws MalformedArrayException + * @throws NoteNotFoundException + * @throws Request410Exception + * @throws RequestException + * @throws SocialAppConfigException + * @throws UrlCloudException */ public function replyTo(Note $note, string $replyTo) { if ($replyTo === '') { return; } + $author = $this->getAuthorFromPostId($replyTo); $note->setInReplyTo($replyTo); // TODO - type can be NOT public ! $note->addInstancePath( - new InstancePath($replyTo, InstancePath::TYPE_PUBLIC, InstancePath::PRIORITY_HIGH) + new InstancePath( + $author->getSharedInbox(), InstancePath::TYPE_INBOX, InstancePath::PRIORITY_HIGH + ) ); } @@ -417,5 +432,23 @@ class NoteService implements ICoreService { return $this->notesRequest->getStreamTimeline($since, $limit, false); } + + /** + * @param $noteId + * + * @return Person + * @throws NoteNotFoundException + * @throws RequestException + * @throws SocialAppConfigException + * @throws InvalidResourceException + * @throws Request410Exception + * @throws UrlCloudException + * @throws MalformedArrayException + */ + public function getAuthorFromPostId($noteId) { + $note = $this->notesRequest->getNoteById($noteId); + + return $this->personService->getFromId($note->getAttributedTo()); + } } diff --git a/lib/Service/ActivityService.php b/lib/Service/ActivityService.php index 37b3481a..dbacd1fc 100644 --- a/lib/Service/ActivityService.php +++ b/lib/Service/ActivityService.php @@ -159,6 +159,7 @@ class ActivityService { public function createActivity(Person $actor, ACore $item, ACore &$activity = null): string { $activity = new Create(); + $item->setParent($activity); // $this->activityStreamsService->initCore($activity); $this->signObject($actor, $item); |