mirror of
https://github.com/flarum/core.git
synced 2025-08-14 20:34:10 +02:00
Fix mentioned filtering (#67)
This commit is contained in:
committed by
GitHub
parent
e2b309ad95
commit
8ed08b63cd
31
extensions/mentions/src/Filter/MentionedFilter.php
Normal file
31
extensions/mentions/src/Filter/MentionedFilter.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* For detailed copyright and license information, please view the
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Mentions\Filter;
|
||||
|
||||
use Flarum\Filter\FilterInterface;
|
||||
use Flarum\Filter\FilterState;
|
||||
|
||||
class MentionedFilter implements FilterInterface
|
||||
{
|
||||
public function getFilterKey(): string
|
||||
{
|
||||
return 'mentioned';
|
||||
}
|
||||
|
||||
public function filter(FilterState $filterState, string $filterValue, bool $negate)
|
||||
{
|
||||
$mentionedId = trim($filterValue, '"');
|
||||
|
||||
$filterState
|
||||
->getQuery()
|
||||
->join('post_mentions_user', 'posts.id', '=', 'post_mentions_user.post_id')
|
||||
->where('post_mentions_user.mentions_user_id', $negate ? '!=' : '=', $mentionedId);
|
||||
}
|
||||
}
|
@@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* For detailed copyright and license information, please view the
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Mentions\Listener;
|
||||
|
||||
use Flarum\Event\ConfigurePostsQuery;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class AddFilterByMentions
|
||||
{
|
||||
public function handle(ConfigurePostsQuery $event)
|
||||
{
|
||||
if ($mentionedId = Arr::get($event->filter, 'mentioned')) {
|
||||
$event->query->join('post_mentions_user', 'posts.id', '=', 'post_mentions_user.post_id')
|
||||
->where('post_mentions_user.mentions_user_id', '=', $mentionedId);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user