Hi! I want to sort comments by created_at
field. As I can see, currently Flarum do this by number
field. The code is here:
flarum/flarum-coreblob/c09efebdcfb4cdc396bee0efafa0a81946fc813f/src/Api/Controller/ShowDiscussionController.php#L187
private function loadPosts($discussion, $actor, $offset, $limit, array $include, ServerRequestInterface $request)
{
$query = $discussion->posts()->whereVisibleTo($actor);
$query->orderBy('number')->skip($offset)->take($limit);
$posts = $query->get();
foreach ($posts as $post) {
$post->discussion = $discussion;
}
$this->loadRelations($posts, $include, $request);
return $posts->all();
}
These lines
$query->orderBy('number')->skip($offset)->take($limit);
$posts = $query->get();
probably means that the sort is hardcoded.
In my extend.php
I tried to write:
(new Extend\ApiController(ShowDiscussionController::class))->setSort(['created_at', 'asc']),
But this doesn't seem to work.
Is there more simple approach than resort number
according to a comment created_at
date?
If there is a way to apply custom sort to discussions, I'd like to know it too.