1
0
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:
Alexander Skvortsov
2021-05-04 14:57:29 -04:00
committed by GitHub
parent e2b309ad95
commit 8ed08b63cd
4 changed files with 126 additions and 31 deletions

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

View File

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