now external profile updates are processed as well

This commit is contained in:
Ghostie 2024-12-29 14:27:51 -05:00
parent 27079892f2
commit ac00afca07
3 changed files with 69 additions and 12 deletions

View File

@ -12,12 +12,12 @@ Notice that the styles were taken from [AnySpace](https://anyspace.3to.moe/about
## TODO:
- [-] Activitypub
- [x] Accounts (users can now be found in mastodon instances)
- [x] Accounts
- [ ] Posts
- [ ] Local posts should be federated
- [ ] Remote posts should be fetched
- [x] Follows
- [ ] I cannot follow myself
- [x] I cannot follow myself
- [ ] Check when waiting for approval
- [ ] Likes
- [ ] 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)
- [ ] Allow custom CSS
- [ ] Profile audio
- [ ] Friends (they are known as follows in the activitypub protocol)
- [ ] Add friends
- [ ] Remove friends
- [x] Friends (they are known as follows in the activitypub protocol)
- [x] Add friends
- [x] Remove friends
- [ ] Posts (everything should be federated)
- [ ] Create posts
- [ ] Delete posts

View File

@ -5,13 +5,65 @@ namespace App\Http\Controllers\AP;
use Illuminate\Http\Request;
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;
class APInstanceInboxController extends Controller
{
public function inbox ()
{
$activity = 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"]);
}
}

View File

@ -106,10 +106,8 @@ class TypeActor {
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
$actor->actor_id = $request['id'] ?? '';
$actor->local_actor_id = TypeActor::actor_build_private_id ($actor->actor_id) ?? '';
@ -136,8 +134,6 @@ class TypeActor {
// Handle nested keys in `publicKey`
$actor->public_key = $request['publicKey']['publicKeyPem'] ?? '';
$actor->save ();
$instances = Instance::where ("inbox", $actor->sharedInbox);
if (!$instances->first ())
{
@ -149,6 +145,15 @@ class TypeActor {
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)
{
$parsed_url = parse_url ($actor_id);