diff --git a/app/Console/Commands/StatusDedupe.php b/app/Console/Commands/StatusDedupe.php new file mode 100644 index 000000000..c7c9b811c --- /dev/null +++ b/app/Console/Commands/StatusDedupe.php @@ -0,0 +1,62 @@ +selectRaw('id, uri, count(uri) as occurences') + ->whereNotNull('uri') + ->groupBy('uri') + ->orderBy('created_at') + ->having('occurences', '>', 1) + ->chunk(50, function($statuses) { + foreach($statuses as $status) { + $this->info("Found duplicate: $status->uri"); + Status::whereUri($status->uri) + ->where('id', '!=', $status->id) + ->get() + ->map(function($status) { + $this->info("Deleting Duplicate ID: $status->id"); + StatusDelete::dispatch($status); + }); + } + }); + } +} diff --git a/app/Http/Controllers/FollowerController.php b/app/Http/Controllers/FollowerController.php index 42967e42e..d37809cfb 100644 --- a/app/Http/Controllers/FollowerController.php +++ b/app/Http/Controllers/FollowerController.php @@ -83,14 +83,18 @@ class FollowerController extends Controller $follower->profile_id = $user->id; $follower->following_id = $target->id; $follower->save(); - + if($remote == true && config('federation.activitypub.remoteFollow') == true) { $this->sendFollow($user, $target); } FollowPipeline::dispatch($follower); } else { - $follower = Follower::whereProfileId($user->id)->whereFollowingId($target->id)->firstOrFail(); - if($remote == true) { + $request = FollowRequest::whereFollowerId($user->id)->whereFollowingId($target->id)->exists(); + $follower = Follower::whereProfileId($user->id)->whereFollowingId($target->id)->exists(); + if($remote == true && $request && !$follower) { + $this->sendFollow($user, $target); + } + if($remote == true && $follower) { $this->sendUndoFollow($user, $target); } $follower->delete(); diff --git a/app/Util/ActivityPub/Helpers.php b/app/Util/ActivityPub/Helpers.php index eaa526b74..ce8cb4ae3 100644 --- a/app/Util/ActivityPub/Helpers.php +++ b/app/Util/ActivityPub/Helpers.php @@ -220,7 +220,7 @@ class Helpers { $id = (int) last(explode('/', $url)); return Status::findOrFail($id); } else { - $cached = Status::whereUrl($url)->first(); + $cached = Status::whereUri($url)->orWhere('url', $url)->first(); if($cached) { return $cached; }