summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2019-05-17 16:33:21 -0100
committerMaxence Lange <maxence@artificial-owl.com>2019-05-17 16:33:21 -0100
commitecdf7e6cf656c22656e8071c7c0f517efbf4ec1d (patch)
tree25ab753fdd49f3d9455ed4bf134eb5f7996c69dd
parent8f1f3a41b65b22470f4e50b4d4fecde71639a90a (diff)
+filterHiddenOnTimeline()
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
-rw-r--r--lib/AP.php4
-rw-r--r--lib/Db/StreamRequest.php30
-rw-r--r--lib/Db/StreamRequestBuilder.php38
-rw-r--r--lib/Model/ActivityPub/Stream.php23
-rw-r--r--lib/Service/BoostService.php2
-rw-r--r--lib/Service/NoteService.php14
6 files changed, 88 insertions, 23 deletions
diff --git a/lib/AP.php b/lib/AP.php
index 75d1d1d8..5db1eabc 100644
--- a/lib/AP.php
+++ b/lib/AP.php
@@ -278,6 +278,7 @@ class AP {
case Announce::TYPE:
$item = new Announce();
+ $item->setHiddenOnTimeline(true);
break;
case Block::TYPE:
@@ -313,7 +314,8 @@ class AP {
break;
case SocialAppNotification::TYPE:
- return new SocialAppNotification();
+ $item = new SocialAppNotification();
+ break;
case Person::TYPE:
$item = new Person();
diff --git a/lib/Db/StreamRequest.php b/lib/Db/StreamRequest.php
index d427fee2..2c39fc12 100644
--- a/lib/Db/StreamRequest.php
+++ b/lib/Db/StreamRequest.php
@@ -237,11 +237,13 @@ class StreamRequest extends StreamRequestBuilder {
* @return Stream[]
* @throws Exception
*/
- public function getStreamHome(Person $actor, int $since = 0, int $limit = 5): array {
+ public function getTimelineHome(Person $actor, int $since = 0, int $limit = 5): array {
$qb = $this->getStreamSelectSql();
$this->joinFollowing($qb, $actor);
$this->limitPaginate($qb, $since, $limit);
+ $this->filterHiddenOnTimeline($qb);
+
$this->leftJoinCacheActors($qb, 'attributed_to');
$this->leftJoinStreamAction($qb);
@@ -274,11 +276,12 @@ class StreamRequest extends StreamRequestBuilder {
* @return array
* @throws Exception
*/
- public function getStreamNotifications(Person $actor, int $since = 0, int $limit = 5): array {
+ public function getTimelineNotifications(Person $actor, int $since = 0, int $limit = 5): array {
$qb = $this->getStreamSelectSql();
$this->limitPaginate($qb, $since, $limit);
$this->limitToRecipient($qb, $actor->getId(), false);
+
$this->leftJoinCacheActors($qb, 'attributed_to');
$this->leftJoinStreamAction($qb);
@@ -308,13 +311,14 @@ class StreamRequest extends StreamRequestBuilder {
* @return array
* @throws Exception
*/
- public function getStreamAccount(string $actorId, int $since = 0, int $limit = 5): array {
+ public function getTimelineAccount(string $actorId, int $since = 0, int $limit = 5): array {
$qb = $this->getStreamSelectSql();
$this->limitPaginate($qb, $since, $limit);
$this->limitToAttributedTo($qb, $actorId);
- $this->leftJoinCacheActors($qb, 'attributed_to');
$this->limitToRecipient($qb, ACore::CONTEXT_PUBLIC);
+
+ $this->leftJoinCacheActors($qb, 'attributed_to');
$this->leftJoinStreamAction($qb);
$streams = [];
@@ -343,13 +347,14 @@ class StreamRequest extends StreamRequestBuilder {
* @return array
* @throws Exception
*/
- public function getStreamDirect(Person $actor, int $since = 0, int $limit = 5): array {
+ public function getTimelineDirect(Person $actor, int $since = 0, int $limit = 5): array {
$qb = $this->getStreamSelectSql();
$this->limitPaginate($qb, $since, $limit);
$this->limitToRecipient($qb, $actor->getId(), true);
- $this->filterToRecipient($qb, ACore::CONTEXT_PUBLIC);
- $this->filterToRecipient($qb, $actor->getFollowers());
+ $this->filterRecipient($qb, ACore::CONTEXT_PUBLIC);
+ $this->filterRecipient($qb, $actor->getFollowers());
+ $this->filterHiddenOnTimeline($qb);
$this->leftJoinCacheActors($qb, 'attributed_to');
@@ -378,7 +383,7 @@ class StreamRequest extends StreamRequestBuilder {
* @return array
* @throws Exception
*/
- public function getStreamTimeline(int $since = 0, int $limit = 5, bool $localOnly = true
+ public function getTimelineGlobal(int $since = 0, int $limit = 5, bool $localOnly = true
): array {
$qb = $this->getStreamSelectSql();
$this->limitPaginate($qb, $since, $limit);
@@ -387,6 +392,7 @@ class StreamRequest extends StreamRequestBuilder {
$this->limitToLocal($qb, true);
}
+ $this->filterHiddenOnTimeline($qb);
$this->leftJoinCacheActors($qb, 'attributed_to');
$this->leftJoinStreamAction($qb);
@@ -421,7 +427,7 @@ class StreamRequest extends StreamRequestBuilder {
* @return array
* @throws Exception
*/
- public function getStreamTag(Person $actor, string $hashtag, int $since = 0, int $limit = 5
+ public function getTimelineTag(Person $actor, string $hashtag, int $since = 0, int $limit = 5
): array {
$qb = $this->getStreamSelectSql();
@@ -433,6 +439,8 @@ class StreamRequest extends StreamRequestBuilder {
$qb->andWhere($this->exprValueWithinJsonFormat($qb, 'hashtags', '' . $hashtag));
$this->limitPaginate($qb, $since, $limit);
+ $this->filterHiddenOnTimeline($qb);
+
$this->leftJoinCacheActors($qb, 'attributed_to');
$this->leftJoinStreamAction($qb);
@@ -552,6 +560,10 @@ class StreamRequest extends StreamRequestBuilder {
->setValue('object_id', $qb->createNamedParameter($stream->getObjectId()))
->setValue('cache', $qb->createNamedParameter($cache))
->setValue(
+ 'hidden_on_timeline',
+ $qb->createNamedParameter(($stream->isHiddenOnTimeline()) ? '1' : '0')
+ )
+ ->setValue(
'instances', $qb->createNamedParameter(
json_encode($stream->getInstancePaths(), JSON_UNESCAPED_SLASHES)
)
diff --git a/lib/Db/StreamRequestBuilder.php b/lib/Db/StreamRequestBuilder.php
index 254d3ca0..14b5f59c 100644
--- a/lib/Db/StreamRequestBuilder.php
+++ b/lib/Db/StreamRequestBuilder.php
@@ -92,9 +92,8 @@ class StreamRequestBuilder extends CoreRequestBuilder {
->addSelect(
's.type', 's.to', 's.to_array', 's.cc', 's.bcc', 's.content',
's.summary', 's.attachments', 's.published', 's.published_time', 's.cache',
- 's.object_id',
- 's.attributed_to', 's.in_reply_to', 's.source', 's.local', 's.instances',
- 's.creation'
+ 's.object_id', 's.attributed_to', 's.in_reply_to', 's.source', 's.local',
+ 's.instances', 's.creation', 's.hidden_on_timeline'
)
->from(self::TABLE_STREAMS, 's');
@@ -150,6 +149,36 @@ class StreamRequestBuilder extends CoreRequestBuilder {
/**
* @param IQueryBuilder $qb
+ */
+ protected function filterHiddenOnTimeline(IQueryBuilder $qb) {
+ $actor = $this->viewer;
+
+ if ($actor === null) {
+ return;
+ }
+
+ $func = $qb->func();
+ $expr = $qb->expr();
+ $filter = $expr->orX();
+ $filter->add(
+ $expr->neq(
+ $func->lower('attributed_to'),
+ $func->lower($qb->createNamedParameter($actor->getId()))
+ )
+ );
+ $filter->add(
+ $expr->eq(
+ 'hidden_on_timeline',
+ $qb->createNamedParameter('0')
+ )
+ );
+
+ $qb->andwhere($filter);
+ }
+
+
+ /**
+ * @param IQueryBuilder $qb
* @param Person $actor
*/
protected function joinFollowing(IQueryBuilder $qb, Person $actor) {
@@ -343,7 +372,7 @@ class StreamRequestBuilder extends CoreRequestBuilder {
* @param IQueryBuilder $qb
* @param string $recipient
*/
- protected function filterToRecipient(IQueryBuilder &$qb, string $recipient) {
+ protected function filterRecipient(IQueryBuilder &$qb, string $recipient) {
$expr = $qb->expr();
$filter = $expr->andX();
@@ -354,7 +383,6 @@ class StreamRequestBuilder extends CoreRequestBuilder {
$filter->add($this->exprValueNotWithinJsonFormat($qb, 'bcc', $recipient));
$qb->andWhere($filter);
-// return $filter;
}
diff --git a/lib/Model/ActivityPub/Stream.php b/lib/Model/ActivityPub/Stream.php
index 6fdfee08..8c40d0bf 100644
--- a/lib/Model/ActivityPub/Stream.php
+++ b/lib/Model/ActivityPub/Stream.php
@@ -74,6 +74,9 @@ class Stream extends ACore implements JsonSerializable {
/** @var StreamAction */
private $action = null;
+ /** @var bool */
+ private $hiddenOnTimeline = false;
+
public function __construct($parent = null) {
parent::__construct($parent);
@@ -289,6 +292,25 @@ class Stream extends ACore implements JsonSerializable {
/**
+ * @return bool
+ */
+ public function isHiddenOnTimeline(): bool {
+ return $this->hiddenOnTimeline;
+ }
+
+ /**
+ * @param bool $hiddenOnTimeline
+ *
+ * @return Stream
+ */
+ public function setHiddenOnTimeline(bool $hiddenOnTimeline): Stream {
+ $this->hiddenOnTimeline = $hiddenOnTimeline;
+
+ return $this;
+ }
+
+
+ /**
* @param array $data
*/
public function import(array $data) {
@@ -321,6 +343,7 @@ class Stream extends ACore implements JsonSerializable {
$this->setObjectId($this->validate(self::AS_ID, 'object_id', $data, ''));
$this->setAttributedTo($this->validate(self::AS_ID, 'attributed_to', $data, ''));
$this->setInReplyTo($this->validate(self::AS_ID, 'in_reply_to', $data));
+ $this->setHiddenOnTimeline($this->getBool('hidden_on_timeline', $data, false));
$cache = new Cache();
$cache->import($this->getArray('cache', $data, []));
diff --git a/lib/Service/BoostService.php b/lib/Service/BoostService.php
index 44a27a2a..bf705e4a 100644
--- a/lib/Service/BoostService.php
+++ b/lib/Service/BoostService.php
@@ -120,7 +120,7 @@ class BoostService {
} catch (StreamNotFoundException $e) {
}
- $announce = new Announce();
+ $announce = AP::$activityPub->getItemFromType(Announce::TYPE);
$this->noteService->assignItem($announce, $actor, Stream::TYPE_PUBLIC);
$announce->setActor($actor);
diff --git a/lib/Service/NoteService.php b/lib/Service/NoteService.php
index 1799f955..e865d03b 100644
--- a/lib/Service/NoteService.php
+++ b/lib/Service/NoteService.php
@@ -349,7 +349,7 @@ class NoteService {
* @throws Exception
*/
public function getStreamHome(Person $actor, int $since = 0, int $limit = 5): array {
- return $this->streamRequest->getStreamHome($actor, $since, $limit);
+ return $this->streamRequest->getTimelineHome($actor, $since, $limit);
}
@@ -362,7 +362,7 @@ class NoteService {
* @throws Exception
*/
public function getStreamNotifications(Person $actor, int $since = 0, int $limit = 5): array {
- return $this->streamRequest->getStreamNotifications($actor, $since, $limit);
+ return $this->streamRequest->getTimelineNotifications($actor, $since, $limit);
}
@@ -375,7 +375,7 @@ class NoteService {
* @throws Exception
*/
public function getStreamAccount(string $actorId, int $since = 0, int $limit = 5): array {
- return $this->streamRequest->getStreamAccount($actorId, $since, $limit);
+ return $this->streamRequest->getTimelineAccount($actorId, $since, $limit);
}
@@ -388,7 +388,7 @@ class NoteService {
* @throws Exception
*/
public function getStreamDirect(Person $actor, int $since = 0, int $limit = 5): array {
- return $this->streamRequest->getStreamDirect($actor, $since, $limit);
+ return $this->streamRequest->getTimelineDirect($actor, $since, $limit);
}
@@ -400,7 +400,7 @@ class NoteService {
* @throws Exception
*/
public function getStreamLocalTimeline(int $since = 0, int $limit = 5): array {
- return $this->streamRequest->getStreamTimeline($since, $limit, true);
+ return $this->streamRequest->getTimelineGlobal($since, $limit, true);
}
@@ -415,7 +415,7 @@ class NoteService {
*/
public function getStreamLocalTag(Person $actor, string $hashtag, int $since = 0, int $limit = 5
): array {
- return $this->streamRequest->getStreamTag($actor, $hashtag, $since, $limit);
+ return $this->streamRequest->getTimelineTag($actor, $hashtag, $since, $limit);
}
@@ -440,7 +440,7 @@ class NoteService {
* @throws Exception
*/
public function getStreamGlobalTimeline(int $since = 0, int $limit = 5): array {
- return $this->streamRequest->getStreamTimeline($since, $limit, false);
+ return $this->streamRequest->getTimelineGlobal($since, $limit, false);
}