From 8df77ff38059cf6fa01164078b4f30b03ce6192b Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Sat, 8 Dec 2018 11:41:56 -0100 Subject: [PATCH 1/2] adding route and content to the Notification Stream --- appinfo/routes.php | 1 + lib/Controller/LocalController.php | 25 +++++++++++++++++++ lib/Db/NotesRequest.php | 32 +++++++++++++++++++++++++ lib/Service/ActivityPub/NoteService.php | 12 ++++++++++ 4 files changed, 70 insertions(+) diff --git a/appinfo/routes.php b/appinfo/routes.php index 6a595a4e..506a89aa 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -65,6 +65,7 @@ return [ ['name' => 'SocialPub#displayPost', 'url' => '/@{username}/{postId}', 'verb' => 'GET'], ['name' => 'Local#streamHome', 'url' => '/api/v1/stream/home', 'verb' => 'GET'], + ['name' => 'Local#streamNotifications', 'url' => '/api/v1/stream/notifications', 'verb' => 'GET'], ['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'], diff --git a/lib/Controller/LocalController.php b/lib/Controller/LocalController.php index a99782d9..7ee27ebc 100644 --- a/lib/Controller/LocalController.php +++ b/lib/Controller/LocalController.php @@ -217,6 +217,31 @@ class LocalController extends Controller { } + + + /** + * @NoCSRFRequired + * @NoAdminRequired + * @NoSubAdminRequired + * + * @param int $since + * @param int $limit + * + * @return DataResponse + */ + public function streamNotifications($since = 0, int $limit = 5): DataResponse { + try { + $this->initViewer(true); + $posts = $this->noteService->getStreamNotifications($this->viewer, $since, $limit); + + return $this->success($posts); + } catch (Exception $e) { + return $this->fail($e); + } + } + + + /** * // TODO: Delete the NoCSRF check * diff --git a/lib/Db/NotesRequest.php b/lib/Db/NotesRequest.php index 9e687e25..74fa6faa 100644 --- a/lib/Db/NotesRequest.php +++ b/lib/Db/NotesRequest.php @@ -185,6 +185,38 @@ class NotesRequest extends NotesRequestBuilder { } + /** + * Should returns: + * - Public/Unlisted/Followers-only post where current $actor is tagged, + * - Events: + * - people liking or re-posting your posts + * - someone wants to follow you + * - someone is following you + * + * @param Person $actor + * @param int $since + * @param int $limit + * + * @return array + */ + public function getStreamNotifications(Person $actor, int $since = 0, int $limit = 5): array { + $qb = $this->getNotesSelectSql(); + + $this->limitPaginate($qb, $since, $limit); + $this->limitToRecipient($qb, $actor->getId(), false); + $this->leftJoinCacheActors($qb, 'attributed_to'); + + $notes = []; + $cursor = $qb->execute(); + while ($data = $cursor->fetch()) { + $notes[] = $this->parseNotesSelectSql($data); + } + $cursor->closeCursor(); + + return $notes; + } + + /** * Should returns: * * public message from actorId. diff --git a/lib/Service/ActivityPub/NoteService.php b/lib/Service/ActivityPub/NoteService.php index af0257f9..e721c24c 100644 --- a/lib/Service/ActivityPub/NoteService.php +++ b/lib/Service/ActivityPub/NoteService.php @@ -361,6 +361,18 @@ class NoteService implements ICoreService { } + /** + * @param Person $actor + * @param int $since + * @param int $limit + * + * @return Note[] + */ + public function getStreamNotifications(Person $actor, int $since = 0, int $limit = 5): array { + return $this->notesRequest->getStreamNotifications($actor, $since, $limit); + } + + /** * @param string $actorId * @param int $since From a493363a1aa9ae44c7c85758dd009c503cae1141 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Tue, 18 Dec 2018 17:37:05 -0100 Subject: [PATCH 2/2] fixing phpdoc Signed-off-by: Maxence Lange --- lib/Db/NotesRequest.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/Db/NotesRequest.php b/lib/Db/NotesRequest.php index 74fa6faa..856e6cdc 100644 --- a/lib/Db/NotesRequest.php +++ b/lib/Db/NotesRequest.php @@ -187,11 +187,11 @@ class NotesRequest extends NotesRequestBuilder { /** * Should returns: - * - Public/Unlisted/Followers-only post where current $actor is tagged, - * - Events: - * - people liking or re-posting your posts - * - someone wants to follow you - * - someone is following you + * * Public/Unlisted/Followers-only post where current $actor is tagged, + * - Events: (not yet) + * - people liking or re-posting your posts (not yet) + * - someone wants to follow you (not yet) + * - someone is following you (not yet) * * @param Person $actor * @param int $since @@ -220,7 +220,7 @@ class NotesRequest extends NotesRequestBuilder { /** * Should returns: * * public message from actorId. - * - to followers-only if follower is logged. + * - to followers-only if follower is logged. (not yet (check ?)) * * @param string $actorId * @param int $since @@ -249,7 +249,7 @@ class NotesRequest extends NotesRequestBuilder { /** * Should returns: * * Private message. - * - group messages. + * - group messages. (not yet) * * @param Person $actor * @param int $since @@ -280,7 +280,7 @@ class NotesRequest extends NotesRequestBuilder { /** * Should returns: - * - All local public/federated posts + * * All local public/federated posts * * @param int $since * @param int $limit