Fetch local data without HTTP requests
This commit is contained in:
parent
d8bf9c4601
commit
424a85bb94
|
@ -31,11 +31,13 @@ use Friendica\DI;
|
||||||
use Friendica\Network\Probe;
|
use Friendica\Network\Probe;
|
||||||
use Friendica\Protocol\ActivityNamespace;
|
use Friendica\Protocol\ActivityNamespace;
|
||||||
use Friendica\Protocol\ActivityPub;
|
use Friendica\Protocol\ActivityPub;
|
||||||
|
use Friendica\Protocol\ActivityPub\Transmitter;
|
||||||
use Friendica\Util\Crypto;
|
use Friendica\Util\Crypto;
|
||||||
use Friendica\Util\DateTimeFormat;
|
use Friendica\Util\DateTimeFormat;
|
||||||
use Friendica\Util\HTTPSignature;
|
use Friendica\Util\HTTPSignature;
|
||||||
use Friendica\Util\JsonLD;
|
use Friendica\Util\JsonLD;
|
||||||
use Friendica\Util\Network;
|
use Friendica\Util\Network;
|
||||||
|
use Friendica\Util\Strings;
|
||||||
|
|
||||||
class APContact
|
class APContact
|
||||||
{
|
{
|
||||||
|
@ -161,6 +163,14 @@ class APContact
|
||||||
DI::cache()->set($cachekey, System::callstack(20), Duration::FIVE_MINUTES);
|
DI::cache()->set($cachekey, System::callstack(20), Duration::FIVE_MINUTES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Network::isLocalLink($url) && ($local_uid = User::getIdForURL($url))) {
|
||||||
|
$data = Transmitter::getProfile($local_uid);
|
||||||
|
$local_owner = User::getOwnerDataById($local_uid);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($data)) {
|
||||||
|
$local_owner = [];
|
||||||
|
|
||||||
$curlResult = HTTPSignature::fetchRaw($url);
|
$curlResult = HTTPSignature::fetchRaw($url);
|
||||||
$failed = empty($curlResult) || empty($curlResult->getBody()) ||
|
$failed = empty($curlResult) || empty($curlResult->getBody()) ||
|
||||||
(!$curlResult->isSuccess() && ($curlResult->getReturnCode() != 410));
|
(!$curlResult->isSuccess() && ($curlResult->getReturnCode() != 410));
|
||||||
|
@ -178,6 +188,7 @@ class APContact
|
||||||
self::markForArchival($fetched_contact ?: []);
|
self::markForArchival($fetched_contact ?: []);
|
||||||
return $fetched_contact;
|
return $fetched_contact;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$compacted = JsonLD::compact($data);
|
$compacted = JsonLD::compact($data);
|
||||||
if (empty($compacted['@id'])) {
|
if (empty($compacted['@id'])) {
|
||||||
|
@ -267,7 +278,11 @@ class APContact
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($apcontact['following'])) {
|
if (!empty($apcontact['following'])) {
|
||||||
|
if (!empty($local_owner)) {
|
||||||
|
$following = ActivityPub\Transmitter::getContacts($local_owner, [Contact::SHARING, Contact::FRIEND], 'following');
|
||||||
|
} else {
|
||||||
$following = ActivityPub::fetchContent($apcontact['following']);
|
$following = ActivityPub::fetchContent($apcontact['following']);
|
||||||
|
}
|
||||||
if (!empty($following['totalItems'])) {
|
if (!empty($following['totalItems'])) {
|
||||||
// Mastodon seriously allows for this condition?
|
// Mastodon seriously allows for this condition?
|
||||||
// Jul 14 2021 - See https://mastodon.social/@BLUW for a negative following count
|
// Jul 14 2021 - See https://mastodon.social/@BLUW for a negative following count
|
||||||
|
@ -279,7 +294,11 @@ class APContact
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($apcontact['followers'])) {
|
if (!empty($apcontact['followers'])) {
|
||||||
|
if (!empty($local_owner)) {
|
||||||
|
$followers = ActivityPub\Transmitter::getContacts($local_owner, [Contact::FOLLOWER, Contact::FRIEND], 'followers');
|
||||||
|
} else {
|
||||||
$followers = ActivityPub::fetchContent($apcontact['followers']);
|
$followers = ActivityPub::fetchContent($apcontact['followers']);
|
||||||
|
}
|
||||||
if (!empty($followers['totalItems'])) {
|
if (!empty($followers['totalItems'])) {
|
||||||
// Mastodon seriously allows for this condition?
|
// Mastodon seriously allows for this condition?
|
||||||
// Jul 14 2021 - See https://mastodon.online/@goes11 for a negative followers count
|
// Jul 14 2021 - See https://mastodon.online/@goes11 for a negative followers count
|
||||||
|
@ -291,7 +310,11 @@ class APContact
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($apcontact['outbox'])) {
|
if (!empty($apcontact['outbox'])) {
|
||||||
|
if (!empty($local_owner)) {
|
||||||
|
$outbox = ActivityPub\Transmitter::getOutbox($local_owner);
|
||||||
|
} else {
|
||||||
$outbox = ActivityPub::fetchContent($apcontact['outbox']);
|
$outbox = ActivityPub::fetchContent($apcontact['outbox']);
|
||||||
|
}
|
||||||
if (!empty($outbox['totalItems'])) {
|
if (!empty($outbox['totalItems'])) {
|
||||||
$apcontact['statuses_count'] = $outbox['totalItems'];
|
$apcontact['statuses_count'] = $outbox['totalItems'];
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,8 +22,6 @@
|
||||||
namespace Friendica\Protocol;
|
namespace Friendica\Protocol;
|
||||||
|
|
||||||
use Friendica\Core\Protocol;
|
use Friendica\Core\Protocol;
|
||||||
use Friendica\Database\DBA;
|
|
||||||
use Friendica\DI;
|
|
||||||
use Friendica\Model\APContact;
|
use Friendica\Model\APContact;
|
||||||
use Friendica\Model\User;
|
use Friendica\Model\User;
|
||||||
use Friendica\Util\HTTPSignature;
|
use Friendica\Util\HTTPSignature;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user