summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--appinfo/routes.php3
-rw-r--r--lib/Controller/ApiController.php22
-rw-r--r--lib/Db/StreamRequest.php23
-rw-r--r--lib/Db/StreamRequestBuilder.php2
-rw-r--r--lib/Service/StreamService.php12
-rw-r--r--lib/Tools/Db/ExtendedQueryBuilder.php5
6 files changed, 62 insertions, 5 deletions
diff --git a/appinfo/routes.php b/appinfo/routes.php
index a05daff8..787f0d16 100644
--- a/appinfo/routes.php
+++ b/appinfo/routes.php
@@ -79,11 +79,12 @@ return [
['name' => 'Api#instance', 'url' => '/api/v1/instance/', 'verb' => 'GET'],
['name' => 'Api#customEmojis', 'url' => '/api/v1/custom_emojis', 'verb' => 'GET'],
['name' => 'Api#savedSearches', 'url' => '/api/saved_searches/list.json', 'verb' => 'GET'],
+ ['name' => 'Api#timelines', 'url' => '/api/v1/timelines/{timeline}/', 'verb' => 'GET'],
['name' => 'Api#favourites', 'url' => '/api/v1/favourites/', 'verb' => 'GET'],
['name' => 'Api#notifications', 'url' => '/api/v1/notifications', 'verb' => 'GET'],
['name' => 'Api#tag', 'url' => '/api/v1/timelines/tag/{hashtag}', 'verb' => 'GET'],
['name' => 'Api#statusNew', 'url' => '/api/v1/statuses', 'verb' => 'POST'],
- ['name' => 'Api#timelines', 'url' => '/api/v1/timelines/{timeline}/', 'verb' => 'GET'],
+ ['name' => 'Api#statusGet', 'url' => '/api/v1/statuses/{nid}', 'verb' => 'GET'],
['name' => 'Api#accountStatuses', 'url' => '/api/v1/accounts/{account}/statuses', 'verb' => 'GET'],
// Api for local front-end
diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php
index a31894bd..71d0cde2 100644
--- a/lib/Controller/ApiController.php
+++ b/lib/Controller/ApiController.php
@@ -285,6 +285,28 @@ class ApiController extends Controller {
* @NoCSRFRequired
* @PublicPage
*
+ * @param int $nid
+ *
+ * @return DataResponse
+ */
+ public function statusGet(int $nid): DataResponse {
+ try {
+ $this->initViewer(true);
+
+ $item = $this->streamService->getStreamByNid($nid);
+
+ return new DataResponse($item, Http::STATUS_OK);
+ } catch (Exception $e) {
+ return $this->error($e->getMessage());
+ }
+ }
+
+
+
+ /**
+ * @NoCSRFRequired
+ * @PublicPage
+ *
* @param string $account
* @param int $limit
* @param int $max_id
diff --git a/lib/Db/StreamRequest.php b/lib/Db/StreamRequest.php
index 88488a19..9e0c18ff 100644
--- a/lib/Db/StreamRequest.php
+++ b/lib/Db/StreamRequest.php
@@ -228,6 +228,26 @@ class StreamRequest extends StreamRequestBuilder {
/**
+ * @param string $id
+ * @param bool $asViewer
+ * @param int $format
+ *
+ * @return Stream
+ * @throws StreamNotFoundException
+ */
+ public function getStreamByNid(int $nid): Stream {
+ $qb = $this->getStreamSelectSql(ACore::FORMAT_LOCAL);
+ $qb->limitToNid($nid);
+ $qb->linkToCacheActors('ca', 's.attributed_to_prim');
+
+ $qb->limitToViewer('sd', 'f', true, true);
+ $qb->leftJoinStreamAction('sa');
+
+ return $this->getStreamFromRequest($qb);
+ }
+
+
+ /**
* @param string $idPrim
*
* @return Stream
@@ -446,8 +466,6 @@ class StreamRequest extends StreamRequestBuilder {
}
-
-
/**
* Should returns:
* - public message from actorId.
@@ -482,7 +500,6 @@ class StreamRequest extends StreamRequestBuilder {
}
-
/**
* @param TimelineOptions $options
*
diff --git a/lib/Db/StreamRequestBuilder.php b/lib/Db/StreamRequestBuilder.php
index 634d2db1..e2b421d1 100644
--- a/lib/Db/StreamRequestBuilder.php
+++ b/lib/Db/StreamRequestBuilder.php
@@ -172,7 +172,7 @@ class StreamRequestBuilder extends CoreRequestBuilder {
try {
$result = $qb->getRow([$this, 'parseStreamSelectSql']);
} catch (RowNotFoundException $e) {
- throw new StreamNotFoundException($e->getMessage());
+ throw new StreamNotFoundException('stream not found');
}
return $result;
diff --git a/lib/Service/StreamService.php b/lib/Service/StreamService.php
index 501c6e4a..0b72fc40 100644
--- a/lib/Service/StreamService.php
+++ b/lib/Service/StreamService.php
@@ -360,6 +360,18 @@ class StreamService {
/**
* @param string $id
+ * @param bool $asViewer
+ *
+ * @return Stream
+ * @throws StreamNotFoundException
+ */
+ public function getStreamByNid(int $nid): Stream {
+ return $this->streamRequest->getStreamByNid($nid);
+ }
+
+
+ /**
+ * @param string $id
* @param int $since
* @param int $limit
* @param bool $asViewer
diff --git a/lib/Tools/Db/ExtendedQueryBuilder.php b/lib/Tools/Db/ExtendedQueryBuilder.php
index 32f5d0a6..cda11f80 100644
--- a/lib/Tools/Db/ExtendedQueryBuilder.php
+++ b/lib/Tools/Db/ExtendedQueryBuilder.php
@@ -86,6 +86,11 @@ class ExtendedQueryBuilder extends QueryBuilder implements IExtendedQueryBuilder
}
+ public function limitToNid(int $id): void {
+ $this->limitToDBFieldInt('nid', $id);
+ }
+
+
/**
* @param array $ids
*