- // load current friends if possible.
- if (($contact['poco'] != "") && ($contact['success_update'] > $contact['failure_update'])) {
- $r = q("SELECT count(*) AS total FROM glink
- WHERE `cid` = %d AND updated > UTC_TIMESTAMP() - INTERVAL 1 DAY",
- intval($contact['id'])
- );
- if (DBA::is_result($r)) {
- if (!$r[0]['total']) {
- PortableContact::loadWorker($contact['id'], $importer_uid, 0, $contact['poco']);
- }
+ // Possibly switch the remote contact to AP
+ if ($contact['network'] === Protocol::OSTATUS) {
+ ActivityPub\Receiver::switchContact($contact['id'], $importer_uid, $contact['url']);
+ $contact = DBA::selectFirst('contact', [], ['id' => $contact_id]);
+ }
+
+ // These three networks can be able to speak AP, so we are trying to fetch AP profile data here
+ if (in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DIASPORA, Protocol::DFRN])) {
+ $apcontact = APContact::getByURL($contact['url'], true);
+
+ $updated = DateTimeFormat::utcNow();
+ if (($contact['network'] === Protocol::ACTIVITYPUB) && empty($apcontact)) {
+ self::updateContact($contact, ['last-update' => $updated, 'failure_update' => $updated]);
+ Contact::markForArchival($contact);
+ Logger::log('Contact archived');
+ return;
+ } elseif (!empty($apcontact)) {
+ $fields = ['last-update' => $updated, 'success_update' => $updated];
+ self::updateContact($contact, $fields);
+ Contact::unmarkForArchival($contact);