mirror of
https://github.com/friendica/friendica
synced 2025-04-25 10:30:12 +00:00
Merge remote-tracking branch 'upstream/2022.09-rc' into duplicates
This commit is contained in:
commit
36668dfdb1
15 changed files with 276 additions and 580 deletions
|
@ -277,7 +277,7 @@ class Contact
|
|||
// 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;
|
||||
|
@ -307,9 +307,8 @@ class Contact
|
|||
}
|
||||
|
||||
// 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' => PRIORITY_LOW, 'dont_fork' => true], 'UpdateContact', $contact['id']);
|
||||
}
|
||||
|
||||
// Remove the internal fields
|
||||
|
@ -962,7 +961,6 @@ class Contact
|
|||
|
||||
DI::cache()->delete(ActivityPub\Transmitter::CACHEKEY_CONTACTS . 'followers:' . $uid);
|
||||
DI::cache()->delete(ActivityPub\Transmitter::CACHEKEY_CONTACTS . 'following:' . $uid);
|
||||
DI::cache()->delete(NoScrape::CACHEKEY . $uid);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1221,11 +1219,15 @@ class Contact
|
|||
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' => 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;
|
||||
|
@ -2524,7 +2526,7 @@ class Contact
|
|||
|
||||
$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;
|
||||
|
@ -3382,12 +3384,12 @@ class Contact
|
|||
if (empty($url) || !is_string($url)) {
|
||||
continue;
|
||||
}
|
||||
$contact = self::getByURL($url, false, ['id', 'updated']);
|
||||
$contact = self::getByURL($url, false, ['id', 'network', 'next-update']);
|
||||
if (empty($contact['id']) && Network::isValidHttpUrl($url)) {
|
||||
Worker::add(PRIORITY_LOW, 'AddContact', 0, $url);
|
||||
++$added;
|
||||
} elseif ($contact['updated'] < DateTimeFormat::utc('now -7 days')) {
|
||||
Worker::add(PRIORITY_LOW, 'UpdateContact', $contact['id']);
|
||||
} elseif (Probe::isProbable($contact['network']) && ($contact['next-update'] < DateTimeFormat::utcNow())) {
|
||||
Worker::add(['priority' => PRIORITY_LOW, 'dont_fork' => true], 'UpdateContact', $contact['id']);
|
||||
++$updated;
|
||||
} else {
|
||||
++$unchanged;
|
||||
|
|
|
@ -23,6 +23,7 @@ namespace Friendica\Model;
|
|||
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\Protocol;
|
||||
use Friendica\Core\Worker;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Network\Probe;
|
||||
|
@ -43,6 +44,7 @@ class FContact
|
|||
*/
|
||||
public static function getByURL(string $handle, $update = null): array
|
||||
{
|
||||
Logger::debug('Fetch fcontact', ['handle' => $handle, 'update' => $update]);
|
||||
$person = DBA::selectFirst('fcontact', [], ['network' => Protocol::DIASPORA, 'addr' => $handle]);
|
||||
if (!DBA::isResult($person)) {
|
||||
$urls = [$handle, str_replace('http://', 'https://', $handle), Strings::normaliseLink($handle)];
|
||||
|
@ -50,21 +52,17 @@ class FContact
|
|||
}
|
||||
|
||||
if (DBA::isResult($person)) {
|
||||
Logger::debug('In cache', ['person' => $person]);
|
||||
Logger::debug('In cache', ['handle' => $handle]);
|
||||
|
||||
if (is_null($update)) {
|
||||
// update record occasionally so it doesn't get stale
|
||||
$d = strtotime($person['updated'] . ' +00:00');
|
||||
if ($d < strtotime('now - 14 days')) {
|
||||
$update = true;
|
||||
}
|
||||
|
||||
if (empty($person['guid']) || empty($person['uri-id'])) {
|
||||
$update = true;
|
||||
$update = empty($person['guid']) || empty($person['uri-id']) || ($person['created'] <= DBA::NULL_DATETIME);
|
||||
if (GServer::getNextUpdateDate(true, $person['created'], $person['updated'], false) < DateTimeFormat::utcNow()) {
|
||||
Logger::debug('Start background update', ['handle' => $handle]);
|
||||
Worker::add(['priority' => PRIORITY_LOW, 'dont_fork' => true], 'UpdateFContact', $handle);
|
||||
}
|
||||
}
|
||||
} elseif (is_null($update)) {
|
||||
$update = !DBA::isResult($person);
|
||||
$update = true;
|
||||
} else {
|
||||
$person = [];
|
||||
}
|
||||
|
@ -95,7 +93,8 @@ class FContact
|
|||
{
|
||||
$uriid = ItemURI::insert(['uri' => $arr['url'], 'guid' => $arr['guid']]);
|
||||
|
||||
$contact = Contact::getByUriId($uriid, ['id']);
|
||||
$fcontact = DBA::selectFirst('fcontact', ['created'], ['url' => $arr['url'], 'network' => $arr['network']]);
|
||||
$contact = Contact::getByUriId($uriid, ['id', 'created']);
|
||||
$apcontact = APContact::getByURL($arr['url'], false);
|
||||
if (!empty($apcontact)) {
|
||||
$interacted = $apcontact['following_count'];
|
||||
|
@ -129,10 +128,14 @@ class FContact
|
|||
'updated' => DateTimeFormat::utcNow(),
|
||||
];
|
||||
|
||||
$condition = ['url' => $arr['url'], 'network' => $arr['network']];
|
||||
if (empty($fcontact['created'])) {
|
||||
$fields['created'] = $fields['updated'];
|
||||
} elseif (!empty($contact['created']) && ($fcontact['created'] <= DBA::NULL_DATETIME)) {
|
||||
$fields['created'] = $contact['created'];
|
||||
}
|
||||
|
||||
$fields = DI::dbaDefinition()->truncateFieldsForTable('fcontact', $fields);
|
||||
DBA::update('fcontact', $fields, $condition, true);
|
||||
DBA::update('fcontact', $fields, ['url' => $arr['url'], 'network' => $arr['network']], true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1870,23 +1870,40 @@ class Item
|
|||
return '';
|
||||
}
|
||||
|
||||
// Convert attachments to links
|
||||
$naked_body = BBCode::removeAttachment($item['body']);
|
||||
if (empty($naked_body)) {
|
||||
$languages = self::getLanguageArray(trim($item['title'] . "\n" . $item['body']), 3);
|
||||
if (empty($languages)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return json_encode($languages);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a language array from a given text
|
||||
*
|
||||
* @param string $body
|
||||
* @param integer $count
|
||||
* @return array
|
||||
*/
|
||||
public static function getLanguageArray(string $body, int $count): array
|
||||
{
|
||||
// Convert attachments to links
|
||||
$naked_body = BBCode::removeAttachment($body);
|
||||
if (empty($naked_body)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// Remove links and pictures
|
||||
$naked_body = BBCode::removeLinks($naked_body);
|
||||
|
||||
// Convert the title and the body to plain text
|
||||
$naked_body = trim($item['title'] . "\n" . BBCode::toPlaintext($naked_body));
|
||||
$naked_body = BBCode::toPlaintext($naked_body);
|
||||
|
||||
// Remove possibly remaining links
|
||||
$naked_body = preg_replace(Strings::autoLinkRegEx(), '', $naked_body);
|
||||
|
||||
if (empty($naked_body)) {
|
||||
return '';
|
||||
return [];
|
||||
}
|
||||
|
||||
$naked_body = self::getDominantLanguage($naked_body);
|
||||
|
@ -1898,12 +1915,7 @@ class Item
|
|||
$availableLanguages['fa'] = 'fa';
|
||||
|
||||
$ld = new Language(array_keys($availableLanguages));
|
||||
$languages = $ld->detect($naked_body)->limit(0, 3)->close();
|
||||
if (is_array($languages)) {
|
||||
return json_encode($languages);
|
||||
}
|
||||
|
||||
return '';
|
||||
return $ld->detect($naked_body)->limit(0, $count)->close() ?: [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue