[ENTITY][Actor] Add is_local, it's common to depend, and this makes it much faster, with a low space cost

This commit is contained in:
2021-11-16 23:24:06 +00:00
parent f1a30ac0e6
commit 89d36a68e5
6 changed files with 35 additions and 37 deletions

View File

@@ -145,9 +145,7 @@ class ActivitypubRsa extends Entity
$apRSA = self::getWithPK(['actor_id' => ($actor_id = $gsactor->getId())]);
if (!$apRSA instanceof self) {
// Nonexistent key pair for this profile
try {
// throws exception if remote
$gsactor->getLocalUser();
if ($gsactor->getIsLocal()) {
self::generateKeys($private_key, $public_key);
@@ -155,7 +153,7 @@ class ActivitypubRsa extends Entity
$apRSA->setActorId($actor_id);
$apRSA->setPrivateKey($private_key);
$apRSA->setPublicKey($public_key);
} catch (Exception) {
} else {
// ASSERT: This should never happen, but try to recover!
Log::error("Activitypub_rsa: An impossible thing has happened... Please let the devs know.");
if ($fetch) {

View File

@@ -239,6 +239,7 @@ class Explorer
'created' => new DateTime($res['published'] ?? 'now'),
'bio' => isset($res['summary']) ? mb_substr(Security::sanitize($res['summary']), 0, 1000) : null,
'homepage' => $res['url'] ?? $res['id'],
'is_local' => false,
'modified' => new DateTime(),
];

View File

@@ -5,6 +5,7 @@ declare(strict_types = 1);
namespace Plugin\ActivityPub\Util\Response;
use App\Entity\Actor;
use App\Util\Exception\ClientException;
use Exception;
use Plugin\ActivityPub\Util\Model\EntityToType\GSActorToType;
@@ -17,7 +18,10 @@ abstract class ActorResponse
*/
public static function handle(Actor $gsactor, int $status = 200): TypeResponse
{
$gsactor->getLocalUser(); // This throws exception if not a local user, which is intended
return new TypeResponse(data: GSActorToType::translate($gsactor), status: $status);
if ($gsactor->getIsLocal()) {
return new TypeResponse(data: GSActorToType::translate($gsactor), status: $status);
} else {
throw new ClientException('This is a remote actor, you should request it to its source of authority instead.');
}
}
}