AP: Support "discoverable"

This commit is contained in:
Michael 2021-06-30 05:40:11 +00:00
parent 4308cace68
commit e2dc36a691
6 changed files with 44 additions and 32 deletions

View file

@ -1,6 +1,6 @@
-- ------------------------------------------ -- ------------------------------------------
-- Friendica 2021.06-rc (Siberian Iris) -- Friendica 2021.06-rc (Siberian Iris)
-- DB_UPDATE_VERSION 1423 -- DB_UPDATE_VERSION 1424
-- ------------------------------------------ -- ------------------------------------------
@ -340,6 +340,7 @@ CREATE TABLE IF NOT EXISTS `apcontact` (
`outbox` varchar(255) COMMENT '', `outbox` varchar(255) COMMENT '',
`sharedinbox` varchar(255) COMMENT '', `sharedinbox` varchar(255) COMMENT '',
`manually-approve` boolean COMMENT '', `manually-approve` boolean COMMENT '',
`discoverable` boolean COMMENT 'Mastodon extension: true if profile is published in their directory',
`nick` varchar(255) NOT NULL DEFAULT '' COMMENT '', `nick` varchar(255) NOT NULL DEFAULT '' COMMENT '',
`name` varchar(255) COMMENT '', `name` varchar(255) COMMENT '',
`about` text COMMENT '', `about` text COMMENT '',

View file

@ -7,7 +7,7 @@ Fields
------ ------
| Field | Description | Type | Null | Key | Default | Extra | | Field | Description | Type | Null | Key | Default | Extra |
| ---------------- | ---------------------------- | -------------- | ---- | --- | ------------------- | ----- | | ---------------- | ------------------------------------------------------------------- | -------------- | ---- | --- | ------------------- | ----- |
| url | URL of the contact | varbinary(255) | NO | PRI | NULL | | | url | URL of the contact | varbinary(255) | NO | PRI | NULL | |
| uuid | | varchar(255) | YES | | NULL | | | uuid | | varchar(255) | YES | | NULL | |
| type | | varchar(20) | NO | | NULL | | | type | | varchar(20) | NO | | NULL | |
@ -17,6 +17,7 @@ Fields
| outbox | | varchar(255) | YES | | NULL | | | outbox | | varchar(255) | YES | | NULL | |
| sharedinbox | | varchar(255) | YES | | NULL | | | sharedinbox | | varchar(255) | YES | | NULL | |
| manually-approve | | boolean | YES | | NULL | | | manually-approve | | boolean | YES | | NULL | |
| discoverable | Mastodon extension: true if profile is published in their directory | boolean | YES | | NULL | |
| nick | | varchar(255) | NO | | | | | nick | | varchar(255) | NO | | | |
| name | | varchar(255) | YES | | NULL | | | name | | varchar(255) | YES | | NULL | |
| about | | text | YES | | NULL | | | about | | text | YES | | NULL | |

View file

@ -284,6 +284,8 @@ class APContact
} }
} }
$apcontact['discoverable'] = JsonLD::fetchElement($compacted, 'toot:discoverable', '@value');
// To-Do // To-Do
// Unhandled // Unhandled

View file

