diff --git a/app/Console/Commands/CatchUnoptimizedMedia.php b/app/Console/Commands/CatchUnoptimizedMedia.php index 22ae56be1..1072c45d6 100644 --- a/app/Console/Commands/CatchUnoptimizedMedia.php +++ b/app/Console/Commands/CatchUnoptimizedMedia.php @@ -2,6 +2,7 @@ namespace App\Console\Commands; +use DB; use App\Jobs\ImageOptimizePipeline\ImageOptimize; use App\Media; use Illuminate\Console\Command; @@ -39,9 +40,19 @@ class CatchUnoptimizedMedia extends Command */ public function handle() { - $medias = Media::whereNotNull('status_id')->whereNull('processed_at')->take(250)->get(); - foreach ($medias as $media) { - ImageOptimize::dispatch($media); - } + DB::transaction(function() { + Media::whereNull('processed_at') + ->whereNotNull('status_id') + ->whereNotNull('media_path') + ->whereIn('mime', [ + 'image/jpeg', + 'image/png', + ]) + ->chunk(50, function($medias) { + foreach ($medias as $media) { + ImageOptimize::dispatch($media); + } + }); + }); } } diff --git a/app/Util/ActivityPub/Helpers.php b/app/Util/ActivityPub/Helpers.php index e9ea90e91..e0fb72995 100644 --- a/app/Util/ActivityPub/Helpers.php +++ b/app/Util/ActivityPub/Helpers.php @@ -388,7 +388,10 @@ class Helpers { if($local == true) { $id = last(explode('/', $url)); - return Profile::whereUsername($id)->firstOrFail(); + return Profile::whereNull('status') + ->whereNull('domain') + ->whereUsername($id) + ->firstOrFail(); } $res = self::fetchProfileFromUrl($url); if(isset($res['id']) == false) { diff --git a/app/Util/ActivityPub/Inbox.php b/app/Util/ActivityPub/Inbox.php index 7c2f2332b..b64985bf6 100644 --- a/app/Util/ActivityPub/Inbox.php +++ b/app/Util/ActivityPub/Inbox.php @@ -15,6 +15,7 @@ use App\{ use Carbon\Carbon; use App\Util\ActivityPub\Helpers; use App\Jobs\LikePipeline\LikePipeline; +use App\Jobs\FollowPipeline\FollowPipeline; use App\Util\ActivityPub\Validator\{ Accept, @@ -243,28 +244,40 @@ class Inbox public function handleAcceptActivity() { + $actor = $this->payload['actor']; - $obj = $this->payload['object']; - switch ($obj['type']) { - case 'Follow': - $accept = [ - '@context' => 'https://www.w3.org/ns/activitystreams', - 'id' => $target->permalink().'#accepts/follows/' . $follower->id, - 'type' => 'Accept', - 'actor' => $target->permalink(), - 'object' => [ - 'id' => $actor->permalink('#follows/'.$target->id), - 'type' => 'Follow', - 'actor' => $actor->permalink(), - 'object' => $target->permalink() - ] - ]; - break; - - default: - # code... - break; + $obj = $this->payload['object']['object']; + $type = $this->payload['object']['type']; + + if($type !== 'Follow') { + return; } + + $actor = Helpers::validateUrl($actor); + $target = Helpers::validateLocalUrl($obj); + + if(!$actor || !$target) { + return; + } + $actor = Helpers::profileFetch($actor); + $target = Helpers::profileFetch($target); + + $request = FollowRequest::whereFollowerId($actor->id) + ->whereFollowingId($target->id) + ->whereIsRejected(false) + ->first(); + + if(!$request) { + return; + } + + $follower = new Follower(); + $follower->profile_id = $actor->id; + $follower->following_id = $target->id; + $follower->save(); + FollowPipeline::dispatch($follower); + + $request->delete(); } public function handleDeleteActivity() diff --git a/resources/views/collection/show.blade.php b/resources/views/collection/show.blade.php index 17b8fa63b..76e1fce1f 100644 --- a/resources/views/collection/show.blade.php +++ b/resources/views/collection/show.blade.php @@ -8,6 +8,17 @@

Collection

{{$collection->title}}

+ @auth + @if($collection->profile_id == Auth::user()->profile_id) +
+
+ @csrf + + +
+
+ @endif + @endauth