From a74c547af470947c3420157cba237c4951da58f4 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 3 Aug 2020 13:10:49 -0400 Subject: [PATCH] Move ContactRelation class to Contact\Relation - Update references in GContact --- src/Model/Contact.php | 2 +- .../Relation.php} | 4 ++-- src/Model/GContact.php | 23 ++++++++++++++----- src/Model/Item.php | 2 +- src/Module/Admin/Site.php | 10 ++++---- src/Worker/ContactDiscovery.php | 4 ++-- 6 files changed, 28 insertions(+), 17 deletions(-) rename src/Model/{ContactRelation.php => Contact/Relation.php} (99%) diff --git a/src/Model/Contact.php b/src/Model/Contact.php index b6b0fec5d..3bd826945 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -2124,7 +2124,7 @@ class Contact return false; } - if (ContactRelation::isDiscoverable($ret['url'])) { + if (Contact\Relation::isDiscoverable($ret['url'])) { Worker::add(PRIORITY_LOW, 'ContactDiscovery', $ret['url']); } diff --git a/src/Model/ContactRelation.php b/src/Model/Contact/Relation.php similarity index 99% rename from src/Model/ContactRelation.php rename to src/Model/Contact/Relation.php index 85dbc93b9..a98f2bfd9 100644 --- a/src/Model/ContactRelation.php +++ b/src/Model/Contact/Relation.php @@ -19,7 +19,7 @@ * */ -namespace Friendica\Model; +namespace Friendica\Model\Contact; use Exception; use Friendica\Core\Logger; @@ -35,7 +35,7 @@ use Friendica\Util\Strings; * This table is directional (cid = source, relation-cid = target), references public contacts (with uid=0) and records both * follows and the last interaction (likes/comments) on public posts. */ -class ContactRelation +class Relation { /** * No discovery of followers/followings diff --git a/src/Model/GContact.php b/src/Model/GContact.php index 55749d3b1..305120268 100644 --- a/src/Model/GContact.php +++ b/src/Model/GContact.php @@ -24,6 +24,7 @@ namespace Friendica\Model; use Exception; use Friendica\Core\Protocol; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Util\DateTimeFormat; /** @@ -48,7 +49,7 @@ class GContact $sourceId, ]; - return ContactRelation::countCommonFollows($sourceId, $targetIds['public'] ?? 0, $condition); + return Contact\Relation::countCommonFollows($sourceId, $targetIds['public'] ?? 0, $condition); } /** @@ -71,7 +72,12 @@ LIMIT 1", $zcid ); - return ContactRelation::countCommonFollowers($sourceId, $targetPublicContact['id'] ?? 0); + $condition = [ + 'NOT `self` AND NOT `blocked` AND NOT `hidden` AND `id` != ?', + $sourceId, + ]; + + return Contact\Relation::countCommonFollowers($sourceId, $targetPublicContact['id'] ?? 0, $condition); } /** @@ -97,7 +103,7 @@ LIMIT 1", $sourceId, ]; - return ContactRelation::listCommonFollows($sourceId, $targetIds['public'] ?? 0, $condition, $limit, $start, $shuffle); + return Contact\Relation::listCommonFollows($sourceId, $targetIds['public'] ?? 0, $condition, $limit, $start, $shuffle); } /** @@ -126,7 +132,12 @@ LIMIT 1", $zcid ); - return ContactRelation::listCommonFollows($sourceId, $targetPublicContact['id'] ?? 0, [], $limit, $start, $shuffle); + $condition = [ + 'NOT `self` AND NOT `blocked` AND NOT `hidden` AND `id` != ?', + $sourceId, + ]; + + return Contact\Relation::listCommonFollows($sourceId, $targetPublicContact['id'] ?? 0, $condition, $limit, $start, $shuffle); } /** @@ -139,7 +150,7 @@ LIMIT 1", { $cids = Contact::getPublicAndUserContacID($cid, $uid); - return ContactRelation::countFollows($cids['public'] ?? 0); + return Contact\Relation::countFollows($cids['public'] ?? 0); } /** @@ -154,6 +165,6 @@ LIMIT 1", { $cids = Contact::getPublicAndUserContacID($cid, $uid); - return ContactRelation::listFollows($cids['public'] ?? 0, [], $limit, $start); + return Contact\Relation::listFollows($cids['public'] ?? 0, [], $limit, $start); } } diff --git a/src/Model/Item.php b/src/Model/Item.php index b6f8ffa3d..54cd4a5db 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -1554,7 +1554,7 @@ class Item } // Update the contact relations - ContactRelation::store($parent['author-id'], $item['author-id'], $item['created']); + Contact\Relation::store($parent['author-id'], $item['author-id'], $item['created']); } return $item; diff --git a/src/Module/Admin/Site.php b/src/Module/Admin/Site.php index 7b298cd93..50566b349 100644 --- a/src/Module/Admin/Site.php +++ b/src/Module/Admin/Site.php @@ -28,7 +28,7 @@ use Friendica\Core\Theme; use Friendica\Core\Worker; use Friendica\Database\DBA; use Friendica\DI; -use Friendica\Model\ContactRelation; +use Friendica\Model\Contact; use Friendica\Module\BaseAdmin; use Friendica\Module\Register; use Friendica\Util\BasePath; @@ -175,7 +175,7 @@ class Site extends BaseAdmin $min_memory = (!empty($_POST['min_memory']) ? intval(trim($_POST['min_memory'])) : 0); $optimize_max_tablesize = (!empty($_POST['optimize_max_tablesize']) ? intval(trim($_POST['optimize_max_tablesize'])) : 100); $optimize_fragmentation = (!empty($_POST['optimize_fragmentation']) ? intval(trim($_POST['optimize_fragmentation'])) : 30); - $contact_discovery = (!empty($_POST['contact_discovery']) ? intval(trim($_POST['contact_discovery'])) : ContactRelation::DISCOVERY_NONE); + $contact_discovery = (!empty($_POST['contact_discovery']) ? intval(trim($_POST['contact_discovery'])) : Contact\Relation::DISCOVERY_NONE); $synchronize_directory = (!empty($_POST['synchronize_directory']) ? intval(trim($_POST['synchronize_directory'])) : false); $poco_requery_days = (!empty($_POST['poco_requery_days']) ? intval(trim($_POST['poco_requery_days'])) : 7); $poco_discovery = (!empty($_POST['poco_discovery']) ? intval(trim($_POST['poco_discovery'])) : false); @@ -532,9 +532,9 @@ class Site extends BaseAdmin ]; $discovery_choices = [ - ContactRelation::DISCOVERY_NONE => DI::l10n()->t('none'), - ContactRelation::DISCOVERY_LOCAL => DI::l10n()->t('Local contacts'), - ContactRelation::DISCOVERY_INTERACTOR => DI::l10n()->t('Interactors'), + Contact\Relation::DISCOVERY_NONE => DI::l10n()->t('none'), + Contact\Relation::DISCOVERY_LOCAL => DI::l10n()->t('Local contacts'), + Contact\Relation::DISCOVERY_INTERACTOR => DI::l10n()->t('Interactors'), // "All" is deactivated until we are sure not to put too much stress on the fediverse with this // ContactRelation::DISCOVERY_ALL => DI::l10n()->t('All'), ]; diff --git a/src/Worker/ContactDiscovery.php b/src/Worker/ContactDiscovery.php index 34d4a7da0..5dac17322 100644 --- a/src/Worker/ContactDiscovery.php +++ b/src/Worker/ContactDiscovery.php @@ -21,7 +21,7 @@ namespace Friendica\Worker; -use Friendica\Model\ContactRelation; +use Friendica\Model\Contact; class ContactDiscovery { @@ -31,6 +31,6 @@ class ContactDiscovery */ public static function execute(string $url) { - ContactRelation::discoverByUrl($url); + Contact\Relation::discoverByUrl($url); } }