From 61a28c21711332edca0642ca153f6854ed33591c Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Tue, 4 Dec 2018 23:01:07 -0100 Subject: [PATCH] get public messages from an account Signed-off-by: Maxence Lange --- appinfo/routes.php | 1 + lib/Db/NotesRequest.php | 32 +++++++++++++++++++++++-- lib/Service/ActivityPub/NoteService.php | 2 +- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/appinfo/routes.php b/appinfo/routes.php index 7fc4b1fb..6a595a4e 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -68,6 +68,7 @@ return [ ['name' => 'Local#streamTimeline', 'url' => '/api/v1/stream/timeline', 'verb' => 'GET'], ['name' => 'Local#streamFederated', 'url' => '/api/v1/stream/federated', 'verb' => 'GET'], ['name' => 'Local#streamDirect', 'url' => '/api/v1/stream/direct', 'verb' => 'GET'], + ['name' => 'Local#streamAccount', 'url' => '/api/v1/account/{username}/stream', 'verb' => 'GET'], ['name' => 'Local#postCreate', 'url' => '/api/v1/post', 'verb' => 'POST'], ['name' => 'Local#postDelete', 'url' => '/api/v1/post', 'verb' => 'DELETE'], diff --git a/lib/Db/NotesRequest.php b/lib/Db/NotesRequest.php index cc3fd342..ec9aca9f 100644 --- a/lib/Db/NotesRequest.php +++ b/lib/Db/NotesRequest.php @@ -189,10 +189,38 @@ class NotesRequest extends NotesRequestBuilder { /** - * Should returns: + * Should returns: + * * public message from actorId. + * - to followers-only if follower is logged. + * + * @param string $actorId + * @param int $since + * @param int $limit + * + * @return array + */ + public function getStreamAccount(string $actorId, int $since = 0, int $limit = 5): array { + $qb = $this->getNotesSelectSql(); + $this->limitToRecipient($qb, ActivityService::TO_PUBLIC); + $this->limitPaginate($qb, $since, $limit); + $this->limitToAttributedTo($qb, $actorId); + + $notes = []; + $cursor = $qb->execute(); + while ($data = $cursor->fetch()) { + $notes[] = $this->parseNotesSelectSql($data); + } + $cursor->closeCursor(); + + return $notes; + } + + + /** + * Should returns: * * Private message. * - group messages. - + * * @param string $actorId * @param int $since * @param int $limit diff --git a/lib/Service/ActivityPub/NoteService.php b/lib/Service/ActivityPub/NoteService.php index f99dd13a..8bddea7b 100644 --- a/lib/Service/ActivityPub/NoteService.php +++ b/lib/Service/ActivityPub/NoteService.php @@ -370,7 +370,7 @@ class NoteService implements ICoreService { * @return Note[] */ public function getStreamAccount(string $actorId, int $since = 0, int $limit = 5): array { - return $this->notesRequest->getStreamHome($actorId, $since, $limit); + return $this->notesRequest->getStreamAccount($actorId, $since, $limit); }