[PLUGIN][ActivityPub][Model][Actor] Fix internal logic for updating
Actors
This commit is contained in:
parent
1daa314c55
commit
626b4263f1
@ -134,7 +134,7 @@ class Language extends Controller
|
||||
// Stay on same page, but force update and prevent resubmission
|
||||
throw new RedirectException('settings_sort_languages');
|
||||
} else {
|
||||
throw new RedirectException('settings', ['open' => 'account', '_fragment' => 'save_account_info_languages']);
|
||||
throw new RedirectException('person_actor_settings', ['id' => $user->getId(), 'open' => 'settings-language-details', '_fragment' => 'settings-language-details']);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -233,9 +233,17 @@ class ActivitypubActor extends Entity
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function update_profile(self &$ap_actor, Actor &$actor, ActivitypubRsa &$activitypub_rsa, string $res): void
|
||||
{
|
||||
\Plugin\ActivityPub\Util\Model\Actor::fromJson($res, ['objects' => ['ActivitypubActor' => &$ap_actor, 'Actor' => &$actor, 'ActivitypubRsa' => &$activitypub_rsa]]);
|
||||
public static function update_profile(
|
||||
self &$ap_actor,
|
||||
Actor &$actor,
|
||||
ActivitypubRsa &$activitypub_rsa,
|
||||
string $res,
|
||||
): void {
|
||||
\Plugin\ActivityPub\Util\Model\Actor::fromJson($res, ['objects' => [
|
||||
'ActivitypubActor' => &$ap_actor,
|
||||
'Actor' => &$actor,
|
||||
'ActivitypubRsa' => &$activitypub_rsa,
|
||||
]]);
|
||||
}
|
||||
|
||||
public static function schemaDef(): array
|
||||
|
@ -38,6 +38,8 @@ use App\Core\Log;
|
||||
use App\Entity\Actor;
|
||||
use App\Util\Exception\ServerException;
|
||||
use DateTimeInterface;
|
||||
use Exception;
|
||||
use Plugin\ActivityPub\Util\Explorer;
|
||||
|
||||
/**
|
||||
* ActivityPub Keys System
|
||||
@ -157,14 +159,24 @@ class ActivitypubRsa extends Entity
|
||||
'private_key' => $private_key,
|
||||
'public_key' => $public_key,
|
||||
]);
|
||||
DB::persist($apRSA);
|
||||
DB::wrapInTransaction(fn () => DB::persist($apRSA));
|
||||
} else {
|
||||
// ASSERT: This should never happen, but try to recover!
|
||||
Log::error('Activitypub_rsa: An impossible thing has happened... Please let the devs know.');
|
||||
Log::error('Activitypub_rsa: It seems that the RSA key for this remote actor was somehow lost. That should have never happened!');
|
||||
if ($fetch) {
|
||||
//$res = Activitypub_explorer::get_remote_user_activity($profile->getUri());
|
||||
//Activitypub_rsa::update_public_key($profile, $res['publicKey']['publicKeyPem']);
|
||||
//return self::ensure_public_key($profile, false);
|
||||
try {
|
||||
$res = Explorer::getRemoteActorActivity($gsactor->getUri());
|
||||
if (\is_null($res)) {
|
||||
throw new ServerException('Activitypub_rsa: Failed to find keys for given profile. That should have not happened! Invalid remote actor (null response).');
|
||||
}
|
||||
DB::wrapInTransaction(fn () => DB::persist(self::create([
|
||||
'actor_id' => $gsactor->getId(),
|
||||
'public_key' => json_decode($res, associative: true)['publicKey']['publicKeyPem'],
|
||||
])));
|
||||
return self::getByActor($gsactor, false);
|
||||
} catch (Exception $e) {
|
||||
throw new ServerException('Activitypub_rsa: Failed to find keys for given profile. That should have not happened!', previous: $e);
|
||||
}
|
||||
} else {
|
||||
throw new ServerException('Activitypub_rsa: Failed to find keys for given profile. That should have not happened!');
|
||||
}
|
||||
|
@ -104,45 +104,47 @@ class Actor extends Model
|
||||
}
|
||||
|
||||
// Actor
|
||||
$actor_map = [
|
||||
'nickname' => $object->get('preferredUsername'),
|
||||
'fullname' => !empty($object->get('name')) ? $object->get('name') : null,
|
||||
'created' => new DateTime($object->get('published') ?? 'now'),
|
||||
'bio' => $object->get('summary'),
|
||||
'is_local' => false, // duh!
|
||||
'type' => self::$_as2_actor_type_to_gs_actor_type[$object->get('type')],
|
||||
'roles' => $roles,
|
||||
'modified' => new DateTime(),
|
||||
];
|
||||
if (isset($options['objects']['Actor'])) {
|
||||
$actor = $options['objects']['Actor'];
|
||||
$actor = GSActor::create($actor_map, $options['objects']['Actor']);
|
||||
} else {
|
||||
$actor_map = [
|
||||
'nickname' => $object->get('preferredUsername'),
|
||||
'fullname' => !empty($object->get('name')) ? $object->get('name') : null,
|
||||
'created' => new DateTime($object->get('published') ?? 'now'),
|
||||
'bio' => $object->get('summary'),
|
||||
'is_local' => false, // duh!
|
||||
'type' => self::$_as2_actor_type_to_gs_actor_type[$object->get('type')],
|
||||
'roles' => $roles,
|
||||
'modified' => new DateTime(),
|
||||
];
|
||||
$actor = GSActor::create($actor_map);
|
||||
DB::persist($actor);
|
||||
}
|
||||
|
||||
// ActivityPub Actor
|
||||
$ap_actor_map = [
|
||||
'inbox_uri' => $object->get('inbox'),
|
||||
'inbox_shared_uri' => ($object->has('endpoints') && isset($object->get('endpoints')['sharedInbox'])) ? $object->get('endpoints')['sharedInbox'] : null,
|
||||
'uri' => $object->get('id'),
|
||||
'actor_id' => $actor->getId(),
|
||||
'url' => $object->get('url') ?? null,
|
||||
];
|
||||
if (isset($options['objects']['ActivitypubActor'])) {
|
||||
$ap_actor = $options['objects']['ActivitypubActor'];
|
||||
$ap_actor = ActivitypubActor::create($ap_actor_map, $options['objects']['ActivitypubActor']);
|
||||
} else {
|
||||
$ap_actor = ActivitypubActor::create([
|
||||
'inbox_uri' => $object->get('inbox'),
|
||||
'inbox_shared_uri' => ($object->has('endpoints') && isset($object->get('endpoints')['sharedInbox'])) ? $object->get('endpoints')['sharedInbox'] : null,
|
||||
'uri' => $object->get('id'),
|
||||
'actor_id' => $actor->getId(),
|
||||
'url' => $object->get('url') ?? null,
|
||||
], $options['objects']['ActivitypubActor'] ?? null);
|
||||
$ap_actor = ActivitypubActor::create($ap_actor_map);
|
||||
DB::persist($ap_actor);
|
||||
}
|
||||
|
||||
// Public Key
|
||||
$ap_rsa_map = [
|
||||
'actor_id' => $actor->getID(),
|
||||
'public_key' => ($object->has('publicKey') && isset($object->get('publicKey')['publicKeyPem'])) ? $object->get('publicKey')['publicKeyPem'] : null,
|
||||
];
|
||||
if (isset($options['objects']['ActivitypubRsa'])) {
|
||||
$apRSA = $options['objects']['ActivitypubRsa'];
|
||||
$apRSA = ActivitypubRsa::create($ap_rsa_map, $options['objects']['ActivitypubRsa']);
|
||||
} else {
|
||||
$apRSA = ActivitypubRsa::create([
|
||||
'actor_id' => $actor->getID(),
|
||||
'public_key' => ($object->has('publicKey') && isset($object->get('publicKey')['publicKeyPem'])) ? $object->get('publicKey')['publicKeyPem'] : null,
|
||||
], $options['objects']['ActivitypubRsa'] ?? null);
|
||||
$apRSA = ActivitypubRsa::create($ap_rsa_map);
|
||||
DB::persist($apRSA);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user