mirror of
https://github.com/flarum/core.git
synced 2025-10-11 23:14:29 +02:00
merges 5.5 and master into next-back
This commit is contained in:
@@ -93,6 +93,18 @@ class ListDiscussionsController extends AbstractListController
|
||||
$results->areMoreResults() ? null : 0
|
||||
);
|
||||
|
||||
return $results->getResults();
|
||||
$results = $results->getResults();
|
||||
|
||||
if ($relations = array_intersect($load, ['startPost', 'lastPost'])) {
|
||||
foreach ($results as $discussion) {
|
||||
foreach ($relations as $relation) {
|
||||
if ($discussion->$relation) {
|
||||
$discussion->$relation->discussion = $discussion;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
}
|
||||
|
@@ -14,6 +14,7 @@ namespace Flarum\Api\Controller;
|
||||
use Flarum\Discussion\Discussion;
|
||||
use Flarum\Notification\NotificationRepository;
|
||||
use Flarum\User\Exception\PermissionDeniedException;
|
||||
use Flarum\Api\UrlGenerator;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Tobscure\JsonApi\Document;
|
||||
|
||||
@@ -39,16 +40,23 @@ class ListNotificationsController extends AbstractListController
|
||||
public $limit = 10;
|
||||
|
||||
/**
|
||||
* @var \Flarum\Notification\NotificationRepository
|
||||
* @var NotificationRepository
|
||||
*/
|
||||
protected $notifications;
|
||||
|
||||
/**
|
||||
* @param \Flarum\Notification\NotificationRepository $notifications
|
||||
* @var UrlGenerator
|
||||
*/
|
||||
public function __construct(NotificationRepository $notifications)
|
||||
protected $url;
|
||||
|
||||
/**
|
||||
* @param NotificationRepository $notifications
|
||||
* @param UrlGenerator $url
|
||||
*/
|
||||
public function __construct(NotificationRepository $notifications, UrlGenerator $url)
|
||||
{
|
||||
$this->notifications = $notifications;
|
||||
$this->url = $url;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -68,10 +76,33 @@ class ListNotificationsController extends AbstractListController
|
||||
$offset = $this->extractOffset($request);
|
||||
$include = $this->extractInclude($request);
|
||||
|
||||
$notifications = $this->notifications->findByUser($actor, $limit, $offset)
|
||||
if (! in_array('subject', $include)) {
|
||||
$include[] = 'subject';
|
||||
}
|
||||
|
||||
$notifications = $this->notifications->findByUser($actor, $limit + 1, $offset)
|
||||
->load(array_diff($include, ['subject.discussion']))
|
||||
->all();
|
||||
|
||||
$areMoreResults = false;
|
||||
|
||||
if (count($notifications) > $limit) {
|
||||
array_pop($notifications);
|
||||
$areMoreResults = true;
|
||||
}
|
||||
|
||||
$document->addPaginationLinks(
|
||||
$this->url->toRoute('notifications.index'),
|
||||
$request->getQueryParams(),
|
||||
$offset,
|
||||
$limit,
|
||||
$areMoreResults ? null : 0
|
||||
);
|
||||
|
||||
$notifications = array_filter($notifications, function ($notification) {
|
||||
return ! $notification->subjectModel || $notification->subject;
|
||||
});
|
||||
|
||||
if (in_array('subject.discussion', $include)) {
|
||||
$this->loadSubjectDiscussions($notifications);
|
||||
}
|
||||
|
@@ -173,6 +173,12 @@ class ShowDiscussionController extends AbstractShowController
|
||||
|
||||
$query->orderBy('time')->skip($offset)->take($limit)->with($include);
|
||||
|
||||
return $query->get()->all();
|
||||
$posts = $query->get()->all();
|
||||
|
||||
foreach ($posts as $post) {
|
||||
$post->discussion = $discussion;
|
||||
}
|
||||
|
||||
return $posts;
|
||||
}
|
||||
}
|
||||
|
@@ -80,7 +80,7 @@ class UploadFaviconController extends ShowForumController
|
||||
$mount->delete($file);
|
||||
}
|
||||
|
||||
$uploadName = 'favicon-'.Str::lower(Str::quickRandom(8)).'.'.$extension;
|
||||
$uploadName = 'favicon-'.Str::lower(Str::random(8)).'.'.$extension;
|
||||
|
||||
$mount->move('source://'.pathinfo($tmpFile, PATHINFO_BASENAME), "target://$uploadName");
|
||||
|
||||
|
@@ -73,7 +73,7 @@ class UploadLogoController extends ShowForumController
|
||||
$mount->delete($file);
|
||||
}
|
||||
|
||||
$uploadName = 'logo-'.Str::lower(Str::quickRandom(8)).'.png';
|
||||
$uploadName = 'logo-'.Str::lower(Str::random(8)).'.png';
|
||||
|
||||
$mount->move('source://'.pathinfo($tmpFile, PATHINFO_BASENAME), "target://$uploadName");
|
||||
|
||||
|
Reference in New Issue
Block a user