[CONTROLLER][Feeds] In Home feed, include specifically subscribed-{person,group,business,organization}, but allow querying for subscribed or subscribed-actor{,s}

This commit is contained in:
Hugo Sales 2021-12-25 10:12:38 +00:00
parent dad322e577
commit 0f54d2121e
No known key found for this signature in database
GPG Key ID: 7D0C7EAFC9D835A0
2 changed files with 22 additions and 3 deletions

View File

@ -73,7 +73,8 @@ class Feed extends Component
public function onSearchQueryAddJoins(QueryBuilder &$note_qb, QueryBuilder &$actor_qb) 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; return Event::next;
} }
@ -106,8 +107,26 @@ class Feed extends Component
$note_expr = $eb->eq('note.conversation_id', (int) trim($term[1])); $note_expr = $eb->eq('note.conversation_id', (int) trim($term[1]));
break; break;
case 'note-from': case 'note-from':
case 'notes-from':
$subscribed_expr = $eb->eq('subscription.subscriber', $actor->getId());
$type_consts = [];
if ($term[1] === 'subscribed') { 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; break;
} }

View File

@ -75,7 +75,7 @@ class Feeds extends FeedController
{ {
Common::ensureLoggedIn(); Common::ensureLoggedIn();
$data = Feed::query( $data = Feed::query(
query: 'note-from:subscribed', query: 'note-from:subscribed-person,subscribed-group,subscribed-organization,subscribed-business',
page: $this->int('p'), page: $this->int('p'),
language: Common::actor()?->getTopLanguage()?->getLocale(), language: Common::actor()?->getTopLanguage()?->getLocale(),
actor: Common::actor(), actor: Common::actor(),