use Friendica\Network\Probe;
use Friendica\Protocol\ActivityNamespace;
use Friendica\Protocol\ActivityPub;
+use Friendica\Protocol\ActivityPub\Transmitter;
use Friendica\Util\Crypto;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\HTTPSignature;
use Friendica\Util\JsonLD;
use Friendica\Util\Network;
+use Friendica\Util\Strings;
class APContact
{
DI::cache()->set($cachekey, System::callstack(20), Duration::FIVE_MINUTES);
}
- $curlResult = HTTPSignature::fetchRaw($url);
- $failed = empty($curlResult) || empty($curlResult->getBody()) ||
- (!$curlResult->isSuccess() && ($curlResult->getReturnCode() != 410));
-
- if (!$failed) {
- $data = json_decode($curlResult->getBody(), true);
- $failed = empty($data) || !is_array($data);
+ if (Network::isLocalLink($url) && ($local_uid = User::getIdForURL($url))) {
+ $data = Transmitter::getProfile($local_uid);
+ $local_owner = User::getOwnerDataById($local_uid);
}
- if (!$failed && ($curlResult->getReturnCode() == 410)) {
- $data = ['@context' => ActivityPub::CONTEXT, 'id' => $url, 'type' => 'Tombstone'];
- }
+ if (empty($data)) {
+ $local_owner = [];
- if ($failed) {
- self::markForArchival($fetched_contact ?: []);
- return $fetched_contact;
+ $curlResult = HTTPSignature::fetchRaw($url);
+ $failed = empty($curlResult) || empty($curlResult->getBody()) ||
+ (!$curlResult->isSuccess() && ($curlResult->getReturnCode() != 410));
+
+ if (!$failed) {
+ $data = json_decode($curlResult->getBody(), true);
+ $failed = empty($data) || !is_array($data);
+ }
+
+ if (!$failed && ($curlResult->getReturnCode() == 410)) {
+ $data = ['@context' => ActivityPub::CONTEXT, 'id' => $url, 'type' => 'Tombstone'];
+ }
+
+ if ($failed) {
+ self::markForArchival($fetched_contact ?: []);
+ return $fetched_contact;
+ }
}
$compacted = JsonLD::compact($data);
}
if (!empty($apcontact['following'])) {
- $following = ActivityPub::fetchContent($apcontact['following']);
+ if (!empty($local_owner)) {
+ $following = ActivityPub\Transmitter::getContacts($local_owner, [Contact::SHARING, Contact::FRIEND], 'following');
+ } else {
+ $following = ActivityPub::fetchContent($apcontact['following']);
+ }
if (!empty($following['totalItems'])) {
// Mastodon seriously allows for this condition?
// Jul 14 2021 - See https://mastodon.social/@BLUW for a negative following count
}
if (!empty($apcontact['followers'])) {
- $followers = ActivityPub::fetchContent($apcontact['followers']);
+ if (!empty($local_owner)) {
+ $followers = ActivityPub\Transmitter::getContacts($local_owner, [Contact::FOLLOWER, Contact::FRIEND], 'followers');
+ } else {
+ $followers = ActivityPub::fetchContent($apcontact['followers']);
+ }
if (!empty($followers['totalItems'])) {
// Mastodon seriously allows for this condition?
// Jul 14 2021 - See https://mastodon.online/@goes11 for a negative followers count
}
if (!empty($apcontact['outbox'])) {
- $outbox = ActivityPub::fetchContent($apcontact['outbox']);
+ if (!empty($local_owner)) {
+ $outbox = ActivityPub\Transmitter::getOutbox($local_owner);
+ } else {
+ $outbox = ActivityPub::fetchContent($apcontact['outbox']);
+ }
if (!empty($outbox['totalItems'])) {
$apcontact['statuses_count'] = $outbox['totalItems'];
}