Update AP Inbox

This commit is contained in:
Daniel Supernault 2024-09-07 03:01:50 -06:00
parent 3e88b7c890
commit a55238d2e5
No known key found for this signature in database
GPG key ID: 23740873EE6F76A1

View file

@ -2,65 +2,58 @@
namespace App\Util\ActivityPub;
use Cache, DB, Log, Purify, Redis, Storage, Validator;
use Illuminate\Support\Facades\Bus;
use App\{
Activity,
DirectMessage,
Follower,
FollowRequest,
Instance,
Like,
Notification,
Media,
Profile,
Status,
StatusHashtag,
Story,
StoryView,
UserFilter
};
use Carbon\Carbon;
use App\Util\ActivityPub\Helpers;
use Illuminate\Support\Str;
use App\Jobs\LikePipeline\LikePipeline;
use App\Jobs\FollowPipeline\FollowPipeline;
use App\DirectMessage;
use App\Follower;
use App\FollowRequest;
use App\Instance;
use App\Jobs\DeletePipeline\DeleteRemoteProfilePipeline;
use App\Jobs\FollowPipeline\FollowPipeline;
use App\Jobs\HomeFeedPipeline\FeedRemoveRemotePipeline;
use App\Jobs\LikePipeline\LikePipeline;
use App\Jobs\MovePipeline\CleanupLegacyAccountMovePipeline;
use App\Jobs\MovePipeline\MoveMigrateFollowersPipeline;
use App\Jobs\MovePipeline\ProcessMovePipeline;
use App\Jobs\MovePipeline\UnfollowLegacyAccountMovePipeline;
use App\Jobs\ProfilePipeline\HandleUpdateActivity;
use App\Jobs\StatusPipeline\RemoteStatusDelete;
use App\Jobs\StatusPipeline\StatusRemoteUpdatePipeline;
use App\Jobs\StoryPipeline\StoryExpire;
use App\Jobs\StoryPipeline\StoryFetch;
use App\Jobs\StatusPipeline\StatusRemoteUpdatePipeline;
use App\Jobs\ProfilePipeline\HandleUpdateActivity;
use App\Jobs\MovePipeline\ProcessMovePipeline;
use App\Jobs\MovePipeline\MoveMigrateFollowersPipeline;
use App\Jobs\MovePipeline\UnfollowLegacyAccountMovePipeline;
use App\Jobs\MovePipeline\CleanupLegacyAccountMovePipeline;
use App\Like;
use App\Media;
use App\Models\Conversation;
use App\Models\RemoteReport;
use App\Notification;
use App\Profile;
use App\Services\AccountService;
use App\Services\FollowerService;
use App\Services\PollService;
use App\Services\ReblogService;
use App\Services\UserFilterService;
use App\Status;
use App\Story;
use App\StoryView;
use App\UserFilter;
use App\Util\ActivityPub\Validator\Accept as AcceptValidator;
use App\Util\ActivityPub\Validator\Add as AddValidator;
use App\Util\ActivityPub\Validator\Announce as AnnounceValidator;
use App\Util\ActivityPub\Validator\Follow as FollowValidator;
use App\Util\ActivityPub\Validator\Like as LikeValidator;
use App\Util\ActivityPub\Validator\UndoFollow as UndoFollowValidator;
use App\Util\ActivityPub\Validator\UpdatePersonValidator;
use App\Util\ActivityPub\Validator\MoveValidator;
use App\Services\AccountService;
use App\Services\PollService;
use App\Services\FollowerService;
use App\Services\ReblogService;
use App\Services\StatusService;
use App\Services\UserFilterService;
use App\Services\NetworkTimelineService;
use App\Models\Conversation;
use App\Models\RemoteReport;
use App\Jobs\HomeFeedPipeline\FeedRemoveRemotePipeline;
use App\Util\ActivityPub\Validator\UpdatePersonValidator;
use Cache;
use Illuminate\Support\Facades\Bus;
use Illuminate\Support\Str;
use Purify;
use Storage;
class Inbox
{
protected $headers;
protected $profile;
protected $payload;
protected $logger;
public function __construct($headers, $profile, $payload)
@ -73,7 +66,7 @@ class Inbox
public function handle()
{
$this->handleVerb();
return;
}
public function handleVerb()
@ -90,17 +83,23 @@ class Inbox
break;
case 'Follow':
if(FollowValidator::validate($this->payload) == false) { return; }
if (FollowValidator::validate($this->payload) == false) {
return;
}
$this->handleFollowActivity();
break;
case 'Announce':
if(AnnounceValidator::validate($this->payload) == false) { return; }
if (AnnounceValidator::validate($this->payload) == false) {
return;
}
$this->handleAnnounceActivity();
break;
case 'Accept':
if(AcceptValidator::validate($this->payload) == false) { return; }
if (AcceptValidator::validate($this->payload) == false) {
return;
}
$this->handleAcceptActivity();
break;
@ -109,7 +108,9 @@ class Inbox
break;
case 'Like':
if(LikeValidator::validate($this->payload) == false) { return; }
if (LikeValidator::validate($this->payload) == false) {
return;
}
$this->handleLikeActivity();
break;
@ -144,6 +145,7 @@ class Inbox
case 'Move':
if (MoveValidator::validate($this->payload) == false) {
\Log::info('[AP][INBOX][MOVE] VALIDATE_FAILURE '.json_encode($this->payload));
return;
}
$this->handleMoveActivity();
@ -205,7 +207,6 @@ class Inbox
break;
}
return;
}
public function handleCreateActivity()
@ -240,6 +241,7 @@ class Inbox
if ($activity['type'] == 'Question') {
$this->handlePollCreate();
return;
}
@ -250,6 +252,7 @@ class Inbox
parse_url($to[0], PHP_URL_HOST) == config('pixelfed.domain.app')
) {
$this->handleDirectMessage();
return;
}
@ -262,7 +265,7 @@ class Inbox
}
$this->handleNoteCreate();
}
return;
}
public function handleNoteReply()
@ -277,7 +280,7 @@ class Inbox
$url = isset($activity['url']) ? $activity['url'] : $activity['id'];
Helpers::statusFirstOrFetch($url, true);
return;
}
public function handlePollCreate()
@ -289,7 +292,7 @@ class Inbox
}
$url = isset($activity['url']) ? $activity['url'] : $activity['id'];
Helpers::statusFirstOrFetch($url);
return;
}
public function handleNoteCreate()
@ -307,6 +310,7 @@ class Inbox
Helpers::validateLocalUrl($activity['inReplyTo'])
) {
$this->handlePollVote();
return;
}
@ -335,7 +339,7 @@ class Inbox
$actor,
$activity
);
return;
}
public function handlePollVote()
@ -390,7 +394,6 @@ class Inbox
PollService::del($status->id);
return;
}
public function handleDirectMessage()
@ -450,13 +453,13 @@ class Inbox
Conversation::updateOrInsert(
[
'to_id' => $profile->id,
'from_id' => $actor->id
'from_id' => $actor->id,
],
[
'type' => 'text',
'status_id' => $status->id,
'dm_id' => $dm->id,
'is_hidden' => $hidden
'is_hidden' => $hidden,
]
);
@ -473,7 +476,7 @@ class Inbox
continue;
}
$media = new Media();
$media = new Media;
$media->remote_media = true;
$media->status_id = $status->id;
$media->profile_id = $status->profile_id;
@ -506,7 +509,7 @@ class Inbox
$dm->meta = [
'domain' => parse_url($msgText, PHP_URL_HOST),
'local' => parse_url($msgText, PHP_URL_HOST) ==
parse_url(config('app.url'), PHP_URL_HOST)
parse_url(config('app.url'), PHP_URL_HOST),
];
$dm->save();
}
@ -519,7 +522,7 @@ class Inbox
->exists();
if ($profile->domain == null && $hidden == false && ! $nf) {
$notification = new Notification();
$notification = new Notification;
$notification->profile_id = $profile->id;
$notification->actor_id = $actor->id;
$notification->action = 'dm';
@ -528,7 +531,6 @@ class Inbox
$notification->save();
}
return;
}
public function handleFollowActivity()
@ -568,7 +570,7 @@ class Inbox
'follower_id' => $actor->id,
'following_id' => $target->id,
], [
'activity' => collect($this->payload)->only(['id','actor','object','type'])->toArray()
'activity' => collect($this->payload)->only(['id', 'actor', 'object', 'type'])->toArray(),
]);
} else {
$follower = new Follower;
@ -590,8 +592,8 @@ class Inbox
'id' => $this->payload['id'],
'actor' => $actor->permalink(),
'type' => 'Follow',
'object' => $target->permalink()
]
'object' => $target->permalink(),
],
];
Helpers::sendSignedObject($target, $actor->inbox_url, $accept);
Cache::forget('profile:follower_count:'.$target->id);
@ -600,7 +602,6 @@ class Inbox
Cache::forget('profile:following_count:'.$actor->id);
}
return;
}
public function handleAnnounceActivity()
@ -630,7 +631,7 @@ class Inbox
$status = Status::firstOrCreate([
'profile_id' => $actor->id,
'reblog_of_id' => $parent->id,
'type' => 'share'
'type' => 'share',
]);
Notification::firstOrCreate(
@ -648,7 +649,6 @@ class Inbox
ReblogService::addPostReblog($parent->profile_id, $status->id);
return;
}
public function handleAcceptActivity()
@ -696,7 +696,6 @@ class Inbox
$request->delete();
return;
}
public function handleDeleteActivity()
@ -715,6 +714,7 @@ class Inbox
return;
}
DeleteRemoteProfilePipeline::dispatch($profile)->onQueue('inbox');
return;
} else {
if (! isset(
@ -741,6 +741,7 @@ class Inbox
return;
}
DeleteRemoteProfilePipeline::dispatch($profile)->onQueue('inbox');
return;
break;
@ -766,6 +767,7 @@ class Inbox
}
}
RemoteStatusDelete::dispatch($status)->onQueue('high');
return;
break;
@ -775,6 +777,7 @@ class Inbox
if ($story) {
StoryExpire::dispatch($story)->onQueue('story');
}
return;
break;
@ -783,7 +786,7 @@ class Inbox
break;
}
}
return;
}
public function handleLikeActivity()
@ -815,7 +818,7 @@ class Inbox
$like = Like::firstOrCreate([
'profile_id' => $profile->id,
'status_id' => $status->id
'status_id' => $status->id,
]);
if ($like->wasRecentlyCreated == true) {
@ -824,12 +827,9 @@ class Inbox
LikePipeline::dispatch($like);
}
return;
}
public function handleRejectActivity()
{
}
public function handleRejectActivity() {}
public function handleUndoActivity()
{
@ -931,7 +931,7 @@ class Inbox
->forceDelete();
break;
}
return;
}
public function handleViewActivity()
@ -983,7 +983,7 @@ class Inbox
$view = StoryView::firstOrCreate([
'story_id' => $story->id,
'profile_id' => $profile->id
'profile_id' => $profile->id,
]);
if ($view->wasRecentlyCreated == true) {
@ -991,7 +991,6 @@ class Inbox
$story->save();
}
return;
}
public function handleStoryReactionActivity()
@ -1074,7 +1073,7 @@ class Inbox
$status->in_reply_to_profile_id = $story->profile_id;
$status->entities = json_encode([
'story_id' => $story->id,
'reaction' => $text
'reaction' => $text,
]);
$status->save();
@ -1088,20 +1087,20 @@ class Inbox
'story_actor_username' => $actorProfile->username,
'story_id' => $story->id,
'story_media_url' => url(Storage::url($story->path)),
'reaction' => $text
'reaction' => $text,
]);
$dm->save();
Conversation::updateOrInsert(
[
'to_id' => $story->profile_id,
'from_id' => $actorProfile->id
'from_id' => $actorProfile->id,
],
[
'type' => 'story:react',
'status_id' => $status->id,
'dm_id' => $dm->id,
'is_hidden' => false
'is_hidden' => false,
]
);
@ -1113,7 +1112,6 @@ class Inbox
$n->action = 'story:react';
$n->save();
return;
}
public function handleStoryReplyActivity()
@ -1169,7 +1167,6 @@ class Inbox
$actorProfile = Helpers::profileFetch($actor);
if (AccountService::blocksDomain($targetProfile->id, $actorProfile->domain) == true) {
return;
}
@ -1197,7 +1194,7 @@ class Inbox
$status->in_reply_to_profile_id = $story->profile_id;
$status->entities = json_encode([
'story_id' => $story->id,
'caption' => $text
'caption' => $text,
]);
$status->save();
@ -1211,20 +1208,20 @@ class Inbox
'story_actor_username' => $actorProfile->username,
'story_id' => $story->id,
'story_media_url' => url(Storage::url($story->path)),
'caption' => $text
'caption' => $text,
]);
$dm->save();
Conversation::updateOrInsert(
[
'to_id' => $story->profile_id,
'from_id' => $actorProfile->id
'from_id' => $actorProfile->id,
],
[
'type' => 'story:comment',
'status_id' => $status->id,
'dm_id' => $dm->id,
'is_hidden' => false
'is_hidden' => false,
]
);
@ -1236,7 +1233,6 @@ class Inbox
$n->action = 'story:comment';
$n->save();
return;
}
public function handleFlagActivity()
@ -1321,7 +1317,7 @@ class Inbox
$instanceHost = parse_url($id, PHP_URL_HOST);
$instance = Instance::updateOrCreate([
'domain' => $instanceHost
'domain' => $instanceHost,
]);
$report = new RemoteReport;
@ -1332,11 +1328,10 @@ class Inbox
$report->instance_id = $instance->id;
$report->report_meta = [
'actor' => $actor,
'object' => $object
'object' => $object,
];
$report->save();
return;
}
public function handleUpdateActivity()
@ -1376,10 +1371,10 @@ class Inbox
}
Bus::chain([
new ProcessMoveActivity,
new ProcessMovePipeline,
new MoveMigrateFollowersPipeline,
new UnfollowLegacyAccountMovePipeline,
new CleanupLegacyAccountMovePipeline
new CleanupLegacyAccountMovePipeline,
])
->onQueue('move')
->dispatch($target, $activity);