1
0
Fork 0
forked from mirror/pixelfed

Remove AP logger from Inbox

This commit is contained in:
Daniel Supernault 2018-12-23 19:42:50 -07:00
parent b5bee7b87d
commit 7f88500d18
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -32,7 +32,7 @@ class Inbox
public function handle() public function handle()
{ {
$this->authenticatePayload(); $this->handleVerb();
} }
public function authenticatePayload() public function authenticatePayload()
@ -142,16 +142,11 @@ class Inbox
$activity = $this->payload['object']; $activity = $this->payload['object'];
$actor = $this->actorFirstOrCreate($this->payload['actor']); $actor = $this->actorFirstOrCreate($this->payload['actor']);
$inReplyTo = $activity['inReplyTo']; $inReplyTo = $activity['inReplyTo'];
$url = $activity['id'];
if(!Helpers::statusFirstOrFetch($activity['url'], true)) { if(!Helpers::statusFirstOrFetch($url, true)) {
$this->logger->delete();
return; return;
} }
$this->logger->to_id = $this->profile->id;
$this->logger->from_id = $actor->id;
$this->logger->processed_at = Carbon::now();
$this->logger->save();
} }
public function handleNoteCreate() public function handleNoteCreate()
@ -164,12 +159,11 @@ class Inbox
if(Helpers::userInAudience($this->profile, $this->payload) == false) { if(Helpers::userInAudience($this->profile, $this->payload) == false) {
//Log::error('AP:inbox:userInAudience:false - Activity#'.$this->logger->id); //Log::error('AP:inbox:userInAudience:false - Activity#'.$this->logger->id);
$logger = Activity::find($this->logger->id);
$logger->delete();
return; return;
} }
if(Status::whereUrl($activity['url'])->exists()) { $url = $activity['id'];
if(Status::whereUrl($url)->exists()) {
return; return;
} }
@ -178,18 +172,12 @@ class Inbox
$status->profile_id = $actor->id; $status->profile_id = $actor->id;
$status->caption = strip_tags($activity['content']); $status->caption = strip_tags($activity['content']);
$status->visibility = $status->scope = 'public'; $status->visibility = $status->scope = 'public';
$status->url = $activity['url']; $status->url = $url;
$status->save(); $status->save();
return $status; return $status;
}); });
Helpers::importNoteAttachment($activity, $status); Helpers::importNoteAttachment($activity, $status);
$logger = Activity::find($this->logger->id);
$logger->to_id = $this->profile->id;
$logger->from_id = $actor->id;
$logger->processed_at = Carbon::now();
$logger->save();
} }
public function handleFollowActivity() public function handleFollowActivity()
@ -214,7 +202,6 @@ class Inbox
'local_profile' => empty($actor->domain) 'local_profile' => empty($actor->domain)
]); ]);
if($follower->wasRecentlyCreated == false) { if($follower->wasRecentlyCreated == false) {
$this->logger->delete();
return; return;
} }
// send notification // send notification
@ -228,37 +215,53 @@ class Inbox
$notification->item_type = "App\Profile"; $notification->item_type = "App\Profile";
$notification->save(); $notification->save();
\Cache::forever('notification.'.$notification->id, $notification);
$redis = Redis::connection();
$nkey = config('cache.prefix').':user.'.$target->id.'.notifications';
$redis->lpush($nkey, $notification->id);
// send Accept to remote profile // send Accept to remote profile
$accept = [ $accept = [
'@context' => 'https://www.w3.org/ns/activitystreams', '@context' => 'https://www.w3.org/ns/activitystreams',
'id' => $follower->permalink('/accept'), 'id' => $target->permalink().'#accepts/follows/',
'type' => 'Accept', 'type' => 'Accept',
'actor' => $target->permalink(), 'actor' => $target->permalink(),
'object' => [ 'object' => [
'id' => $this->payload['id'], 'id' => $actor->permalink('#follows/'.$target->id),
'type' => 'Follow', 'type' => 'Follow',
'actor' => $target->permalink(), 'actor' => $actor->permalink(),
'object' => $actor->permalink() 'object' => $target->permalink()
] ]
]; ];
Helpers::sendSignedObject($target, $actor->inbox_url, $accept); Helpers::sendSignedObject($target, $actor->inbox_url, $accept);
} }
$this->logger->to_id = $target->id;
$this->logger->from_id = $actor->id;
$this->logger->processed_at = Carbon::now();
$this->logger->save();
} }
public function handleAnnounceActivity() public function handleAnnounceActivity()
{ {
$actor = $this->actorFirstOrCreate($this->payload['actor']);
$activity = $this->payload['object'];
if(!$actor || $actor->domain == null) {
return;
}
if(Helpers::validateLocalUrl($activity) == false) {
return;
}
$parent = Helpers::statusFirstOrFetch($activity, true);
if(!$parent) {
return;
}
$status = Status::firstOrCreate([
'profile_id' => $actor->id,
'in_reply_to_id' => $parent->id,
'type' => 'reply'
]);
if($status->wasRecentlyCreated) {
$notification = new Notification();
$notification->profile_id = $parent->profile->id;
$notification->actor_id = $actor->id;
$notification->action = 'comment';
$notification->message = $status->toText();
$notification->rendered = $status->toHtml();
$notification->item_id = $parent->id;
$notification->item_type = "App\Status";
$notification->save();
}
} }
public function handleAcceptActivity() public function handleAcceptActivity()
@ -289,10 +292,6 @@ class Inbox
return; return;
} }
LikePipeline::dispatch($like); LikePipeline::dispatch($like);
$this->logger->to_id = $status->profile_id;
$this->logger->from_id = $profile->id;
$this->logger->processed_at = Carbon::now();
$this->logger->save();
} }
@ -306,19 +305,15 @@ class Inbox
$actor = $this->payload['actor']; $actor = $this->payload['actor'];
$profile = self::actorFirstOrCreate($actor); $profile = self::actorFirstOrCreate($actor);
$obj = $this->payload['object']; $obj = $this->payload['object'];
$status = Helpers::statusFirstOrFetch($obj['object']);
switch ($obj['type']) { switch ($obj['type']) {
case 'Like': case 'Like':
$status = Helpers::statusFirstOrFetch($obj['object']);
Like::whereProfileId($profile->id) Like::whereProfileId($profile->id)
->whereStatusId($status->id) ->whereStatusId($status->id)
->delete(); ->delete();
break; break;
} }
$this->logger->to_id = $status->profile_id;
$this->logger->from_id = $profile->id;
$this->logger->processed_at = Carbon::now();
$this->logger->save();
} }
} }