@ -65,9 +65,11 @@ class ActivityPub
'dfrn' => 'http://purl.org/macgirvin/dfrn/1.0/', 'dfrn' => 'http://purl.org/macgirvin/dfrn/1.0/',
'diaspora' => 'https://diasporafoundation.org/ns/', 'diaspora' => 'https://diasporafoundation.org/ns/',
'litepub' => 'http://litepub.social/ns#', 'litepub' => 'http://litepub.social/ns#',
'toot' => 'http://joinmastodon.org/ns#',
'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers', 'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers',
'sensitive' => 'as:sensitive', 'Hashtag' => 'as:Hashtag', 'sensitive' => 'as:sensitive', 'Hashtag' => 'as:Hashtag',
'directMessage' => 'litepub:directMessage']]; 'directMessage' => 'litepub:directMessage',
'discoverable' => 'toot:discoverable']];
const ACCOUNT_TYPES = ['Person', 'Organization', 'Service', 'Group', 'Application', 'Tombstone']; const ACCOUNT_TYPES = ['Person', 'Organization', 'Service', 'Group', 'Application', 'Tombstone'];
/** /**
* Checks if the web request is done for the AP protocol * Checks if the web request is done for the AP protocol
@ -166,6 +168,10 @@ class ActivityPub
$profile['baseurl'] = $apcontact['baseurl']; $profile['baseurl'] = $apcontact['baseurl'];
$profile['gsid'] = $apcontact['gsid']; $profile['gsid'] = $apcontact['gsid'];
if (!is_null($apcontact['discoverable'])) {
$profile['hide'] = !$apcontact['discoverable'];
}
// Remove all "null" fields // Remove all "null" fields
foreach ($profile as $field => $content) { foreach ($profile as $field => $content) {
if (is_null($content)) { if (is_null($content)) {

View file

@ -325,7 +325,7 @@ class Transmitter
return []; return [];
} }
$fields = ['locality', 'region', 'country-name']; $fields = ['locality', 'region', 'country-name', 'net-publish'];
$profile = DBA::selectFirst('profile', $fields, ['uid' => $uid]); $profile = DBA::selectFirst('profile', $fields, ['uid' => $uid]);
if (!DBA::isResult($profile)) { if (!DBA::isResult($profile)) {
return []; return [];
@ -340,7 +340,7 @@ class Transmitter
$contact = User::getSystemAccount(); $contact = User::getSystemAccount();
$user = ['guid' => '', 'nickname' => $contact['nick'], 'pubkey' => $contact['pubkey'], $user = ['guid' => '', 'nickname' => $contact['nick'], 'pubkey' => $contact['pubkey'],
'account-type' => $contact['contact-type'], 'page-flags' => User::PAGE_FLAGS_NORMAL]; 'account-type' => $contact['contact-type'], 'page-flags' => User::PAGE_FLAGS_NORMAL];
$profile = ['locality' => '', 'region' => '', 'country-name' => '']; $profile = ['locality' => '', 'region' => '', 'country-name' => '', 'net-publish' => false];
} }
$data = ['@context' => ActivityPub::CONTEXT]; $data = ['@context' => ActivityPub::CONTEXT];
@ -375,6 +375,7 @@ class Transmitter
$data['url'] = $contact['url']; $data['url'] = $contact['url'];
$data['manuallyApprovesFollowers'] = in_array($user['page-flags'], [User::PAGE_FLAGS_NORMAL, User::PAGE_FLAGS_PRVGROUP]); $data['manuallyApprovesFollowers'] = in_array($user['page-flags'], [User::PAGE_FLAGS_NORMAL, User::PAGE_FLAGS_PRVGROUP]);
$data['discoverable'] = $profile['net-publish'];
$data['publicKey'] = ['id' => $contact['url'] . '#main-key', $data['publicKey'] = ['id' => $contact['url'] . '#main-key',
'owner' => $contact['url'], 'owner' => $contact['url'],
'publicKeyPem' => $user['pubkey']]; 'publicKeyPem' => $user['pubkey']];

View file

@ -55,7 +55,7 @@
use Friendica\Database\DBA; use Friendica\Database\DBA;
if (!defined('DB_UPDATE_VERSION')) { if (!defined('DB_UPDATE_VERSION')) {
define('DB_UPDATE_VERSION', 1423); define('DB_UPDATE_VERSION', 1424);
} }
return [ return [
@ -401,6 +401,7 @@ return [
"outbox" => ["type" => "varchar(255)", "comment" => ""], "outbox" => ["type" => "varchar(255)", "comment" => ""],
"sharedinbox" => ["type" => "varchar(255)", "comment" => ""], "sharedinbox" => ["type" => "varchar(255)", "comment" => ""],
"manually-approve" => ["type" => "boolean", "comment" => ""], "manually-approve" => ["type" => "boolean", "comment" => ""],
"discoverable" => ["type" => "boolean", "comment" => "Mastodon extension: true if profile is published in their directory"],
"nick" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""], "nick" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
"name" => ["type" => "varchar(255)", "comment" => ""], "name" => ["type" => "varchar(255)", "comment" => ""],
"about" => ["type" => "text", "comment" => ""], "about" => ["type" => "text", "comment" => ""],