diff --git a/app/Http/Controllers/CommentController.php b/app/Http/Controllers/CommentController.php index 20685da00..7248b0a59 100644 --- a/app/Http/Controllers/CommentController.php +++ b/app/Http/Controllers/CommentController.php @@ -13,6 +13,7 @@ use App\Jobs\StatusPipeline\NewStatusPipeline; use App\Util\Lexer\Autolink; use App\Profile; use App\Status; +use App\UserFilter; use League\Fractal; use App\Transformer\Api\StatusTransformer; use League\Fractal\Serializer\ArraySerializer; @@ -57,6 +58,16 @@ class CommentController extends Controller return; } + $filtered = UserFilter::whereUserId($status->profile_id) + ->whereFilterableType('App\Profile') + ->whereIn('filter_type', ['mute', 'block']) + ->whereFilterableId($profile->id) + ->exists(); + + if($filtered == true) { + return; + } + $reply = DB::transaction(function() use($comment, $status, $profile) { $autolink = Autolink::create()->autolink($comment); $reply = new Status(); diff --git a/app/Http/Controllers/PublicApiController.php b/app/Http/Controllers/PublicApiController.php index bd22505e3..7d4e5c639 100644 --- a/app/Http/Controllers/PublicApiController.php +++ b/app/Http/Controllers/PublicApiController.php @@ -113,10 +113,22 @@ class PublicApiController extends Controller $profile = Profile::whereUsername($username)->whereNull('status')->firstOrFail(); $status = Status::whereProfileId($profile->id)->whereCommentsDisabled(false)->findOrFail($postId); $this->scopeCheck($profile, $status); + + if(Auth::check()) { + $pid = Auth::user()->profile->id; + $filtered = UserFilter::whereUserId($pid) + ->whereFilterableType('App\Profile') + ->whereIn('filter_type', ['mute', 'block']) + ->pluck('filterable_id')->toArray(); + } else { + $filtered = []; + } + if($request->filled('min_id') || $request->filled('max_id')) { if($request->filled('min_id')) { $replies = $status->comments() ->whereNull('reblog_of_id') + ->whereNotIn('profile_id', $filtered) ->select('id', 'caption', 'is_nsfw', 'rendered', 'profile_id', 'in_reply_to_id', 'type', 'reply_count', 'created_at') ->where('id', '>=', $request->min_id) ->orderBy('id', 'desc') @@ -125,6 +137,7 @@ class PublicApiController extends Controller if($request->filled('max_id')) { $replies = $status->comments() ->whereNull('reblog_of_id') + ->whereNotIn('profile_id', $filtered) ->select('id', 'caption', 'is_nsfw', 'rendered', 'profile_id', 'in_reply_to_id', 'type', 'reply_count', 'created_at') ->where('id', '<=', $request->max_id) ->orderBy('id', 'desc') @@ -133,6 +146,7 @@ class PublicApiController extends Controller } else { $replies = $status->comments() ->whereNull('reblog_of_id') + ->whereNotIn('profile_id', $filtered) ->select('id', 'caption', 'is_nsfw', 'rendered', 'profile_id', 'in_reply_to_id', 'type', 'reply_count', 'created_at') ->orderBy('id', 'desc') ->paginate($limit); diff --git a/app/Jobs/CommentPipeline/CommentPipeline.php b/app/Jobs/CommentPipeline/CommentPipeline.php index db0951181..b028bdae7 100644 --- a/app/Jobs/CommentPipeline/CommentPipeline.php +++ b/app/Jobs/CommentPipeline/CommentPipeline.php @@ -4,7 +4,8 @@ namespace App\Jobs\CommentPipeline; use App\{ Notification, - Status + Status, + UserFilter }; use App\Services\NotificationService; use DB, Cache, Log, Redis; @@ -56,6 +57,15 @@ class CommentPipeline implements ShouldQueue if ($actor->id === $target->id || $status->comments_disabled == true) { return true; } + $filtered = UserFilter::whereUserId($target->id) + ->whereFilterableType('App\Profile') + ->whereIn('filter_type', ['mute', 'block']) + ->whereFilterableId($actor->id) + ->exists(); + + if($filtered == true) { + return; + } DB::transaction(function() use($target, $actor, $comment) { $notification = new Notification(); diff --git a/public/js/profile.js b/public/js/profile.js index a22d3d1ad..33f11d26c 100644 Binary files a/public/js/profile.js and b/public/js/profile.js differ diff --git a/public/js/status.js b/public/js/status.js index 820b837a7..594814bb6 100644 Binary files a/public/js/status.js and b/public/js/status.js differ diff --git a/public/js/timeline.js b/public/js/timeline.js index a74bf4288..13c1c2958 100644 Binary files a/public/js/timeline.js and b/public/js/timeline.js differ diff --git a/public/mix-manifest.json b/public/mix-manifest.json index 7f3f6bb3e..c2be5258c 100644 Binary files a/public/mix-manifest.json and b/public/mix-manifest.json differ diff --git a/resources/assets/js/components/PostMenu.vue b/resources/assets/js/components/PostMenu.vue index b219978ad..20a7472a9 100644 --- a/resources/assets/js/components/PostMenu.vue +++ b/resources/assets/js/components/PostMenu.vue @@ -12,8 +12,8 @@ Report - Mute Profile - Block Profile + Mute Profile + Block Profile @@ -187,6 +187,36 @@ }); break; } + }, + + muteProfile(status) { + if($('body').hasClass('loggedIn') == false) { + return; + } + + axios.post('/i/mute', { + type: 'user', + item: status.account.id + }).then(res => { + swal('Success', 'You have successfully muted ' + status.account.acct, 'success'); + }).catch(err => { + swal('Error', 'Something went wrong. Please try again later.', 'error'); + }); + }, + + blockProfile(status) { + if($('body').hasClass('loggedIn') == false) { + return; + } + + axios.post('/i/block', { + type: 'user', + item: status.account.id + }).then(res => { + swal('Success', 'You have successfully blocked ' + status.account.acct, 'success'); + }).catch(err => { + swal('Error', 'Something went wrong. Please try again later.', 'error'); + }); } } }