Просмотр исходного кода

Update Inbox handler, remove logger

Daniel Supernault 5 лет назад
Родитель
Сommit
fee25d44e0
1 измененных файлов с 26 добавлено и 18 удалено
  1. 26 18
      app/Util/ActivityPub/Inbox.php

+ 26 - 18
app/Util/ActivityPub/Inbox.php

@@ -42,12 +42,12 @@ class Inbox
     {
     {
         $this->handleVerb();
         $this->handleVerb();
 
 
-        if(!Activity::where('data->id', $this->payload['id'])->exists()){
-            (new Activity())->create([
-                'to_id' => $this->profile->id,
-                'data' => json_encode($this->payload)
-            ]);
-        }
+        // if(!Activity::where('data->id', $this->payload['id'])->exists()) {
+        //     (new Activity())->create([
+        //         'to_id' => $this->profile->id,
+        //         '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 = Follower::firstOrCreate([
-                'profile_id' => $actor->id,
-                'following_id' => $target->id,
-                'local_profile' => empty($actor->domain)
-            ]);
-            if($follower->wasRecentlyCreated == true && $target->domain == null) {
-                // send notification
+            $follower = new Follower;
+            $follower->profile_id => $actor->id;
+            $follower->following_id => $target->id;
+            $follower->local_profile => empty($actor->domain);
+
+            if($target->domain == null) {
                 Notification::firstOrCreate([
                 Notification::firstOrCreate([
                     'profile_id' => $target->id,
                     'profile_id' => $target->id,
                     'actor_id' => $actor->id,
                     'actor_id' => $actor->id,