forked from GNUsocial/gnu-social
[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
|
// Stay on same page, but force update and prevent resubmission
|
||||||
throw new RedirectException('settings_sort_languages');
|
throw new RedirectException('settings_sort_languages');
|
||||||
} else {
|
} 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
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public static function update_profile(self &$ap_actor, Actor &$actor, ActivitypubRsa &$activitypub_rsa, string $res): void
|
public static function update_profile(
|
||||||
{
|
self &$ap_actor,
|
||||||
\Plugin\ActivityPub\Util\Model\Actor::fromJson($res, ['objects' => ['ActivitypubActor' => &$ap_actor, 'Actor' => &$actor, 'ActivitypubRsa' => &$activitypub_rsa]]);
|
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
|
public static function schemaDef(): array
|
||||||
|
@ -38,6 +38,8 @@ use App\Core\Log;
|
|||||||
use App\Entity\Actor;
|
use App\Entity\Actor;
|
||||||
use App\Util\Exception\ServerException;
|
use App\Util\Exception\ServerException;
|
||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
|
use Exception;
|
||||||
|
use Plugin\ActivityPub\Util\Explorer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ActivityPub Keys System
|
* ActivityPub Keys System
|
||||||
@ -157,14 +159,24 @@ class ActivitypubRsa extends Entity
|
|||||||
'private_key' => $private_key,
|
'private_key' => $private_key,
|
||||||
'public_key' => $public_key,
|
'public_key' => $public_key,
|
||||||
]);
|
]);
|
||||||
DB::persist($apRSA);
|
DB::wrapInTransaction(fn () => DB::persist($apRSA));
|
||||||
} else {
|
} else {
|
||||||
// ASSERT: This should never happen, but try to recover!
|
// 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) {
|
if ($fetch) {
|
||||||
//$res = Activitypub_explorer::get_remote_user_activity($profile->getUri());
|
try {
|
||||||
//Activitypub_rsa::update_public_key($profile, $res['publicKey']['publicKeyPem']);
|
$res = Explorer::getRemoteActorActivity($gsactor->getUri());
|
||||||
//return self::ensure_public_key($profile, false);
|
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 {
|
} else {
|
||||||
throw new ServerException('Activitypub_rsa: Failed to find keys for given profile. That should have not happened!');
|
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
|
||||||
|
$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'])) {
|
if (isset($options['objects']['Actor'])) {
|
||||||
$actor = $options['objects']['Actor'];
|
$actor = GSActor::create($actor_map, $options['objects']['Actor']);
|
||||||
} else {
|
} 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);
|
$actor = GSActor::create($actor_map);
|
||||||
DB::persist($actor);
|
DB::persist($actor);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ActivityPub 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'])) {
|
if (isset($options['objects']['ActivitypubActor'])) {
|
||||||
$ap_actor = $options['objects']['ActivitypubActor'];
|
$ap_actor = ActivitypubActor::create($ap_actor_map, $options['objects']['ActivitypubActor']);
|
||||||
} else {
|
} else {
|
||||||
$ap_actor = ActivitypubActor::create([
|
$ap_actor = ActivitypubActor::create($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,
|
|
||||||
], $options['objects']['ActivitypubActor'] ?? null);
|
|
||||||
DB::persist($ap_actor);
|
DB::persist($ap_actor);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Public Key
|
// 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'])) {
|
if (isset($options['objects']['ActivitypubRsa'])) {
|
||||||
$apRSA = $options['objects']['ActivitypubRsa'];
|
$apRSA = ActivitypubRsa::create($ap_rsa_map, $options['objects']['ActivitypubRsa']);
|
||||||
} else {
|
} else {
|
||||||
$apRSA = ActivitypubRsa::create([
|
$apRSA = ActivitypubRsa::create($ap_rsa_map);
|
||||||
'actor_id' => $actor->getID(),
|
|
||||||
'public_key' => ($object->has('publicKey') && isset($object->get('publicKey')['publicKeyPem'])) ? $object->get('publicKey')['publicKeyPem'] : null,
|
|
||||||
], $options['objects']['ActivitypubRsa'] ?? null);
|
|
||||||
DB::persist($apRSA);
|
DB::persist($apRSA);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user