diff --git a/app/Util/ActivityPub/Inbox.php b/app/Util/ActivityPub/Inbox.php new file mode 100644 index 00000000..310c91b8 --- /dev/null +++ b/app/Util/ActivityPub/Inbox.php @@ -0,0 +1,88 @@ +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(); + + } + +} \ No newline at end of file