mirror of
https://github.com/flarum/framework.git
synced 2024-11-25 09:41:49 +08:00
parent
a7f53dbe63
commit
f17f789878
|
@ -9,8 +9,8 @@
|
|||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Flarum\Core\Group;
|
||||
use Flarum\Database\Migration;
|
||||
use Flarum\Group\Group;
|
||||
|
||||
return Migration::addPermissions([
|
||||
'discussion.likePosts' => Group::MEMBER_ID
|
||||
|
|
|
@ -11,8 +11,8 @@
|
|||
|
||||
namespace Flarum\Likes\Event;
|
||||
|
||||
use Flarum\Core\Post;
|
||||
use Flarum\Core\User;
|
||||
use Flarum\Post\Post;
|
||||
use Flarum\User\User;
|
||||
|
||||
class PostWasLiked
|
||||
{
|
||||
|
|
|
@ -11,8 +11,8 @@
|
|||
|
||||
namespace Flarum\Likes\Event;
|
||||
|
||||
use Flarum\Core\Post;
|
||||
use Flarum\Core\User;
|
||||
use Flarum\Post\Post;
|
||||
use Flarum\User\User;
|
||||
|
||||
class PostWasUnliked
|
||||
{
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
namespace Flarum\Likes\Listener;
|
||||
|
||||
use Flarum\Event\ConfigureWebApp;
|
||||
use Flarum\Event\Rendering;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
|
||||
class AddClientAssets
|
||||
|
@ -21,13 +21,13 @@ class AddClientAssets
|
|||
*/
|
||||
public function subscribe(Dispatcher $events)
|
||||
{
|
||||
$events->listen(ConfigureWebApp::class, [$this, 'addAssets']);
|
||||
$events->listen(Rendering::class, [$this, 'addAssets']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ConfigureClientView $event
|
||||
*/
|
||||
public function addAssets(ConfigureWebApp $event)
|
||||
public function addAssets(Rendering $event)
|
||||
{
|
||||
if ($event->isForum()) {
|
||||
$event->addAssets([
|
||||
|
|
|
@ -12,14 +12,14 @@
|
|||
namespace Flarum\Likes\Listener;
|
||||
|
||||
use Flarum\Api\Controller;
|
||||
use Flarum\Api\Serializer\BasicUserSerializer;
|
||||
use Flarum\Api\Serializer\PostSerializer;
|
||||
use Flarum\Api\Serializer\UserBasicSerializer;
|
||||
use Flarum\Core\Post;
|
||||
use Flarum\Core\User;
|
||||
use Flarum\Event\ConfigureApiController;
|
||||
use Flarum\Event\GetApiRelationship;
|
||||
use Flarum\Event\GetModelRelationship;
|
||||
use Flarum\Event\PrepareApiAttributes;
|
||||
use Flarum\Event\Serializing;
|
||||
use Flarum\Event\WillGetData;
|
||||
use Flarum\Post\Post;
|
||||
use Flarum\User\User;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
|
||||
class AddPostLikesRelationship
|
||||
|
@ -31,8 +31,8 @@ class AddPostLikesRelationship
|
|||
{
|
||||
$events->listen(GetModelRelationship::class, [$this, 'getModelRelationship']);
|
||||
$events->listen(GetApiRelationship::class, [$this, 'getApiAttributes']);
|
||||
$events->listen(PrepareApiAttributes::class, [$this, 'prepareApiAttributes']);
|
||||
$events->listen(ConfigureApiController::class, [$this, 'includeLikes']);
|
||||
$events->listen(Serializing::class, [$this, 'prepareApiAttributes']);
|
||||
$events->listen(WillGetData::class, [$this, 'includeLikes']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -53,14 +53,14 @@ class AddPostLikesRelationship
|
|||
public function getApiAttributes(GetApiRelationship $event)
|
||||
{
|
||||
if ($event->isRelationship(PostSerializer::class, 'likes')) {
|
||||
return $event->serializer->hasMany($event->model, UserBasicSerializer::class, 'likes');
|
||||
return $event->serializer->hasMany($event->model, BasicUserSerializer::class, 'likes');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PrepareApiAttributes $event
|
||||
* @param Serializing $event
|
||||
*/
|
||||
public function prepareApiAttributes(PrepareApiAttributes $event)
|
||||
public function prepareApiAttributes(Serializing $event)
|
||||
{
|
||||
if ($event->isSerializer(PostSerializer::class)) {
|
||||
$event->attributes['canLike'] = (bool) $event->actor->can('like', $event->model);
|
||||
|
@ -68,9 +68,9 @@ class AddPostLikesRelationship
|
|||
}
|
||||
|
||||
/**
|
||||
* @param ConfigureApiController $event
|
||||
* @param WillGetData $event
|
||||
*/
|
||||
public function includeLikes(ConfigureApiController $event)
|
||||
public function includeLikes(WillGetData $event)
|
||||
{
|
||||
if ($event->isController(Controller\ShowDiscussionController::class)) {
|
||||
$event->addInclude('posts.likes');
|
||||
|
|
|
@ -11,11 +11,11 @@
|
|||
|
||||
namespace Flarum\Likes\Listener;
|
||||
|
||||
use Flarum\Core\Access\AssertPermissionTrait;
|
||||
use Flarum\Event\PostWasDeleted;
|
||||
use Flarum\Event\PostWillBeSaved;
|
||||
use Flarum\Event\Deleted;
|
||||
use Flarum\Event\Saving;
|
||||
use Flarum\Likes\Event\PostWasLiked;
|
||||
use Flarum\Likes\Event\PostWasUnliked;
|
||||
use Flarum\User\AssertPermissionTrait;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
|
||||
class SaveLikesToDatabase
|
||||
|
@ -27,14 +27,14 @@ class SaveLikesToDatabase
|
|||
*/
|
||||
public function subscribe(Dispatcher $events)
|
||||
{
|
||||
$events->listen(PostWillBeSaved::class, [$this, 'whenPostWillBeSaved']);
|
||||
$events->listen(PostWasDeleted::class, [$this, 'whenPostWasDeleted']);
|
||||
$events->listen(Saving::class, [$this, 'whenPostIsSaving']);
|
||||
$events->listen(Deleted::class, [$this, 'whenPostIsDeleted']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PostWillBeSaved $event
|
||||
* @param Saving $event
|
||||
*/
|
||||
public function whenPostWillBeSaved(PostWillBeSaved $event)
|
||||
public function whenPostIsSaving(Saving $event)
|
||||
{
|
||||
$post = $event->post;
|
||||
$data = $event->data;
|
||||
|
@ -60,9 +60,9 @@ class SaveLikesToDatabase
|
|||
}
|
||||
|
||||
/**
|
||||
* @param PostWasDeleted $event
|
||||
* @param Deleted $event
|
||||
*/
|
||||
public function whenPostWasDeleted(PostWasDeleted $event)
|
||||
public function whenPostIsDeleted(Deleted $event)
|
||||
{
|
||||
$event->post->likes()->detach();
|
||||
}
|
||||
|
|
|
@ -11,14 +11,14 @@
|
|||
|
||||
namespace Flarum\Likes\Listener;
|
||||
|
||||
use Flarum\Api\Serializer\PostBasicSerializer;
|
||||
use Flarum\Core\Notification\NotificationSyncer;
|
||||
use Flarum\Core\Post;
|
||||
use Flarum\Core\User;
|
||||
use Flarum\Api\Serializer\BasicPostSerializer;
|
||||
use Flarum\Event\ConfigureNotificationTypes;
|
||||
use Flarum\Likes\Event\PostWasLiked;
|
||||
use Flarum\Likes\Event\PostWasUnliked;
|
||||
use Flarum\Likes\Notification\PostLikedBlueprint;
|
||||
use Flarum\Notification\NotificationSyncer;
|
||||
use Flarum\Post\Post;
|
||||
use Flarum\User\User;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
|
||||
class SendNotificationWhenPostIsLiked
|
||||
|
@ -51,7 +51,7 @@ class SendNotificationWhenPostIsLiked
|
|||
*/
|
||||
public function registerNotificationType(ConfigureNotificationTypes $event)
|
||||
{
|
||||
$event->add(PostLikedBlueprint::class, PostBasicSerializer::class, ['alert']);
|
||||
$event->add(PostLikedBlueprint::class, BasicPostSerializer::class, ['alert']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -11,9 +11,9 @@
|
|||
|
||||
namespace Flarum\Likes\Notification;
|
||||
|
||||
use Flarum\Core\Notification\BlueprintInterface;
|
||||
use Flarum\Core\Post;
|
||||
use Flarum\Core\User;
|
||||
use Flarum\Notification\Blueprint\BlueprintInterface;
|
||||
use Flarum\Post\Post;
|
||||
use Flarum\User\User;
|
||||
|
||||
class PostLikedBlueprint implements BlueprintInterface
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user