Skip to content

Commit

Permalink
Fixed #1 and #2
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaucau committed Aug 19, 2021
1 parent 9a74da8 commit 0c0c333
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/LoadForumTagsRelationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
use Flarum\Api\Controller\ShowForumController;
use Flarum\Http\RequestUtil;
use Flarum\Tags\Tag;
use Illuminate\Database\Eloquent\Collection;
use Psr\Http\Message\ServerRequestInterface;

class LoadForumTagsRelationship
{
/**
* Load tags that a user is following
* @param ShowForumController $controller
* @param $data
* @param ServerRequestInterface $request
Expand All @@ -18,14 +20,20 @@ public function __invoke(ShowForumController $controller, &$data, ServerRequestI
{
$actor = RequestUtil::getActor($request);

$data['tags'] = Tag::query()
$followedTags = Tag::query()
->join('tag_user', function ($join) use ($actor) {
$join->on('tag_user.tag_id', '=', 'tags.id');
$join->on('tag_user.user_id', '=', resolve('db')->raw($actor->id));
$join->whereNotNull('tag_user.subscription');
})
->selectRaw('tags.*')
->select('tags.*')
->whereVisibleTo($actor)
->get();

$tags = Collection::empty();
$tags = $tags->merge($data['tags']);
$tags = $tags->merge($followedTags);

$data['tags'] = $tags;
}
}

0 comments on commit 0c0c333

Please sign in to comment.