From 639d160c24da1ee7e0f96e9e10fabc3fac56599a Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 30 Jul 2023 17:46:37 +0000 Subject: [PATCH] Improvements for relais like relay.fedi.buzz --- src/Console/Relay.php | 8 ++------ src/Model/APContact.php | 8 ++++++++ src/Protocol/Relay.php | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Console/Relay.php b/src/Console/Relay.php index 52682241e6..11d1dbf821 100644 --- a/src/Console/Relay.php +++ b/src/Console/Relay.php @@ -23,8 +23,8 @@ namespace Friendica\Console; use Asika\SimpleConsole\CommandArgsException; use Friendica\Model\APContact; -use Friendica\Model\Contact; use Friendica\Protocol\ActivityPub\Transmitter; +use Friendica\Protocol\Relay as ProtocolRelay; /** * tool to control the list of ActivityPub relay servers from the CLI @@ -90,13 +90,9 @@ HELP; } if ((count($this->args) == 1) && ($this->getArgument(0) == 'list')) { - $contacts = $this->dba->select('apcontact', ['url'], - ["`type` IN (?, ?) AND `url` IN (SELECT `url` FROM `contact` WHERE `uid` = ? AND `rel` = ?)", - 'Application', 'Service', 0, Contact::FRIEND]); - while ($contact = $this->dba->fetch($contacts)) { + foreach (ProtocolRelay::getList(['url']) as $contact) { $this->out($contact['url']); } - $this->dba->close($contacts); } elseif (count($this->args) == 0) { throw new CommandArgsException('too few arguments'); } elseif (count($this->args) == 1) { diff --git a/src/Model/APContact.php b/src/Model/APContact.php index 2a5b89928f..c49017b595 100644 --- a/src/Model/APContact.php +++ b/src/Model/APContact.php @@ -584,6 +584,14 @@ class APContact */ public static function isRelay(array $apcontact): bool { + if (in_array($apcontact['type'], ['Person', 'Organization'])) { + return false; + } + + if (($apcontact['type'] == 'Service') && empty($apcontact['outbox']) && empty($apcontact['sharedinbox']) && empty($apcontact['following']) && empty($apcontact['followers']) && empty($apcontact['statuses_count'])) { + return true; + } + if (empty($apcontact['nick']) || $apcontact['nick'] != 'relay') { return false; } diff --git a/src/Protocol/Relay.php b/src/Protocol/Relay.php index c5131fb3fd..ae8ecbbb24 100644 --- a/src/Protocol/Relay.php +++ b/src/Protocol/Relay.php @@ -354,7 +354,7 @@ class Relay public static function getList(array $fields = []): array { return DBA::selectToArray('apcontact', $fields, - ["`type` = ? AND `url` IN (SELECT `url` FROM `contact` WHERE `uid` = ? AND `rel` = ?)", 'Application', 0, Contact::FRIEND]); + ["`type` IN (?, ?) AND `url` IN (SELECT `url` FROM `contact` WHERE `uid` = ? AND `rel` = ?)", 'Application', 'Service', 0, Contact::FRIEND]); } /**