use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
-use Friendica\Core\Session;
use Friendica\Core\System;
use Friendica\Core\Worker;
use Friendica\Database\Database;
use Friendica\Database\DBA;
use Friendica\DI;
-use Friendica\Module\NoScrape;
use Friendica\Network\HTTPException;
use Friendica\Network\Probe;
use Friendica\Protocol\Activity;
return $contact;
}
+ /**
+ * @param array $fields Array of selected fields, empty for all
+ * @param array $condition Array of fields for condition
+ * @param array $params Array of several parameters
+ * @return array|bool
+ * @throws \Exception
+ */
+ public static function selectFirstAccount(array $fields = [], array $condition = [], array $params = [])
+ {
+ return DBA::selectFirst('account-view', $fields, $condition, $params);
+ }
+
/**
* Insert a row into the contact table
* Important: You can't use DBA::lastInsertId() after this call since it will be set to 0.
return 0;
}
- Contact\User::insertForContactArray($contact);
-
- // Search for duplicated contacts and get rid of them
- if (!$contact['self']) {
- self::removeDuplicates($contact['nurl'], $contact['uid']);
+ $fields = DI::dbaDefinition()->truncateFieldsForTable('account-user', $contact);
+ DBA::insert('account-user', $fields, Database::INSERT_IGNORE);
+ $account_user = DBA::selectFirst('account-user', ['id'], ['uid' => $contact['uid'], 'uri-id' => $contact['uri-id']]);
+ if (empty($account_user['id'])) {
+ Logger::warning('Account-user entry not found', ['cid' => $contact['id'], 'uid' => $contact['uid'], 'uri-id' => $contact['uri-id'], 'url' => $contact['url']]);
+ } elseif ($account_user['id'] != $contact['id']) {
+ $duplicate = DBA::selectFirst('contact', [], ['id' => $account_user['id'], 'deleted' => false]);
+ if (!empty($duplicate['id'])) {
+ $ret = Contact::deleteById($contact['id']);
+ Logger::notice('Deleted duplicated contact', ['ret' => $ret, 'account-user' => $account_user, 'cid' => $duplicate['id'], 'uid' => $duplicate['uid'], 'uri-id' => $duplicate['uri-id'], 'url' => $duplicate['url']]);
+ $contact = $duplicate;
+ } else {
+ $ret = DBA::update('account-user', ['id' => $contact['id']], ['uid' => $contact['uid'], 'uri-id' => $contact['uri-id']]);
+ Logger::notice('Updated account-user', ['ret' => $ret, 'account-user' => $account_user, 'cid' => $contact['id'], 'uid' => $contact['uid'], 'uri-id' => $contact['uri-id'], 'url' => $contact['url']]);
+ }
}
+ Contact\User::insertForContactArray($contact);
+
return $contact['id'];
}
+ /**
+ * Delete contact by id
+ *
+ * @param integer $id
+ * @return boolean
+ */
+ public static function deleteById(int $id): bool
+ {
+ Logger::debug('Delete contact', ['id' => $id]);
+ DBA::delete('account-user', ['id' => $id]);
+ return DBA::delete('contact', ['id' => $id]);
+ }
+
/**
* Updates rows in the contact table
*
return DBA::selectFirst('contact', $fields, ['uri-id' => $uri_id], ['order' => ['uid']]);
}
+ /**
+ * Fetch all remote contacts for a given contact url
+ *
+ * @param string $url The URL of the contact
+ * @param array $fields The wanted fields
+ *
+ * @return array all remote contacts
+ *
+ * @throws \Exception
+ */
+ public static function getVisitorByUrl(string $url, array $fields = ['id', 'uid']): array
+ {
+ $remote = [];
+
+ $remote_contacts = DBA::select('contact', ['id', 'uid'], ['nurl' => Strings::normaliseLink($url), 'rel' => [Contact::FOLLOWER, Contact::FRIEND], 'self' => false]);
+ while ($contact = DBA::fetch($remote_contacts)) {
+ if (($contact['uid'] == 0) || Contact\User::isBlocked($contact['id'], $contact['uid'])) {
+ continue;
+ }
+ $remote[$contact['uid']] = $contact['id'];
+ }
+ DBA::close($remote_contacts);
+
+ return $remote;
+ }
+
/**
* Fetches a contact by a given url
*
// Add internal fields
$removal = [];
if (!empty($fields)) {
- foreach (['id', 'avatar', 'created', 'updated', 'last-update', 'success_update', 'failure_update', 'network'] as $internal) {
+ foreach (['id', 'next-update', 'network'] as $internal) {
if (!in_array($internal, $fields)) {
$fields[] = $internal;
$removal[] = $internal;
}
// Update the contact in the background if needed
- $updated = max($contact['success_update'], $contact['created'], $contact['updated'], $contact['last-update'], $contact['failure_update']);
- if (($updated < DateTimeFormat::utc('now -7 days')) && in_array($contact['network'], Protocol::FEDERATED) && !self::isLocalById($contact['id'])) {
- Worker::add(PRIORITY_LOW, "UpdateContact", $contact['id']);
+ if (Probe::isProbable($contact['network']) && ($contact['next-update'] < DateTimeFormat::utcNow())) {
+ Worker::add(['priority' => Worker::PRIORITY_LOW, 'dont_fork' => true], 'UpdateContact', $contact['id']);
}
// Remove the internal fields
return $contact;
}
+ /**
+ * Checks if a contact uses a specific platform
+ *
+ * @param string $url
+ * @param string $platform
+ * @return boolean
+ */
+ public static function isPlatform(string $url, string $platform): bool
+ {
+ return DBA::exists('account-view', ['nurl' => Strings::normaliseLink($url), 'platform' => $platform]);
+ }
+
/**
* Tests if the given contact is a follower
*
return;
}
+ DBA::delete('account-user', ['id' => $id]);
+
self::clearFollowerFollowingEndpointCache($contact['uid']);
// Archive the contact
}
// Delete it in the background
- Worker::add(PRIORITY_MEDIUM, 'Contact\Remove', $id);
+ Worker::add(Worker::PRIORITY_MEDIUM, 'Contact\Remove', $id);
}
/**
if (in_array($contact['rel'], [self::SHARING, self::FRIEND])) {
$cdata = self::getPublicAndUserContactID($contact['id'], $contact['uid']);
if (!empty($cdata['public'])) {
- Worker::add(PRIORITY_HIGH, 'Contact\Unfollow', $cdata['public'], $contact['uid']);
+ Worker::add(Worker::PRIORITY_HIGH, 'Contact\Unfollow', $cdata['public'], $contact['uid']);
}
}
if (in_array($contact['rel'], [self::FOLLOWER, self::FRIEND])) {
$cdata = self::getPublicAndUserContactID($contact['id'], $contact['uid']);
if (!empty($cdata['public'])) {
- Worker::add(PRIORITY_HIGH, 'Contact\RevokeFollow', $cdata['public'], $contact['uid']);
+ Worker::add(Worker::PRIORITY_HIGH, 'Contact\RevokeFollow', $cdata['public'], $contact['uid']);
}
}
$cdata = self::getPublicAndUserContactID($contact['id'], $contact['uid']);
if (in_array($contact['rel'], [self::SHARING, self::FRIEND]) && !empty($cdata['public'])) {
- Worker::add(PRIORITY_HIGH, 'Contact\Unfollow', $cdata['public'], $contact['uid']);
+ Worker::add(Worker::PRIORITY_HIGH, 'Contact\Unfollow', $cdata['public'], $contact['uid']);
}
if (in_array($contact['rel'], [self::FOLLOWER, self::FRIEND]) && !empty($cdata['public'])) {
- Worker::add(PRIORITY_HIGH, 'Contact\RevokeFollow', $cdata['public'], $contact['uid']);
+ Worker::add(Worker::PRIORITY_HIGH, 'Contact\RevokeFollow', $cdata['public'], $contact['uid']);
}
self::remove($contact['id']);
DI::cache()->delete(ActivityPub\Transmitter::CACHEKEY_CONTACTS . 'followers:' . $uid);
DI::cache()->delete(ActivityPub\Transmitter::CACHEKEY_CONTACTS . 'following:' . $uid);
- DI::cache()->delete(NoScrape::CACHEKEY . $uid);
}
/**
$photos_link = '';
if ($uid == 0) {
- $uid = local_user();
+ $uid = DI::userSession()->getLocalUserId();
}
if (empty($contact['uid']) || ($contact['uid'] != $uid)) {
return 0;
}
- $contact = self::getByURL($url, false, ['id', 'network', 'uri-id'], $uid);
+ $contact = self::getByURL($url, false, ['id', 'network', 'uri-id', 'next-update'], $uid);
if (!empty($contact)) {
$contact_id = $contact['id'];
+ if (Probe::isProbable($contact['network']) && ($contact['next-update'] < DateTimeFormat::utcNow())) {
+ Worker::add(['priority' => Worker::PRIORITY_LOW, 'dont_fork' => true], 'UpdateContact', $contact['id']);
+ }
+
if (empty($update) && (!empty($contact['uri-id']) || is_bool($update))) {
Logger::debug('Contact found', ['url' => $url, 'uid' => $uid, 'update' => $update, 'cid' => $contact_id]);
return $contact_id;
return 0;
}
+ if (!$contact_id && !empty($data['account-type']) && $data['account-type'] == User::ACCOUNT_TYPE_DELETED) {
+ Logger::info('Contact is a tombstone. It will not be inserted', ['url' => $url, 'uid' => $uid]);
+ return 0;
+ }
+
if (!$contact_id) {
$urls = [Strings::normaliseLink($url), Strings::normaliseLink($data['url'])];
if (!empty($data['alias'])) {
$condition = ['nurl' => Strings::normaliseLink($data["url"]), 'uid' => $uid, 'deleted' => false];
// Before inserting we do check if the entry does exist now.
- if (DI::lock()->acquire(self::LOCK_INSERT, 0)) {
- $contact = DBA::selectFirst('contact', ['id'], $condition, ['order' => ['id']]);
- if (DBA::isResult($contact)) {
- $contact_id = $contact['id'];
- Logger::notice('Contact had been created (shortly) before', ['id' => $contact_id, 'url' => $url, 'uid' => $uid]);
- } else {
- $contact_id = self::insert($fields);
- if ($contact_id) {
- Logger::info('Contact inserted', ['id' => $contact_id, 'url' => $url, 'uid' => $uid]);
- }
- }
- DI::lock()->release(self::LOCK_INSERT);
+ $contact = DBA::selectFirst('contact', ['id'], $condition, ['order' => ['id']]);
+ if (DBA::isResult($contact)) {
+ $contact_id = $contact['id'];
+ Logger::notice('Contact had been created (shortly) before', ['id' => $contact_id, 'url' => $url, 'uid' => $uid]);
} else {
- Logger::warning('Contact lock had not been acquired');
+ $contact_id = self::insert($fields);
+ if ($contact_id) {
+ Logger::info('Contact inserted', ['id' => $contact_id, 'url' => $url, 'uid' => $uid]);
+ }
}
if (!$contact_id) {
- Logger::info('Contact was not inserted', ['url' => $url, 'uid' => $uid]);
+ Logger::warning('Contact was not inserted', ['url' => $url, 'uid' => $uid]);
return 0;
}
} else {
$contact_field = ((($contact["contact-type"] == self::TYPE_COMMUNITY) || ($contact['network'] == Protocol::MAIL)) ? 'owner-id' : 'author-id');
if ($thread_mode) {
- $condition = ["((`$contact_field` = ? AND `gravity` = ?) OR (`author-id` = ? AND `gravity` = ? AND `vid` = ?)) AND " . $sql,
- $cid, GRAVITY_PARENT, $cid, GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE), local_user()];
+ $condition = ["((`$contact_field` = ? AND `gravity` = ?) OR (`author-id` = ? AND `gravity` = ? AND `vid` = ? AND `thr-parent-id` = `parent-uri-id`)) AND " . $sql,
+ $cid, Item::GRAVITY_PARENT, $cid, Item::GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE), DI::userSession()->getLocalUserId()];
} else {
$condition = ["`$contact_field` = ? AND `gravity` IN (?, ?) AND " . $sql,
- $cid, GRAVITY_PARENT, GRAVITY_COMMENT, local_user()];
+ $cid, Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT, DI::userSession()->getLocalUserId()];
}
if (!empty($parent)) {
}
if (DI::mode()->isMobile()) {
- $itemsPerPage = DI::pConfig()->get(local_user(), 'system', 'itemspage_mobile_network',
+ $itemsPerPage = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'itemspage_mobile_network',
DI::config()->get('system', 'itemspage_network_mobile'));
} else {
- $itemsPerPage = DI::pConfig()->get(local_user(), 'system', 'itemspage_network',
+ $itemsPerPage = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'itemspage_network',
DI::config()->get('system', 'itemspage_network'));
}
$params = ['order' => ['received' => true], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
- if (DI::pConfig()->get(local_user(), 'system', 'infinite_scroll')) {
+ if (DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'infinite_scroll')) {
$tpl = Renderer::getMarkupTemplate('infinite_scroll_head.tpl');
$o = Renderer::replaceMacros($tpl, ['$reload_uri' => DI::args()->getQueryString()]);
} else {
if ($thread_mode) {
$fields = ['uri-id', 'thr-parent-id', 'gravity', 'author-id', 'commented'];
- $items = Post::toArray(Post::selectForUser(local_user(), $fields, $condition, $params));
+ $items = Post::toArray(Post::selectForUser(DI::userSession()->getLocalUserId(), $fields, $condition, $params));
if ($pager->getStart() == 0) {
- $cdata = self::getPublicAndUserContactID($cid, local_user());
+ $cdata = self::getPublicAndUserContactID($cid, DI::userSession()->getLocalUserId());
if (!empty($cdata['public'])) {
$pinned = Post\Collection::selectToArrayForContact($cdata['public'], Post\Collection::FEATURED, $fields);
$items = array_merge($items, $pinned);
}
}
- $o .= DI::conversation()->create($items, 'contacts', $update, false, 'pinned_commented', local_user());
+ $o .= DI::conversation()->create($items, 'contacts', $update, false, 'pinned_commented', DI::userSession()->getLocalUserId());
} else {
$fields = array_merge(Item::DISPLAY_FIELDLIST, ['featured']);
- $items = Post::toArray(Post::selectForUser(local_user(), $fields, $condition, $params));
+ $items = Post::toArray(Post::selectForUser(DI::userSession()->getLocalUserId(), $fields, $condition, $params));
if ($pager->getStart() == 0) {
- $cdata = self::getPublicAndUserContactID($cid, local_user());
+ $cdata = self::getPublicAndUserContactID($cid, DI::userSession()->getLocalUserId());
if (!empty($cdata['public'])) {
$condition = ["`uri-id` IN (SELECT `uri-id` FROM `collection-view` WHERE `cid` = ? AND `type` = ?)",
$cdata['public'], Post\Collection::FEATURED];
- $pinned = Post::toArray(Post::selectForUser(local_user(), $fields, $condition, $params));
+ $pinned = Post::toArray(Post::selectForUser(DI::userSession()->getLocalUserId(), $fields, $condition, $params));
$items = array_merge($pinned, $items);
}
}
}
if (!$update) {
- if (DI::pConfig()->get(local_user(), 'system', 'infinite_scroll')) {
+ if (DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'infinite_scroll')) {
$o .= HTML::scrollLoader();
} else {
$o .= $pager->renderMinimal(count($items));
/**
* Return the photo path for a given contact array in the given size
*
- * @param array $contact contact array
- * @param string $field Fieldname of the photo in the contact array
+ * @param array $contact contact array
* @param string $size Size of the avatar picture
- * @param string $avatar Avatar path that is displayed when no photo had been found
- * @param bool $no_update Don't perfom an update if no cached avatar was found
+ * @param bool $no_update Don't perfom an update if no cached avatar was found
* @return string photo path
*/
private static function getAvatarPath(array $contact, string $size, bool $no_update = false): string
}
}
- return self::getAvatarUrlForId($contact['id'], $size, $contact['updated'] ?? '');
+ return self::getAvatarUrlForId($contact['id'] ?? 0, $size, $contact['updated'] ?? '');
}
/**
/**
* Helper function for "updateFromProbe". Updates personal and public contact
*
- * @param integer $id contact id
- * @param integer $uid user id
- * @param string $old_url The previous profile URL of the contact
- * @param string $new_url The profile URL of the contact
- * @param array $fields The fields that are updated
+ * @param integer $id contact id
+ * @param integer $uid user id
+ * @param integer $uri_id Uri-Id
+ * @param string $url The profile URL of the contact
+ * @param array $fields The fields that are updated
*
* @throws \Exception
*/
- private static function updateContact(int $id, int $uid, string $old_url, string $new_url, array $fields)
+ private static function updateContact(int $id, int $uid, int $uri_id, string $url, array $fields)
{
if (!self::update($fields, ['id' => $id])) {
Logger::info('Couldn\'t update contact.', ['id' => $id, 'fields' => $fields]);
return;
}
- // Search for duplicated contacts and get rid of them
- if (self::removeDuplicates(Strings::normaliseLink($new_url), $uid)) {
- return;
- }
+ self::setAccountUser($id, $uid, $uri_id, $url);
// Archive or unarchive the contact.
$contact = DBA::selectFirst('contact', [], ['id' => $id]);
}
// Update contact data for all users
- $condition = ['self' => false, 'nurl' => Strings::normaliseLink($old_url)];
+ $condition = ['self' => false, 'nurl' => Strings::normaliseLink($url)];
$condition['network'] = [Protocol::DFRN, Protocol::DIASPORA, Protocol::ACTIVITYPUB];
self::update($fields, $condition);
self::update($fields, $condition);
}
+ /**
+ * Create or update an "account-user" entry
+ *
+ * @param integer $id
+ * @param integer $uid
+ * @param integer $uri_id
+ * @param string $url
+ * @return void
+ */
+ public static function setAccountUser(int $id, int $uid, int $uri_id, string $url)
+ {
+ if (empty($uri_id)) {
+ return;
+ }
+
+ $account_user = DBA::selectFirst('account-user', ['id', 'uid', 'uri-id'], ['id' => $id]);
+ if (!empty($account_user['uri-id']) && ($account_user['uri-id'] != $uri_id)) {
+ if ($account_user['uid'] == $uid) {
+ $ret = DBA::update('account-user', ['uri-id' => $uri_id], ['id' => $id]);
+ Logger::notice('Updated account-user uri-id', ['ret' => $ret, 'account-user' => $account_user, 'cid' => $id, 'uid' => $uid, 'uri-id' => $uri_id, 'url' => $url]);
+ } else {
+ // This should never happen
+ Logger::warning('account-user exists for a different uri-id and uid', ['account_user' => $account_user, 'id' => $id, 'uid' => $uid, 'uri-id' => $uri_id, 'url' => $url]);
+ }
+ }
+
+ $account_user = DBA::selectFirst('account-user', ['id', 'uid', 'uri-id'], ['uid' => $uid, 'uri-id' => $uri_id]);
+ if (!empty($account_user['id'])) {
+ if ($account_user['id'] == $id) {
+ Logger::debug('account-user already exists', ['id' => $id, 'uid' => $uid, 'uri-id' => $uri_id, 'url' => $url]);
+ return;
+ } elseif (!DBA::exists('contact', ['id' => $account_user['id'], 'deleted' => false])) {
+ $ret = DBA::update('account-user', ['id' => $id], ['uid' => $uid, 'uri-id' => $uri_id]);
+ Logger::notice('Updated account-user', ['ret' => $ret, 'account-user' => $account_user, 'cid' => $id, 'uid' => $uid, 'uri-id' => $uri_id, 'url' => $url]);
+ return;
+ }
+ Logger::warning('account-user exists for a different contact id', ['account_user' => $account_user, 'id' => $id, 'uid' => $uid, 'uri-id' => $uri_id, 'url' => $url]);
+ Worker::add(Worker::PRIORITY_HIGH, 'MergeContact', $account_user['id'], $id, $uid);
+ } elseif (DBA::insert('account-user', ['id' => $id, 'uri-id' => $uri_id, 'uid' => $uid], Database::INSERT_IGNORE)) {
+ Logger::notice('account-user was added', ['id' => $id, 'uid' => $uid, 'uri-id' => $uri_id, 'url' => $url]);
+ } else {
+ Logger::warning('account-user was not added', ['id' => $id, 'uid' => $uid, 'uri-id' => $uri_id, 'url' => $url]);
+ }
+ }
+
/**
* Remove duplicated contacts
*
$first = $first_contact['id'];
Logger::info('Found duplicates', ['count' => $count, 'first' => $first, 'uid' => $uid, 'nurl' => $nurl]);
- if (($uid != 0 && ($first_contact['network'] == Protocol::DFRN))) {
- // Don't handle non public DFRN duplicates by now (legacy DFRN is very special because of the key handling)
- Logger::info('Not handling non public DFRN duplicate', ['uid' => $uid, 'nurl' => $nurl]);
- return false;
- }
// Find all duplicates
$condition = ["`nurl` = ? AND `uid` = ? AND `id` != ? AND NOT `self` AND NOT `deleted`", $nurl, $uid, $first];
continue;
}
- Worker::add(PRIORITY_HIGH, 'MergeContact', $first, $duplicate['id'], $uid);
+ Worker::add(Worker::PRIORITY_HIGH, 'MergeContact', $first, $duplicate['id'], $uid);
}
DBA::close($duplicates);
Logger::info('Duplicates handled', ['uid' => $uid, 'nurl' => $nurl, 'callstack' => System::callstack(20)]);
$has_local_data = self::hasLocalData($id, $contact);
- if (!in_array($ret['network'], array_merge(Protocol::FEDERATED, [Protocol::ZOT, Protocol::PHANTOM]))) {
+ if (!Probe::isProbable($ret['network'])) {
// Periodical checks are only done on federated contacts
$failed_next_update = null;
$success_next_update = null;
if (Strings::normaliseLink($contact['url']) != Strings::normaliseLink($ret['url'])) {
Logger::notice('New URL differs from old URL', ['id' => $id, 'uid' => $uid, 'old' => $contact['url'], 'new' => $ret['url']]);
- self::updateContact($id, $uid, $contact['url'], $ret['url'], ['failed' => true, 'local-data' => $has_local_data, 'last-update' => $updated, 'next-update' => $failed_next_update, 'failure_update' => $updated]);
+ self::updateContact($id, $uid, $uriid, $contact['url'], ['failed' => true, 'local-data' => $has_local_data, 'last-update' => $updated, 'next-update' => $failed_next_update, 'failure_update' => $updated]);
return false;
}
// We check after the probing to be able to correct falsely detected contact types.
if (($contact['contact-type'] == self::TYPE_RELAY) &&
(!Strings::compareLink($ret['url'], $contact['url']) || in_array($ret['network'], [Protocol::FEED, Protocol::PHANTOM]))) {
- self::updateContact($id, $uid, $contact['url'], $contact['url'], ['failed' => false, 'local-data' => $has_local_data, 'last-update' => $updated, 'next-update' => $success_next_update, 'success_update' => $updated]);
+ self::updateContact($id, $uid, $uriid, $contact['url'], ['failed' => false, 'local-data' => $has_local_data, 'last-update' => $updated, 'next-update' => $success_next_update, 'success_update' => $updated]);
Logger::info('Not updating relais', ['id' => $id, 'url' => $contact['url']]);
return true;
}
// If Probe::uri fails the network code will be different ("feed" or "unkn")
if (($ret['network'] == Protocol::PHANTOM) || (($ret['network'] == Protocol::FEED) && ($ret['network'] != $contact['network']))) {
- self::updateContact($id, $uid, $contact['url'], $ret['url'], ['failed' => true, 'local-data' => $has_local_data, 'last-update' => $updated, 'next-update' => $failed_next_update, 'failure_update' => $updated]);
+ self::updateContact($id, $uid, $uriid, $contact['url'], ['failed' => true, 'local-data' => $has_local_data, 'last-update' => $updated, 'next-update' => $failed_next_update, 'failure_update' => $updated]);
return false;
}
if ($ret['network'] == Protocol::ACTIVITYPUB) {
$apcontact = APContact::getByURL($ret['url'], false);
if (!empty($apcontact['featured'])) {
- Worker::add(PRIORITY_LOW, 'FetchFeaturedPosts', $ret['url']);
+ Worker::add(Worker::PRIORITY_LOW, 'FetchFeaturedPosts', $ret['url']);
}
}
self::updateAvatar($id, $ret['photo'], $update);
}
- $uriid = ItemURI::insert(['uri' => $ret['url'], 'guid' => $guid]);
-
if (!$update) {
- self::updateContact($id, $uid, $contact['url'], $ret['url'], ['failed' => false, 'local-data' => $has_local_data, 'last-update' => $updated, 'next-update' => $success_next_update, 'success_update' => $updated]);
+ self::updateContact($id, $uid, $uriid, $contact['url'], ['failed' => false, 'local-data' => $has_local_data, 'last-update' => $updated, 'next-update' => $success_next_update, 'success_update' => $updated]);
if (Contact\Relation::isDiscoverable($ret['url'])) {
- Worker::add(PRIORITY_LOW, 'ContactDiscovery', $ret['url']);
+ Worker::add(Worker::PRIORITY_LOW, 'ContactDiscovery', $ret['url']);
}
// Update the public contact
return true;
}
- $ret['uri-id'] = $uriid;
+ $ret['uri-id'] = ItemURI::insert(['uri' => $ret['url'], 'guid' => $guid]);
$ret['nurl'] = Strings::normaliseLink($ret['url']);
$ret['updated'] = $updated;
$ret['failed'] = false;
unset($ret['photo']);
- self::updateContact($id, $uid, $contact['url'], $ret['url'], $ret);
+ self::updateContact($id, $uid, $ret['uri-id'], $ret['url'], $ret);
if (Contact\Relation::isDiscoverable($ret['url'])) {
- Worker::add(PRIORITY_LOW, 'ContactDiscovery', $ret['url']);
+ Worker::add(Worker::PRIORITY_LOW, 'ContactDiscovery', $ret['url']);
}
return true;
// do we have enough information?
if (empty($protocol) || ($protocol == Protocol::PHANTOM) || (empty($ret['url']) && empty($ret['addr']))) {
- $result['message'] .= DI::l10n()->t('The profile address specified does not provide adequate information.') . EOL;
+ $result['message'] .= DI::l10n()->t('The profile address specified does not provide adequate information.') . '<br />';
if (empty($ret['poll'])) {
- $result['message'] .= DI::l10n()->t('No compatible communication protocols or feeds were discovered.') . EOL;
+ $result['message'] .= DI::l10n()->t('No compatible communication protocols or feeds were discovered.') . '<br />';
}
if (empty($ret['name'])) {
- $result['message'] .= DI::l10n()->t('An author or name was not found.') . EOL;
+ $result['message'] .= DI::l10n()->t('An author or name was not found.') . '<br />';
}
if (empty($ret['url'])) {
- $result['message'] .= DI::l10n()->t('No browser URL could be matched to this address.') . EOL;
+ $result['message'] .= DI::l10n()->t('No browser URL could be matched to this address.') . '<br />';
}
if (strpos($ret['url'], '@') !== false) {
- $result['message'] .= DI::l10n()->t('Unable to match @-style Identity Address with a known protocol or email contact.') . EOL;
- $result['message'] .= DI::l10n()->t('Use mailto: in front of address to force email check.') . EOL;
+ $result['message'] .= DI::l10n()->t('Unable to match @-style Identity Address with a known protocol or email contact.') . '<br />';
+ $result['message'] .= DI::l10n()->t('Use mailto: in front of address to force email check.') . '<br />';
}
return $result;
}
if ($protocol === Protocol::OSTATUS && DI::config()->get('system', 'ostatus_disabled')) {
- $result['message'] .= DI::l10n()->t('The profile address specified belongs to a network which has been disabled on this site.') . EOL;
+ $result['message'] .= DI::l10n()->t('The profile address specified belongs to a network which has been disabled on this site.') . '<br />';
$ret['notify'] = '';
}
if (!$ret['notify']) {
- $result['message'] .= DI::l10n()->t('Limited profile. This person will be unable to receive direct/personal notifications from you.') . EOL;
+ $result['message'] .= DI::l10n()->t('Limited profile. This person will be unable to receive direct/personal notifications from you.') . '<br />';
}
$writeable = ((($protocol === Protocol::OSTATUS) && ($ret['notify'])) ? 1 : 0);
$contact = DBA::selectFirst('contact', [], ['url' => $ret['url'], 'network' => $ret['network'], 'uid' => $uid]);
if (!DBA::isResult($contact)) {
- $result['message'] .= DI::l10n()->t('Unable to retrieve contact information.') . EOL;
+ $result['message'] .= DI::l10n()->t('Unable to retrieve contact information.') . '<br />';
return $result;
}
// pull feed and consume it, which should subscribe to the hub.
if ($contact['network'] == Protocol::OSTATUS) {
- Worker::add(PRIORITY_HIGH, 'OnePoll', $contact_id, 'force');
+ Worker::add(Worker::PRIORITY_HIGH, 'OnePoll', $contact_id, 'force');
}
if ($probed) {
self::updateFromProbeArray($contact_id, $ret);
} else {
- Worker::add(PRIORITY_HIGH, 'UpdateContact', $contact_id);
+ Worker::add(Worker::PRIORITY_HIGH, 'UpdateContact', $contact_id);
}
$result['success'] = Protocol::follow($uid, $contact, $protocol);
*/
public static function magicLink(string $contact_url, string $url = ''): string
{
- if (!Session::isAuthenticated()) {
+ if (!DI::userSession()->isAuthenticated()) {
return $url ?: $contact_url; // Equivalent to: ($url != '') ? $url : $contact_url;
}
{
$destination = $url ?: $contact['url']; // Equivalent to ($url != '') ? $url : $contact['url'];
- if (!Session::isAuthenticated()) {
+ if (!DI::userSession()->isAuthenticated()) {
return $destination;
}
return $url;
}
- if (DI::pConfig()->get(local_user(), 'system', 'stay_local') && ($url == '')) {
+ if (DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'stay_local') && ($url == '')) {
return 'contact/' . $contact['id'] . '/conversations';
}
if (empty($url) || !is_string($url)) {
continue;
}
- $contact = self::getByURL($url, false, ['id', 'updated']);
- if (empty($contact['id'])) {
- Worker::add(PRIORITY_LOW, 'AddContact', 0, $url);
+ $contact = self::getByURL($url, false, ['id', 'network', 'next-update']);
+ if (empty($contact['id']) && Network::isValidHttpUrl($url)) {
+ Worker::add(Worker::PRIORITY_LOW, 'AddContact', 0, $url);
++$added;
- } elseif ($contact['updated'] < DateTimeFormat::utc('now -7 days')) {
- Worker::add(PRIORITY_LOW, 'UpdateContact', $contact['id']);
+ } elseif (!empty($contact['network']) && Probe::isProbable($contact['network']) && ($contact['next-update'] < DateTimeFormat::utcNow())) {
+ Worker::add(['priority' => Worker::PRIORITY_LOW, 'dont_fork' => true], 'UpdateContact', $contact['id']);
++$updated;
} else {
++$unchanged;