From cbf1e5c69946b71c7f83a1c8c8683f902ef268d8 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 2 Sep 2020 03:02:50 +0000 Subject: [PATCH] New field "manually-approve" for contact table --- src/Model/Contact.php | 7 +++---- src/Network/Probe.php | 9 ++++++--- src/Object/Api/Mastodon/Account.php | 2 +- src/Protocol/ActivityPub.php | 1 + static/dbstructure.config.php | 3 ++- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/Model/Contact.php b/src/Model/Contact.php index eed77b662f..1b2aa38616 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -1802,7 +1802,7 @@ class Contact // These fields aren't updated by this routine: // 'xmpp', 'sensitive' - $fields = ['uid', 'avatar', 'name', 'nick', 'location', 'keywords', 'about', 'subscribe', + $fields = ['uid', 'avatar', 'name', 'nick', 'location', 'keywords', 'about', 'subscribe', 'manually-approve', 'unsearchable', 'url', 'addr', 'batch', 'notify', 'poll', 'request', 'confirm', 'poco', 'network', 'alias', 'baseurl', 'gsid', 'forum', 'prv', 'contact-type', 'pubkey', 'last-item']; $contact = DBA::selectFirst('contact', $fields, ['id' => $id]); @@ -1851,9 +1851,8 @@ class Contact $ret['prv'] = false; $ret['contact-type'] = $ret['account-type']; if ($ret['contact-type'] == User::ACCOUNT_TYPE_COMMUNITY) { - $apcontact = APContact::getByURL($ret['url'], false); - if (isset($apcontact['manually-approve'])) { - $ret['forum'] = (bool)!$apcontact['manually-approve']; + if (isset($ret['manually-approve'])) { + $ret['forum'] = (bool)!$ret['manually-approve']; $ret['prv'] = (bool)!$ret['forum']; } } diff --git a/src/Network/Probe.php b/src/Network/Probe.php index 098e48c6fc..6de749fa84 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -91,12 +91,12 @@ class Probe "community", "keywords", "location", "about", "hide", "batch", "notify", "poll", "request", "confirm", "subscribe", "poco", "following", "followers", "inbox", "outbox", "sharedinbox", - "priority", "network", "pubkey", "baseurl", "gsid"]; + "priority", "network", "pubkey", "manually-approve", "baseurl", "gsid"]; $newdata = []; foreach ($fields as $field) { if (isset($data[$field])) { - if (in_array($field, ["gsid", "hide", "account-type"])) { + if (in_array($field, ["gsid", "hide", "account-type", "manually-approve"])) { $newdata[$field] = (int)$data[$field]; } else { $newdata[$field] = $data[$field]; @@ -1454,6 +1454,7 @@ class Probe && !empty($hcard_url) ) { $data["network"] = Protocol::DIASPORA; + $data["manually-approve"] = false; // The Diaspora handle must always be lowercase if (!empty($data["addr"])) { @@ -1544,6 +1545,7 @@ class Probe && isset($data["url"]) ) { $data["network"] = Protocol::OSTATUS; + $data["manually-approve"] = false; } else { return $short ? false : []; } @@ -2218,7 +2220,8 @@ class Probe 'following' => $approfile['following'], 'followers' => $approfile['followers'], 'inbox' => $approfile['inbox'], 'outbox' => $approfile['outbox'], 'sharedinbox' => $approfile['endpoints']['sharedInbox'], 'network' => Protocol::DFRN, - 'pubkey' => $profile['upubkey'], 'baseurl' => $approfile['generator']['url'], 'gsid' => $profile['gsid']]; + 'pubkey' => $profile['upubkey'], 'baseurl' => $approfile['generator']['url'], 'gsid' => $profile['gsid'], + 'manually-approve' => in_array($profile['page-flags'], [User::PAGE_FLAGS_NORMAL, User::PAGE_FLAGS_PRVGROUP])]; return self::rearrangeData($data); } } diff --git a/src/Object/Api/Mastodon/Account.php b/src/Object/Api/Mastodon/Account.php index 3ec9506024..517fb152ba 100644 --- a/src/Object/Api/Mastodon/Account.php +++ b/src/Object/Api/Mastodon/Account.php @@ -99,7 +99,7 @@ class Account extends BaseEntity $publicContact['nick'] : $publicContact['addr']; $this->display_name = $publicContact['name']; - $this->locked = !empty($apcontact['manually-approve']); + $this->locked = $publicContact['manually-approve'] ?? !empty($apcontact['manually-approve']); $this->bot = ($publicContact['contact-type'] == Contact::TYPE_NEWS); $this->discoverable = !$publicContact['unsearchable']; $this->group = ($publicContact['contact-type'] == Contact::TYPE_COMMUNITY); diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 359d361b01..19eb8c8bce 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -157,6 +157,7 @@ class ActivityPub $profile['poll'] = $apcontact['outbox']; $profile['pubkey'] = $apcontact['pubkey']; $profile['subscribe'] = $apcontact['subscribe']; + $profile['manually-approve'] = $apcontact['manually-approve']; $profile['baseurl'] = $apcontact['baseurl']; $profile['gsid'] = $apcontact['gsid']; diff --git a/static/dbstructure.config.php b/static/dbstructure.config.php index 4f69035ce0..b1cbb6b27b 100755 --- a/static/dbstructure.config.php +++ b/static/dbstructure.config.php @@ -54,7 +54,7 @@ use Friendica\Database\DBA; if (!defined('DB_UPDATE_VERSION')) { - define('DB_UPDATE_VERSION', 1365); + define('DB_UPDATE_VERSION', 1366); } return [ @@ -153,6 +153,7 @@ return [ "forum" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "contact is a forum"], "prv" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "contact is a private group"], "contact-type" => ["type" => "tinyint", "not null" => "1", "default" => "0", "comment" => ""], + "manually-approve" => ["type" => "boolean", "comment" => ""], "hidden" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""], "archive" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""], "pending" => ["type" => "boolean", "not null" => "1", "default" => "1", "comment" => ""],