pixelfed/app/Util/ActivityPub/Inbox.php

86 lines
1.9 KiB
PHP
Raw Normal View History

2018-06-01 03:17:07 +00:00
<?php
namespace App\Util\ActivityPub;
2018-08-28 03:07:36 +00:00
use App\Like;
use App\Profile;
2018-06-01 03:17:07 +00:00
2018-08-28 03:07:36 +00:00
class Inbox
{
2018-06-01 03:17:07 +00:00
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)
{
2018-08-28 03:07:36 +00:00
if (Profile::whereRemoteUrl($actorUrl)->count() !== 0) {
2018-06-01 03:17:07 +00:00
return Profile::whereRemoteUrl($actorUrl)->firstOrFail();
}
$res = (new DiscoverActor($url))->discover();
$domain = parse_url($res['url'], PHP_URL_HOST);
$username = $res['preferredUsername'];
$remoteUsername = "@{$username}@{$domain}";
2018-08-28 03:07:36 +00:00
$profile = new Profile();
2018-06-01 03:17:07 +00:00
$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();
}
2018-08-28 03:07:36 +00:00
}