+filterHiddenOnTimeline()

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
pull/528/head
Maxence Lange 2019-05-17 16:33:21 -01:00
rodzic 8f1f3a41b6
commit ecdf7e6cf6
6 zmienionych plików z 88 dodań i 23 usunięć

Wyświetl plik

@ -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();

Wyświetl plik

@ -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);
@ -551,6 +559,10 @@ class StreamRequest extends StreamRequestBuilder {
->setValue('activity_id', $qb->createNamedParameter($stream->getActivityId()))
->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)

Wyświetl plik

@ -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');
@ -148,6 +147,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
@ -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;
}

Wyświetl plik

@ -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);
@ -288,6 +291,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
*/
@ -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, []));

Wyświetl plik

@ -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);

Wyświetl plik

@ -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);
}