1
0
mirror of https://github.com/flarum/core.git synced 2025-08-09 09:57:06 +02:00

Don't allow re-liking or re-unliking

This commit is contained in:
Toby Zerner
2015-08-05 16:08:28 +09:30
parent d27f0403d8
commit 4a9f8e0f23

View File

@@ -29,11 +29,13 @@ class PersistData
throw new PermissionDeniedException; throw new PermissionDeniedException;
} }
if ($liked) { $currentlyLiked = $post->likes()->where('user_id', $actor->id)->exists();
if ($liked && ! $currentlyLiked) {
$post->likes()->attach($actor->id); $post->likes()->attach($actor->id);
$post->raise(new PostWasLiked($post, $actor)); $post->raise(new PostWasLiked($post, $actor));
} else { } elseif ($currentlyLiked) {
$post->likes()->detach($actor->id); $post->likes()->detach($actor->id);
$post->raise(new PostWasUnliked($post, $actor)); $post->raise(new PostWasUnliked($post, $actor));