now external profile updates are processed as well
This commit is contained in:
parent
27079892f2
commit
ac00afca07
10
README.md
10
README.md
@ -12,12 +12,12 @@ Notice that the styles were taken from [AnySpace](https://anyspace.3to.moe/about
|
|||||||
## TODO:
|
## TODO:
|
||||||
|
|
||||||
- [-] Activitypub
|
- [-] Activitypub
|
||||||
- [x] Accounts (users can now be found in mastodon instances)
|
- [x] Accounts
|
||||||
- [ ] Posts
|
- [ ] Posts
|
||||||
- [ ] Local posts should be federated
|
- [ ] Local posts should be federated
|
||||||
- [ ] Remote posts should be fetched
|
- [ ] Remote posts should be fetched
|
||||||
- [x] Follows
|
- [x] Follows
|
||||||
- [ ] I cannot follow myself
|
- [x] I cannot follow myself
|
||||||
- [ ] Check when waiting for approval
|
- [ ] Check when waiting for approval
|
||||||
- [ ] Likes
|
- [ ] Likes
|
||||||
- [ ] Comments
|
- [ ] Comments
|
||||||
@ -31,9 +31,9 @@ Notice that the styles were taken from [AnySpace](https://anyspace.3to.moe/about
|
|||||||
- [ ] Mark account as private (in federation manual approval is needed)
|
- [ ] Mark account as private (in federation manual approval is needed)
|
||||||
- [ ] Allow custom CSS
|
- [ ] Allow custom CSS
|
||||||
- [ ] Profile audio
|
- [ ] Profile audio
|
||||||
- [ ] Friends (they are known as follows in the activitypub protocol)
|
- [x] Friends (they are known as follows in the activitypub protocol)
|
||||||
- [ ] Add friends
|
- [x] Add friends
|
||||||
- [ ] Remove friends
|
- [x] Remove friends
|
||||||
- [ ] Posts (everything should be federated)
|
- [ ] Posts (everything should be federated)
|
||||||
- [ ] Create posts
|
- [ ] Create posts
|
||||||
- [ ] Delete posts
|
- [ ] Delete posts
|
||||||
|
@ -5,13 +5,65 @@ namespace App\Http\Controllers\AP;
|
|||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
|
use App\Models\Actor;
|
||||||
|
use App\Models\Activity;
|
||||||
|
|
||||||
|
use App\Types\TypeActor;
|
||||||
|
use App\Types\TypeActivity;
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
|
|
||||||
class APInstanceInboxController extends Controller
|
class APInstanceInboxController extends Controller
|
||||||
{
|
{
|
||||||
public function inbox ()
|
public function inbox ()
|
||||||
{
|
{
|
||||||
Log::info ("APInstanceInboxController:inbox");
|
$activity = request ()->all ();
|
||||||
Log::info (json_encode (request ()->all ()));
|
$activity_type = $activity['type'];
|
||||||
|
|
||||||
|
switch ($activity_type)
|
||||||
|
{
|
||||||
|
case "Update":
|
||||||
|
return $this->handle_update ($activity);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
Log::info ("APInstanceInboxController:inbox");
|
||||||
|
Log::info (json_encode (request ()->all ()));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return response ()->json (["status" => "ok"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function handle_update ($activity)
|
||||||
|
{
|
||||||
|
if (TypeActivity::activity_exists ($activity ["id"]))
|
||||||
|
return response ()->json (["status" => "ok"]);
|
||||||
|
|
||||||
|
$activity ["activity_id"] = $activity ["id"];
|
||||||
|
$new_activity = Activity::create ($activity);
|
||||||
|
|
||||||
|
$object = $activity ["object"];
|
||||||
|
|
||||||
|
switch ($object ["type"])
|
||||||
|
{
|
||||||
|
case "Person":
|
||||||
|
return $this->handle_update_person ($object);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return response ()->json (["status" => "ok"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function handle_update_person ($person)
|
||||||
|
{
|
||||||
|
$actor = Actor::where ("actor_id", $person ["id"])->first ();
|
||||||
|
if (!$actor)
|
||||||
|
$actor = TypeActor::create_from_request ($person);
|
||||||
|
|
||||||
|
TypeActor::update_from_request ($actor, $person);
|
||||||
|
$actor->save ();
|
||||||
|
|
||||||
|
return response ()->json (["status" => "ok"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,10 +106,8 @@ class TypeActor {
|
|||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function create_from_request ($request)
|
public static function update_from_request (Actor $actor, $request)
|
||||||
{
|
{
|
||||||
$actor = new Actor ();
|
|
||||||
|
|
||||||
// Use null coalescing operator `??` for safety
|
// Use null coalescing operator `??` for safety
|
||||||
$actor->actor_id = $request['id'] ?? '';
|
$actor->actor_id = $request['id'] ?? '';
|
||||||
$actor->local_actor_id = TypeActor::actor_build_private_id ($actor->actor_id) ?? '';
|
$actor->local_actor_id = TypeActor::actor_build_private_id ($actor->actor_id) ?? '';
|
||||||
@ -136,8 +134,6 @@ class TypeActor {
|
|||||||
// Handle nested keys in `publicKey`
|
// Handle nested keys in `publicKey`
|
||||||
$actor->public_key = $request['publicKey']['publicKeyPem'] ?? '';
|
$actor->public_key = $request['publicKey']['publicKeyPem'] ?? '';
|
||||||
|
|
||||||
$actor->save ();
|
|
||||||
|
|
||||||
$instances = Instance::where ("inbox", $actor->sharedInbox);
|
$instances = Instance::where ("inbox", $actor->sharedInbox);
|
||||||
if (!$instances->first ())
|
if (!$instances->first ())
|
||||||
{
|
{
|
||||||
@ -149,6 +145,15 @@ class TypeActor {
|
|||||||
return $actor;
|
return $actor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function create_from_request ($request)
|
||||||
|
{
|
||||||
|
$actor = new Actor ();
|
||||||
|
TypeActor::update_from_request ($actor, $request);
|
||||||
|
|
||||||
|
$actor->save ();
|
||||||
|
return $actor;
|
||||||
|
}
|
||||||
|
|
||||||
public static function obtain_actor_info ($actor_id)
|
public static function obtain_actor_info ($actor_id)
|
||||||
{
|
{
|
||||||
$parsed_url = parse_url ($actor_id);
|
$parsed_url = parse_url ($actor_id);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user