Ver Fonte

Add Inbox util

Daniel Supernault há 7 anos atrás
pai
commit
753b6d4721
1 ficheiros alterados com 88 adições e 0 exclusões
  1. 88 0
      app/Util/ActivityPub/Inbox.php

+ 88 - 0
app/Util/ActivityPub/Inbox.php

@@ -0,0 +1,88 @@
+<?php
+
+namespace App\Util\ActivityPub;
+
+use App\Jobs\AvatarPipeline\CreateAvatar;
+use App\{Follower, Like, Profile, Like, Status, User};
+
+class Inbox {
+
+    protected $request;
+    protected $profile;
+    protected $payload;
+
+    public function __construct($request, Profile $profile, $payload)
+    {
+        $this->request = $request;
+        $this->profile = $profile;
+        $this->payload = $payload;
+    }
+
+    public function handle()
+    {
+        $this->authenticatePayload();
+    }
+
+    public function authenticatePayload()
+    {
+        // todo
+
+        $this->handleVerb();
+    }
+
+    public function handleVerb()
+    {
+        $verb = $this->payload['type'];
+
+        switch ($verb) {
+            case 'Create':
+                $this->handleCreateActivity();
+                break;
+
+            case 'Follow':
+                $this->handleFollowActivity();
+                break;
+
+            default:
+                // TODO: decide how to handle invalid verbs.
+                break;
+        }
+    }
+
+    public function handleCreateActivity()
+    {
+        // todo
+    }
+
+    public function handleFollowActivity()
+    {
+        $actor = $this->payload['object'];
+        $target = $this->profile;
+
+    }
+
+    public function actorFirstOrCreate($actorUrl)
+    {
+        if(Profile::whereRemoteUrl($actorUrl)->count() !== 0) {
+            return Profile::whereRemoteUrl($actorUrl)->firstOrFail();
+        }
+
+        $res = (new DiscoverActor($url))->discover();
+
+        $domain = parse_url($res['url'], PHP_URL_HOST);
+        $username = $res['preferredUsername'];
+        $remoteUsername = "@{$username}@{$domain}";
+
+        $profile = new Profile;
+        $profile->user_id = null;
+        $profile->domain = $domain;
+        $profile->username = $remoteUsername;
+        $profile->name = $res['name'];
+        $profile->bio = str_limit($res['summary'], 125);
+        $profile->sharedInbox = $res['endpoints']['sharedInbox'];
+        $profile->remote_url = $res['url'];
+        $profile->save();
+
+    }
+
+}