diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2018-12-18 17:47:01 -0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-18 17:47:01 -0100 |
commit | 7a3d006dabb4a47b044ae0b1f4e6a1187d8352c2 (patch) | |
tree | f8b6f456d5fe0a5425d0bff347f6ffa13875ed2d /lib | |
parent | 99b404785ecca1eac1f8222eba1d2d6c816c276d (diff) | |
parent | a493363a1aa9ae44c7c85758dd009c503cae1141 (diff) |
Merge pull request #181 from nextcloud/notifications-stream
adding route and content to the Notification Stream
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Controller/LocalController.php | 25 | ||||
-rw-r--r-- | lib/Db/NotesRequest.php | 38 | ||||
-rw-r--r-- | lib/Service/ActivityPub/NoteService.php | 12 |
3 files changed, 72 insertions, 3 deletions
diff --git a/lib/Controller/LocalController.php b/lib/Controller/LocalController.php index ee7a0376..ceaa8329 100644 --- a/lib/Controller/LocalController.php +++ b/lib/Controller/LocalController.php @@ -211,6 +211,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); + } + } + + + /** * @NoAdminRequired * @NoSubAdminRequired diff --git a/lib/Db/NotesRequest.php b/lib/Db/NotesRequest.php index 8d2a6ea1..812859f0 100644 --- a/lib/Db/NotesRequest.php +++ b/lib/Db/NotesRequest.php @@ -188,8 +188,40 @@ class NotesRequest extends NotesRequestBuilder { /** * Should returns: + * * 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 + * @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. - * - to followers-only if follower is logged. + * - to followers-only if follower is logged. (not yet (check ?)) * * @param string $actorId * @param int $since @@ -218,7 +250,7 @@ class NotesRequest extends NotesRequestBuilder { /** * Should returns: * * Private message. - * - group messages. + * - group messages. (not yet) * * @param Person $actor * @param int $since @@ -249,7 +281,7 @@ class NotesRequest extends NotesRequestBuilder { /** * Should returns: - * - All local public/federated posts + * * All local public/federated posts * * @param int $since * @param int $limit 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 @@ -362,6 +362,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 * @param int $limit |