Update AccountController, dispatch Accept Follow activity if applicable

pull/3532/head
Daniel Supernault 2022-06-03 04:18:06 -06:00
rodzic 85fb46668c
commit 4dc9365acb
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 0DEF1C662C9033F7
4 zmienionych plików z 83 dodań i 8 usunięć

Wyświetl plik

@ -11,6 +11,11 @@ class FollowRequest extends Model
protected $casts = [
'activity' => 'array',
];
public function actor()
{
return $this->belongsTo(Profile::class, 'follower_id', 'id');
}
public function follower()
{
@ -22,11 +27,6 @@ class FollowRequest extends Model
return $this->belongsTo(Profile::class, 'following_id', 'id');
}
public function actor()
{
return $this->belongsTo(Profile::class, 'follower_id', 'id');
}
public function target()
{
return $this->belongsTo(Profile::class, 'following_id', 'id');

Wyświetl plik

@ -29,6 +29,7 @@ use App\Transformer\Api\Mastodon\v1\AccountTransformer;
use App\Services\AccountService;
use App\Services\UserFilterService;
use App\Services\RelationshipService;
use App\Jobs\FollowPipeline\FollowAcceptPipeline;
class AccountController extends Controller
{
@ -394,8 +395,13 @@ class AccountController extends Controller
$follow->profile_id = $follower->id;
$follow->following_id = $pid;
$follow->save();
FollowPipeline::dispatch($follow);
$followRequest->delete();
if($follower->domain != null && $follower->private_key === null) {
FollowAcceptPipeline::dispatch($followRequest);
} else {
FollowPipeline::dispatch($follow);
$followRequest->delete();
}
break;
case 'reject':

Wyświetl plik

@ -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\AcceptFollow;
class FollowAcceptPipeline 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 AcceptFollow());
$activity = $fractal->createData($resource)->toArray();
$url = $actor->sharedInbox ?? $actor->inbox_url;
Helpers::sendSignedObject($target, $url, $activity);
$follow->delete();
return;
}
}

Wyświetl plik

@ -16,7 +16,7 @@ class AcceptFollow extends Fractal\TransformerAbstract
'actor' => $follow->target->permalink(),
'object' => [
'type' => 'Follow',
'id' => $follow->activity ? $follow->activity['id'] : null,
'id' => $follow->activity && isset($follow->activity['id']) ? $follow->activity['id'] : null,
'actor' => $follow->actor->permalink(),
'object' => $follow->target->permalink()
]