Use criteria's sortIsDefault field

This was introduced in https://github.com/flarum/core/pull/2773, and allows us to more cleanly determine whether the sort requested is the default one, while taking extension modifications into account.
This commit is contained in:
Alexander Skvortsov 2021-04-11 22:29:20 -04:00
parent 4805b7d2ee
commit 078441204d

View File

@ -16,22 +16,9 @@ use Flarum\Tags\Query\TagFilterGambit;
class PinStickiedDiscussionsToTop
{
/**
* Used to get the default sort.
*
* @var ListDiscussionsController
*/
protected $listDiscussionsController;
public function __construct(ListDiscussionsController $listDiscussionsController)
{
$this->listDiscussionsController = $listDiscussionsController;
}
public function __invoke(FilterState $filterState, QueryCriteria $criteria)
{
// TODO: This should take modifications by extensions into account.
if ($criteria->sort == $this->listDiscussionsController->sort) {
if ($criteria->sortIsDefault) {
$query = $filterState->getQuery();
// If we are viewing a specific tag, then pin all stickied