From db55361148c570b16a95f8a71294dc46e0cc8833 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Thu, 24 Jan 2019 10:27:36 -0100 Subject: [PATCH] activityId is saved in db for streamable objects Signed-off-by: Maxence Lange --- lib/Db/CoreRequestBuilder.php | 11 +++++++++++ lib/Db/NotesRequest.php | 26 +++++++++++++++++++++++++ lib/Interfaces/Object/NoteInterface.php | 3 +-- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/lib/Db/CoreRequestBuilder.php b/lib/Db/CoreRequestBuilder.php index c6c7dbb5..73b0708c 100644 --- a/lib/Db/CoreRequestBuilder.php +++ b/lib/Db/CoreRequestBuilder.php @@ -147,6 +147,17 @@ class CoreRequestBuilder { } + /** + * Limit the request to the ActivityId + * + * @param IQueryBuilder $qb + * @param string $activityId + */ + protected function limitToActivityId(IQueryBuilder &$qb, string $activityId) { + $this->limitToDBField($qb, 'activity_id', $activityId, false); + } + + /** * Limit the request to the Preferred Username * diff --git a/lib/Db/NotesRequest.php b/lib/Db/NotesRequest.php index 3d42679e..343fc1c2 100644 --- a/lib/Db/NotesRequest.php +++ b/lib/Db/NotesRequest.php @@ -157,6 +157,32 @@ class NotesRequest extends NotesRequestBuilder { } + /** + * @param string $id + * + * @return Note + * @throws NoteNotFoundException + */ + public function getNoteByActivityId(string $id): Note { + if ($id === '') { + throw new NoteNotFoundException(); + }; + + $qb = $this->getNotesSelectSql(); + $this->limitToActivityId($qb, $id); + + $cursor = $qb->execute(); + $data = $cursor->fetch(); + $cursor->closeCursor(); + + if ($data === false) { + throw new NoteNotFoundException('Post not found'); + } + + return $this->parseNotesSelectSql($data); + } + + /** * @param string $actorId * diff --git a/lib/Interfaces/Object/NoteInterface.php b/lib/Interfaces/Object/NoteInterface.php index 612d2081..d807ab98 100644 --- a/lib/Interfaces/Object/NoteInterface.php +++ b/lib/Interfaces/Object/NoteInterface.php @@ -134,10 +134,9 @@ class NoteInterface implements IActivityPubInterface { if ($activity->getType() === Create::TYPE) { $activity->checkOrigin($item->getId()); $activity->checkOrigin($item->getAttributedTo()); + $item->setActivityId($activity->getId()); $this->save($item); } - - }