mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-12-21 23:32:39 +00:00
Improve follow request flow, federate rejections and delete rejections from database to properly handle future follow requests from same actor
This commit is contained in:
parent
aded149fae
commit
4470981af7
4 changed files with 102 additions and 4 deletions
|
@ -32,9 +32,9 @@ class FollowRequest extends Model
|
|||
return $this->belongsTo(Profile::class, 'following_id', 'id');
|
||||
}
|
||||
|
||||
public function permalink($append = null)
|
||||
public function permalink($append = null, $namespace = '#accepts')
|
||||
{
|
||||
$path = $this->target->permalink("#accepts/follows/{$this->id}{$append}");
|
||||
$path = $this->target->permalink("{$namespace}/follows/{$this->id}{$append}");
|
||||
return url($path);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ use App\Services\AccountService;
|
|||
use App\Services\UserFilterService;
|
||||
use App\Services\RelationshipService;
|
||||
use App\Jobs\FollowPipeline\FollowAcceptPipeline;
|
||||
use App\Jobs\FollowPipeline\FollowRejectPipeline;
|
||||
|
||||
class AccountController extends Controller
|
||||
{
|
||||
|
@ -406,8 +407,11 @@ class AccountController extends Controller
|
|||
break;
|
||||
|
||||
case 'reject':
|
||||
$followRequest->is_rejected = true;
|
||||
$followRequest->save();
|
||||
if($follower->domain != null && $follower->private_key === null) {
|
||||
FollowRejectPipeline::dispatch($followRequest);
|
||||
} else {
|
||||
$followRequest->delete();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
69
app/Jobs/FollowPipeline/FollowRejectPipeline.php
Normal file
69
app/Jobs/FollowPipeline/FollowRejectPipeline.php
Normal file
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
namespace App\Jobs\FollowPipeline;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
use Cache, Log;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
use League\Fractal;
|
||||
use League\Fractal\Serializer\ArraySerializer;
|
||||
use App\FollowRequest;
|
||||
use App\Util\ActivityPub\Helpers;
|
||||
use App\Transformer\ActivityPub\Verb\RejectFollow;
|
||||
|
||||
class FollowRejectPipeline implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $followRequest;
|
||||
|
||||
/**
|
||||
* Delete the job if its models no longer exist.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $deleteWhenMissingModels = true;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(FollowRequest $followRequest)
|
||||
{
|
||||
$this->followRequest = $followRequest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$follow = $this->followRequest;
|
||||
$actor = $follow->actor;
|
||||
$target = $follow->target;
|
||||
|
||||
if($actor->domain == null || $actor->inbox_url == null || !$target->private_key) {
|
||||
return;
|
||||
}
|
||||
|
||||
$fractal = new Fractal\Manager();
|
||||
$fractal->setSerializer(new ArraySerializer());
|
||||
$resource = new Fractal\Resource\Item($follow, new RejectFollow());
|
||||
$activity = $fractal->createData($resource)->toArray();
|
||||
$url = $actor->sharedInbox ?? $actor->inbox_url;
|
||||
|
||||
Helpers::sendSignedObject($target, $url, $activity);
|
||||
|
||||
$follow->delete();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
25
app/Transformer/ActivityPub/Verb/RejectFollow.php
Normal file
25
app/Transformer/ActivityPub/Verb/RejectFollow.php
Normal file
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace App\Transformer\ActivityPub\Verb;
|
||||
|
||||
use App\FollowRequest;
|
||||
use League\Fractal;
|
||||
|
||||
class RejectFollow extends Fractal\TransformerAbstract
|
||||
{
|
||||
public function transform(FollowRequest $follow)
|
||||
{
|
||||
return [
|
||||
'@context' => 'https://www.w3.org/ns/activitystreams',
|
||||
'type' => 'Reject',
|
||||
'id' => $follow->permalink(null, '#rejects'),
|
||||
'actor' => $follow->target->permalink(),
|
||||
'object' => [
|
||||
'type' => 'Follow',
|
||||
'id' => $follow->activity && isset($follow->activity['id']) ? $follow->activity['id'] : null,
|
||||
'actor' => $follow->actor->permalink(),
|
||||
'object' => $follow->target->permalink()
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue