summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2020-10-22 15:01:15 +0200
committerRobin Appelman <robin@icewind.nl>2020-10-22 15:01:37 +0200
commit8c070ee248e8bb36c3e2373ad9f74eeb04d470e2 (patch)
tree19c2c787feb67921b14c8cf2d209f8c8cf22e8fd
parentd0459734496fcd8c0d922d1d17aced3429eb68c8 (diff)
add public timeline for mastodon api
Signed-off-by: Robin Appelman <robin@icewind.nl>
-rw-r--r--lib/Command/Timeline.php4
-rw-r--r--lib/Db/StreamRequest.php36
-rw-r--r--lib/Service/StreamService.php8
3 files changed, 40 insertions, 8 deletions
diff --git a/lib/Command/Timeline.php b/lib/Command/Timeline.php
index d8334b34..8330afd0 100644
--- a/lib/Command/Timeline.php
+++ b/lib/Command/Timeline.php
@@ -169,12 +169,12 @@ class Timeline extends ExtendedBase {
break;
case 'local':
- $stream = $this->streamRequest->getTimelineGlobal(0, $this->count, true);
+ $stream = $this->streamRequest->getTimelineGlobal_dep(0, $this->count, true);
$this->outputStreams($stream);
break;
case 'global':
- $stream = $this->streamRequest->getTimelineGlobal(0, $this->count, false);
+ $stream = $this->streamRequest->getTimelineGlobal_dep(0, $this->count, false);
$this->outputStreams($stream);
break;
diff --git a/lib/Db/StreamRequest.php b/lib/Db/StreamRequest.php
index 7e5ec825..6b4c677b 100644
--- a/lib/Db/StreamRequest.php
+++ b/lib/Db/StreamRequest.php
@@ -412,7 +412,7 @@ class StreamRequest extends StreamRequestBuilder {
*
* @return Stream[]
* @throws DateTimeException
- * @deprecated - use GetTimeline()
+ * @deprecated - use getTimelineHome()
*/
public function getTimelineHome_dep(
int $since = 0, int $limit = 5, int $format = Stream::FORMAT_ACTIVITYPUB
@@ -521,6 +521,37 @@ class StreamRequest extends StreamRequestBuilder {
return $this->getStreamsFromRequest($qb);
}
+ /**
+ * Should returns:
+ * * All local public/federated posts
+ *
+ * @param TimelineOptions $options
+ *
+ * @return Stream[]
+ * @throws DateTimeException
+ */
+ public function getTimelinePublic(TimelineOptions $options): array {
+ $qb = $this->getStreamSelectSql($options->getFormat());
+ $qb->paginate($options);
+
+ $qb->limitToLocal($options->isLocal());
+ $qb->limitToType(Note::TYPE);
+
+ $qb->linkToCacheActors('ca', 's.attributed_to_prim');
+ $qb->leftJoinStreamAction();
+
+ $qb->selectDestFollowing('sd', '');
+ $qb->innerJoinSteamDest('recipient', 'id_prim', 'sd', 's');
+ $qb->limitToDest(ACore::CONTEXT_PUBLIC, 'recipient', 'to', 'sd');
+
+ $result = $this->getStreamsFromRequest($qb);
+ if ($options->isInverted()) {
+ $result = array_reverse($result);
+ }
+
+ return $result;
+ }
+
/**
* Should returns:
@@ -532,8 +563,9 @@ class StreamRequest extends StreamRequestBuilder {
*
* @return Stream[]
* @throws DateTimeException
+ * @deprecated - use getTimelinePublic()
*/
- public function getTimelineGlobal(int $since = 0, int $limit = 5, bool $localOnly = true
+ public function getTimelineGlobal_dep(int $since = 0, int $limit = 5, bool $localOnly = true
): array {
$qb = $this->getStreamSelectSql();
$qb->limitPaginate($since, $limit);
diff --git a/lib/Service/StreamService.php b/lib/Service/StreamService.php
index 8c37cf54..c8f21513 100644
--- a/lib/Service/StreamService.php
+++ b/lib/Service/StreamService.php
@@ -426,9 +426,9 @@ class StreamService {
public function getTimeline(TimelineOptions $options): array {
if ($options->getTimeline() === 'home') {
return $this->streamRequest->getTimelineHome($options);
+ } else if ($options->getTimeline() === 'public') {
+ return $this->streamRequest->getTimelinePublic($options);
}
-
-
}
/**
@@ -480,7 +480,7 @@ class StreamService {
* @deprecated
*/
public function getStreamLocalTimeline(int $since = 0, int $limit = 5): array {
- return $this->streamRequest->getTimelineGlobal($since, $limit, true);
+ return $this->streamRequest->getTimelineGlobal_dep($since, $limit, true);
}
@@ -518,7 +518,7 @@ class StreamService {
* @throws Exception
*/
public function getStreamGlobalTimeline(int $since = 0, int $limit = 5): array {
- return $this->streamRequest->getTimelineGlobal($since, $limit, false);
+ return $this->streamRequest->getTimelineGlobal_dep($since, $limit, false);
}