Update Inbox handler, remove logger

This commit is contained in:
Daniel Supernault 2020-05-21 16:45:51 -06:00
parent 18f32e7bcf
commit fee25d44e0
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -42,12 +42,12 @@ class Inbox
{ {
$this->handleVerb(); $this->handleVerb();
if(!Activity::where('data->id', $this->payload['id'])->exists()){ // if(!Activity::where('data->id', $this->payload['id'])->exists()) {
(new Activity())->create([ // (new Activity())->create([
'to_id' => $this->profile->id, // 'to_id' => $this->profile->id,
'data' => json_encode($this->payload) // 'data' => json_encode($this->payload)
]); // ]);
} // }
return; return;
@ -62,6 +62,7 @@ class Inbox
break; break;
case 'Follow': case 'Follow':
if(FollowValidator::validate($this->payload) == false) { return; }
$this->handleFollowActivity(); $this->handleFollowActivity();
break; break;
@ -80,6 +81,7 @@ class Inbox
break; break;
case 'Like': case 'Like':
if(LikeValidator::validate($this->payload) == false) { return; }
$this->handleLikeActivity(); $this->handleLikeActivity();
break; break;
@ -171,26 +173,32 @@ class Inbox
public function handleFollowActivity() public function handleFollowActivity()
{ {
$actor = $this->actorFirstOrCreate($this->payload['actor']); $actor = $this->actorFirstOrCreate($this->payload['actor']);
if(!$actor || $actor->domain == null) { $target = $this->profile;
if(!$actor || $actor->domain == null || $target->domain !== null) {
return;
}
if(
Follower::whereProfileId($actor->id)
->whereFollowingId($target->id)
->exists() ||
FollowRequest::whereFollowerId($actor->id)
->whereFollowingId($target->id)
->exists();
) {
return; return;
} }
$target = $this->profile;
if($target->is_private == true) { if($target->is_private == true) {
// make follow request
FollowRequest::firstOrCreate([ FollowRequest::firstOrCreate([
'follower_id' => $actor->id, 'follower_id' => $actor->id,
'following_id' => $target->id 'following_id' => $target->id
]); ]);
// todo: send notification
} else { } else {
// store new follower $follower = new Follower;
$follower = Follower::firstOrCreate([ $follower->profile_id => $actor->id;
'profile_id' => $actor->id, $follower->following_id => $target->id;
'following_id' => $target->id, $follower->local_profile => empty($actor->domain);
'local_profile' => empty($actor->domain)
]); if($target->domain == null) {
if($follower->wasRecentlyCreated == true && $target->domain == null) {
// send notification
Notification::firstOrCreate([ Notification::firstOrCreate([
'profile_id' => $target->id, 'profile_id' => $target->id,
'actor_id' => $actor->id, 'actor_id' => $actor->id,