mirror of
https://github.com/flarum/core.git
synced 2025-10-15 08:55:53 +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");
|
||||
|
||||
|
@@ -88,4 +88,12 @@ class BasicDiscussionSerializer extends AbstractSerializer
|
||||
{
|
||||
return $this->hasMany($discussion, 'Flarum\Api\Serializer\BasicPostSerializer');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Tobscure\JsonApi\Relationship
|
||||
*/
|
||||
protected function hideUser($discussion)
|
||||
{
|
||||
return $this->hasOne($discussion, 'Flarum\Api\Serializer\UserBasicSerializer');
|
||||
}
|
||||
}
|
||||
|
@@ -36,8 +36,9 @@ class BasicUserSerializer extends AbstractSerializer
|
||||
}
|
||||
|
||||
return [
|
||||
'username' => $user->username,
|
||||
'avatarUrl' => $user->avatar_url
|
||||
'username' => $user->username,
|
||||
'displayName' => $user->display_name,
|
||||
'avatarUrl' => $user->avatar_url
|
||||
];
|
||||
}
|
||||
|
||||
|
@@ -64,12 +64,4 @@ class DiscussionSerializer extends BasicDiscussionSerializer
|
||||
|
||||
return $attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Tobscure\JsonApi\Relationship
|
||||
*/
|
||||
protected function hideUser($discussion)
|
||||
{
|
||||
return $this->hasOne($discussion, 'Flarum\Api\Serializer\UserSerializer');
|
||||
}
|
||||
}
|
||||
|
@@ -85,7 +85,7 @@ class PostSerializer extends BasicPostSerializer
|
||||
*/
|
||||
protected function discussion($post)
|
||||
{
|
||||
return $this->hasOne($post, 'Flarum\Api\Serializer\DiscussionSerializer');
|
||||
return $this->hasOne($post, 'Flarum\Api\Serializer\DiscussionBasicSerializer');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,7 +93,7 @@ class PostSerializer extends BasicPostSerializer
|
||||
*/
|
||||
protected function editUser($post)
|
||||
{
|
||||
return $this->hasOne($post, 'Flarum\Api\Serializer\UserSerializer');
|
||||
return $this->hasOne($post, 'Flarum\Api\Serializer\UserBasicSerializer');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,6 +101,6 @@ class PostSerializer extends BasicPostSerializer
|
||||
*/
|
||||
protected function hideUser($post)
|
||||
{
|
||||
return $this->hasOne($post, 'Flarum\Api\Serializer\UserSerializer');
|
||||
return $this->hasOne($post, 'Flarum\Api\Serializer\UserBasicSerializer');
|
||||
}
|
||||
}
|
||||
|
@@ -40,7 +40,6 @@ class UserSerializer extends BasicUserSerializer
|
||||
$canEdit = $gate->allows('edit', $user);
|
||||
|
||||
$attributes += [
|
||||
'bio' => $user->bio,
|
||||
'joinTime' => $this->formatDate($user->join_time),
|
||||
'discussionsCount' => (int) $user->discussions_count,
|
||||
'commentsCount' => (int) $user->comments_count,
|
||||
|
Reference in New Issue
Block a user