2018-06-01 21:04:33 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Jobs\StatusPipeline;
|
|
|
|
|
2021-01-18 04:51:25 +00:00
|
|
|
use DB, Storage;
|
2018-11-04 03:24:50 +00:00
|
|
|
use App\{
|
2021-05-12 00:17:03 +00:00
|
|
|
AccountInterstitial,
|
2022-10-07 09:15:34 +00:00
|
|
|
Bookmark,
|
2022-06-19 05:47:16 +00:00
|
|
|
CollectionItem,
|
2022-10-07 09:15:34 +00:00
|
|
|
DirectMessage,
|
|
|
|
Like,
|
|
|
|
Media,
|
2021-05-12 00:17:03 +00:00
|
|
|
MediaTag,
|
2022-10-07 09:15:34 +00:00
|
|
|
Mention,
|
2021-05-12 00:17:03 +00:00
|
|
|
Notification,
|
|
|
|
Report,
|
|
|
|
Status,
|
2022-10-07 09:15:34 +00:00
|
|
|
StatusArchived,
|
2021-05-12 00:17:03 +00:00
|
|
|
StatusHashtag,
|
2022-10-07 09:15:34 +00:00
|
|
|
StatusView
|
2018-11-04 03:24:50 +00:00
|
|
|
};
|
2018-06-01 21:04:33 +00:00
|
|
|
use Illuminate\Bus\Queueable;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
2018-08-28 03:07:36 +00:00
|
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
2019-03-06 01:06:23 +00:00
|
|
|
use League\Fractal;
|
2021-01-18 04:51:25 +00:00
|
|
|
use Illuminate\Support\Str;
|
2019-03-06 01:06:23 +00:00
|
|
|
use League\Fractal\Serializer\ArraySerializer;
|
|
|
|
use App\Transformer\ActivityPub\Verb\DeleteNote;
|
|
|
|
use App\Util\ActivityPub\Helpers;
|
2019-03-08 06:49:19 +00:00
|
|
|
use GuzzleHttp\Pool;
|
|
|
|
use GuzzleHttp\Client;
|
|
|
|
use GuzzleHttp\Promise;
|
|
|
|
use App\Util\ActivityPub\HttpSignature;
|
2022-06-19 05:47:16 +00:00
|
|
|
use App\Services\CollectionService;
|
2021-01-30 23:37:29 +00:00
|
|
|
use App\Services\StatusService;
|
2022-10-07 09:15:34 +00:00
|
|
|
use App\Jobs\MediaPipeline\MediaDeletePipeline;
|
2018-06-01 21:04:33 +00:00
|
|
|
|
|
|
|
class StatusDelete implements ShouldQueue
|
|
|
|
{
|
2021-05-12 00:17:03 +00:00
|
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
|
|
|
|
protected $status;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete the job if its models no longer exist.
|
|
|
|
*
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
public $deleteWhenMissingModels = true;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new job instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct(Status $status)
|
|
|
|
{
|
|
|
|
$this->status = $status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the job.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
|
|
|
$status = $this->status;
|
|
|
|
$profile = $this->status->profile;
|
|
|
|
|
2022-01-18 00:11:16 +00:00
|
|
|
StatusService::del($status->id, true);
|
2021-05-12 00:17:03 +00:00
|
|
|
|
2022-01-18 00:11:16 +00:00
|
|
|
if(in_array($status->type, ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])) {
|
|
|
|
$profile->status_count = $profile->status_count - 1;
|
|
|
|
$profile->save();
|
|
|
|
}
|
2021-05-12 00:17:03 +00:00
|
|
|
|
|
|
|
if(config_cache('federation.activitypub.enabled') == true) {
|
2022-10-07 09:15:34 +00:00
|
|
|
return $this->fanoutDelete($status);
|
2021-05-12 00:17:03 +00:00
|
|
|
} else {
|
2022-10-07 09:15:34 +00:00
|
|
|
return $this->unlinkRemoveMedia($status);
|
2021-05-12 00:17:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function unlinkRemoveMedia($status)
|
|
|
|
{
|
2022-10-07 09:15:34 +00:00
|
|
|
Media::whereStatusId($status->id)
|
|
|
|
->get()
|
|
|
|
->each(function($media) {
|
2022-12-24 11:28:52 +00:00
|
|
|
MediaDeletePipeline::dispatch($media)->onQueue('mmo');
|
2022-10-07 09:15:34 +00:00
|
|
|
});
|
2021-05-12 00:17:03 +00:00
|
|
|
|
|
|
|
if($status->in_reply_to_id) {
|
2022-10-07 09:15:34 +00:00
|
|
|
$parent = Status::findOrFail($status->in_reply_to_id);
|
|
|
|
--$parent->reply_count;
|
|
|
|
$parent->save();
|
2021-05-12 00:17:03 +00:00
|
|
|
}
|
2022-06-19 05:47:16 +00:00
|
|
|
|
2022-10-07 09:15:34 +00:00
|
|
|
Bookmark::whereStatusId($status->id)->delete();
|
|
|
|
|
|
|
|
CollectionItem::whereObjectType('App\Status')
|
|
|
|
->whereObjectId($status->id)
|
|
|
|
->get()
|
|
|
|
->each(function($col) {
|
|
|
|
CollectionService::removeItem($col->collection_id, $col->object_id);
|
|
|
|
$col->delete();
|
2022-06-19 05:47:16 +00:00
|
|
|
});
|
|
|
|
|
2022-10-07 09:15:34 +00:00
|
|
|
DirectMessage::whereStatusId($status->id)->delete();
|
|
|
|
Like::whereStatusId($status->id)->delete();
|
|
|
|
|
|
|
|
MediaTag::where('status_id', $status->id)->delete();
|
|
|
|
Mention::whereStatusId($status->id)->forceDelete();
|
|
|
|
|
|
|
|
Notification::whereItemType('App\Status')
|
|
|
|
->whereItemId($status->id)
|
|
|
|
->forceDelete();
|
|
|
|
|
|
|
|
Report::whereObjectType('App\Status')
|
|
|
|
->whereObjectId($status->id)
|
|
|
|
->delete();
|
|
|
|
|
|
|
|
StatusArchived::whereStatusId($status->id)->delete();
|
|
|
|
StatusHashtag::whereStatusId($status->id)->delete();
|
|
|
|
StatusView::whereStatusId($status->id)->delete();
|
|
|
|
Status::whereInReplyToId($status->id)->update(['in_reply_to_id' => null]);
|
|
|
|
|
|
|
|
AccountInterstitial::where('item_type', 'App\Status')
|
|
|
|
->where('item_id', $status->id)
|
|
|
|
->delete();
|
|
|
|
|
|
|
|
$status->forceDelete();
|
|
|
|
|
|
|
|
return 1;
|
2021-05-12 00:17:03 +00:00
|
|
|
}
|
|
|
|
|
2022-10-07 09:15:34 +00:00
|
|
|
public function fanoutDelete($status)
|
2021-05-12 00:17:03 +00:00
|
|
|
{
|
|
|
|
$audience = $status->profile->getAudienceInbox();
|
|
|
|
$profile = $status->profile;
|
|
|
|
|
|
|
|
$fractal = new Fractal\Manager();
|
|
|
|
$fractal->setSerializer(new ArraySerializer());
|
|
|
|
$resource = new Fractal\Resource\Item($status, new DeleteNote());
|
|
|
|
$activity = $fractal->createData($resource)->toArray();
|
|
|
|
|
|
|
|
$this->unlinkRemoveMedia($status);
|
|
|
|
|
|
|
|
$payload = json_encode($activity);
|
|
|
|
|
|
|
|
$client = new Client([
|
|
|
|
'timeout' => config('federation.activitypub.delivery.timeout')
|
|
|
|
]);
|
|
|
|
|
|
|
|
$requests = function($audience) use ($client, $activity, $profile, $payload) {
|
|
|
|
foreach($audience as $url) {
|
2022-05-02 14:36:12 +00:00
|
|
|
$version = config('pixelfed.version');
|
|
|
|
$appUrl = config('app.url');
|
|
|
|
$headers = HttpSignature::sign($profile, $url, $activity, [
|
|
|
|
'Content-Type' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
|
|
|
|
'User-Agent' => "(Pixelfed/{$version}; +{$appUrl})",
|
|
|
|
]);
|
2021-05-12 00:17:03 +00:00
|
|
|
yield function() use ($client, $url, $headers, $payload) {
|
|
|
|
return $client->postAsync($url, [
|
|
|
|
'curl' => [
|
|
|
|
CURLOPT_HTTPHEADER => $headers,
|
|
|
|
CURLOPT_POSTFIELDS => $payload,
|
|
|
|
CURLOPT_HEADER => true
|
|
|
|
]
|
|
|
|
]);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$pool = new Pool($client, $requests($audience), [
|
|
|
|
'concurrency' => config('federation.activitypub.delivery.concurrency'),
|
|
|
|
'fulfilled' => function ($response, $index) {
|
|
|
|
},
|
|
|
|
'rejected' => function ($reason, $index) {
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
$promise = $pool->promise();
|
|
|
|
|
|
|
|
$promise->wait();
|
|
|
|
|
2022-10-07 09:15:34 +00:00
|
|
|
return 1;
|
2021-05-12 00:17:03 +00:00
|
|
|
}
|
2018-06-01 21:04:33 +00:00
|
|
|
}
|