From 0f54d2121eb6dd3b35afd47acd24d621a133e06a Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Sat, 25 Dec 2021 10:12:38 +0000 Subject: [PATCH] [CONTROLLER][Feeds] In Home feed, include specifically subscribed-{person,group,business,organization}, but allow querying for subscribed or subscribed-actor{,s} --- components/Feed/Feed.php | 23 +++++++++++++++++++++-- src/Controller/Feeds.php | 2 +- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/components/Feed/Feed.php b/components/Feed/Feed.php index 2bff473ebe..1f69ad2b0d 100644 --- a/components/Feed/Feed.php +++ b/components/Feed/Feed.php @@ -73,7 +73,8 @@ class Feed extends Component public function onSearchQueryAddJoins(QueryBuilder &$note_qb, QueryBuilder &$actor_qb) { - $note_qb->leftJoin(Subscription::class, 'subscription', Expr\Join::WITH, 'note.actor_id = subscription.subscribed'); + $note_qb->leftJoin(Subscription::class, 'subscription', Expr\Join::WITH, 'note.actor_id = subscription.subscribed') + ->leftJoin(Actor::class, 'note_actor', Expr\Join::WITH, 'note.actor_id = note_actor.id'); return Event::next; } @@ -106,8 +107,26 @@ class Feed extends Component $note_expr = $eb->eq('note.conversation_id', (int) trim($term[1])); break; case 'note-from': + case 'notes-from': + $subscribed_expr = $eb->eq('subscription.subscriber', $actor->getId()); + $type_consts = []; if ($term[1] === 'subscribed') { - $note_expr = $eb->eq('subscription.subscriber', $actor->getId()); + $type_consts = null; + } + foreach (explode(',', $term[1]) as $from) { + if (str_starts_with($from, 'subscribed-')) { + [, $type] = explode('-', $from); + if (\in_array($type, ['actor', 'actors'])) { + $type_consts = null; + } else { + $type_consts[] = \constant(Actor::class . '::' . mb_strtoupper($type)); + } + } + } + if (\is_null($type_consts)) { + $note_expr = $subscribed_expr; + } elseif (!empty($type_consts)) { + $note_expr = $eb->andX($subscribed_expr, $eb->in('note_actor.type', $type_consts)); } break; } diff --git a/src/Controller/Feeds.php b/src/Controller/Feeds.php index 8df6682268..ed527a3341 100644 --- a/src/Controller/Feeds.php +++ b/src/Controller/Feeds.php @@ -75,7 +75,7 @@ class Feeds extends FeedController { Common::ensureLoggedIn(); $data = Feed::query( - query: 'note-from:subscribed', + query: 'note-from:subscribed-person,subscribed-group,subscribed-organization,subscribed-business', page: $this->int('p'), language: Common::actor()?->getTopLanguage()?->getLocale(), actor: Common::actor(),