]> git.mxchange.org Git - friendica.git/commitdiff
We now store uncommon endpoints
authorMichael <heluecht@pirati.ca>
Mon, 25 Apr 2022 13:45:03 +0000 (13:45 +0000)
committerMichael <heluecht@pirati.ca>
Mon, 25 Apr 2022 13:45:03 +0000 (13:45 +0000)
database.sql
doc/database.md
doc/database/db_endpoint.md [new file with mode: 0644]
src/Model/APContact.php
src/Model/APContact/Endpoint.php [new file with mode: 0644]
src/Util/JsonLD.php
static/dbstructure.config.php

index 26f948c2d322fc5abc0b35b05075b05751d934eb..7511672f30d2b5872da80cfa7e5b69db4bb223d2 100644 (file)
@@ -1,6 +1,6 @@
 -- ------------------------------------------
 -- Friendica 2022.05-dev (Siberian Iris)
--- DB_UPDATE_VERSION 1459
+-- DB_UPDATE_VERSION 1460
 -- ------------------------------------------
 
 
@@ -554,6 +554,18 @@ CREATE TABLE IF NOT EXISTS `diaspora-interaction` (
        FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Signed Diaspora Interaction';
 
+--
+-- TABLE endpoint
+--
+CREATE TABLE IF NOT EXISTS `endpoint` (
+       `url` varbinary(255) NOT NULL COMMENT 'URL of the contact',
+       `type` varchar(20) NOT NULL COMMENT '',
+       `owner-uri-id` int unsigned COMMENT 'Id of the item-uri table entry that contains the apcontact url',
+        PRIMARY KEY(`url`),
+        UNIQUE INDEX `owner-uri-id_type` (`owner-uri-id`,`type`),
+       FOREIGN KEY (`owner-uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
+) DEFAULT COLLATE utf8mb4_general_ci COMMENT='ActivityPub endpoints - used in the ActivityPub implementation';
+
 --
 -- TABLE event
 --
index 629a86ee0a1c827ba865afc20a305d58272a20f5..dff31657fdbd89153b24f721b0d398817bfec8d3 100644 (file)
@@ -21,6 +21,7 @@ Database Tables
 | [conversation](help/database/db_conversation) | Raw data and structure information for messages |
 | [delayed-post](help/database/db_delayed-post) | Posts that are about to be distributed at a later time |
 | [diaspora-interaction](help/database/db_diaspora-interaction) | Signed Diaspora Interaction |
+| [endpoint](help/database/db_endpoint) | ActivityPub endpoints - used in the ActivityPub implementation |
 | [event](help/database/db_event) | Events |
 | [fcontact](help/database/db_fcontact) | Diaspora compatible contacts - used in the Diaspora implementation |
 | [fsuggest](help/database/db_fsuggest) | friend suggestion stuff |
diff --git a/doc/database/db_endpoint.md b/doc/database/db_endpoint.md
new file mode 100644 (file)
index 0000000..f025d33
--- /dev/null
@@ -0,0 +1,30 @@
+Table endpoint
+===========
+
+ActivityPub endpoints - used in the ActivityPub implementation
+
+Fields
+------
+
+| Field        | Description                                                    | Type           | Null | Key | Default | Extra |
+| ------------ | -------------------------------------------------------------- | -------------- | ---- | --- | ------- | ----- |
+| url          | URL of the contact                                             | varbinary(255) | NO   | PRI | NULL    |       |
+| type         |                                                                | varchar(20)    | NO   |     | NULL    |       |
+| owner-uri-id | Id of the item-uri table entry that contains the apcontact url | int unsigned   | YES  |     | NULL    |       |
+
+Indexes
+------------
+
+| Name              | Fields                     |
+| ----------------- | -------------------------- |
+| PRIMARY           | url                        |
+| owner-uri-id_type | UNIQUE, owner-uri-id, type |
+
+Foreign Keys
+------------
+
+| Field | Target Table | Target Field |
+|-------|--------------|--------------|
+| owner-uri-id | [item-uri](help/database/db_item-uri) | id |
+
+Return to [database documentation](help/database)
index 76ca3aaed9fb2d4fa9121ffff70cb898fa0b8db4..0255af7a33cf2c9d653f45d0e443cc0e5c502f82 100644 (file)
@@ -365,7 +365,7 @@ class APContact
                // To-Do
 
                // Unhandled
-               // tag, attachment, image, nomadicLocations, signature, featured, movedTo, liked
+               // tag, attachment, image, nomadicLocations, signature, movedTo, liked
 
                // Unhandled from Misskey
                // sharedInbox, isCat
@@ -431,6 +431,30 @@ class APContact
                        $apcontact['uri-id'] = ItemURI::insert(['uri' => $apcontact['url'], 'guid' => $apcontact['uuid']]);
                }
 
+               foreach (APContact\Endpoint::ENDPOINT_NAMES as $type => $name) {
+                       $value = JsonLD::fetchElement($compacted, $name, '@id');
+                       if (empty($value)) {
+                               continue;
+                       }
+                       APContact\Endpoint::update($apcontact['uri-id'], $type, $value);
+               }
+
+               if (!empty($compacted['as:endpoints'])) {
+                       foreach ($compacted['as:endpoints'] as $name => $endpoint) {
+                               if (empty($endpoint['@id']) || !is_string($endpoint['@id'])) {
+                                       continue;
+                               }
+
+                               if (in_array($name, APContact\Endpoint::ENDPOINT_NAMES)) {
+                                       $key = array_search($name, APContact\Endpoint::ENDPOINT_NAMES);
+                                       APContact\Endpoint::update($apcontact['uri-id'], $key, $endpoint['@id']);
+                                       Logger::debug('Store endpoint', ['key' => $key, 'name' => $name, 'endpoint' => $endpoint['@id']]);
+                               } elseif (!in_array($name, ['as:sharedInbox', 'as:uploadMedia', 'as:oauthTokenEndpoint', 'as:oauthAuthorizationEndpoint', 'litepub:oauthRegistrationEndpoint'])) {
+                                       Logger::debug('Unknown endpoint', ['name' => $name, 'endpoint' => $endpoint['@id']]);
+                               }
+                       }
+               }
+
                $apcontact['updated'] = DateTimeFormat::utcNow();
 
                // We delete the old entry when the URL is changed
diff --git a/src/Model/APContact/Endpoint.php b/src/Model/APContact/Endpoint.php
new file mode 100644 (file)
index 0000000..ebc23da
--- /dev/null
@@ -0,0 +1,71 @@
+<?php
+/**
+ * @copyright Copyright (C) 2010-2022, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Friendica\Model\APContact;
+
+use Friendica\Database\DBA;
+
+class Endpoint
+{
+       // Mobilizon Endpoints
+       const DISCUSSIONS = 10;
+       const EVENTS = 11;
+       const MEMBERS = 12;
+       const POSTS = 13;
+       const RESOURCES = 14;
+       const TODOS = 15;
+
+       // Peertube Endpoints
+       const PLAYLISTS = 20;
+
+       // Mastodon Endpoints
+       const DEVICES = 30;
+
+       const ENDPOINT_NAMES = [
+               self::PLAYLISTS => 'pt:playlists',
+               self::DISCUSSIONS => 'mobilizon:discussions',
+               self::EVENTS => 'mobilizon:events',
+               self::MEMBERS => 'mobilizon:members',
+               self::POSTS => 'mobilizon:posts',
+               self::RESOURCES => 'mobilizon:resources',
+               self::TODOS => 'mobilizon:todos',
+               self::DEVICES => 'toot:devices',
+       ];
+
+       /**
+        * Update an apcontact endpoint
+        *
+        * @param int    $owner_uri_id
+        * @param int    $type
+        * @param string $url
+        * @return bool
+        */
+       public static function update(int $owner_uri_id, int $type, string $url)
+       {
+               if (empty($url) || empty($owner_uri_id)) {
+                       return false;
+               }
+
+               $fields = ['owner-uri-id' => $owner_uri_id, 'type' => $type];
+
+               return DBA::update('endpoint', $fields, ['url' => $url], true);
+       }
+}
index 866fc2cdf54d532142039db2214ba55b3d8187f0..cf1e058a1478711535a950c5cb63bfe2f1c7f0f6 100644 (file)
@@ -139,7 +139,9 @@ class JsonLD
                        'toot' => (object)['@id' => 'http://joinmastodon.org/ns#', '@type' => '@id'],
                        'litepub' => (object)['@id' => 'http://litepub.social/ns#', '@type' => '@id'],
                        'sc' => (object)['@id' => 'http://schema.org#', '@type' => '@id'],
-                       'pt' => (object)['@id' => 'https://joinpeertube.org/ns#', '@type' => '@id']];
+                       'pt' => (object)['@id' => 'https://joinpeertube.org/ns#', '@type' => '@id'],
+                       'mobilizon' => (object)['@id' => 'https://joinmobilizon.org/ns#', '@type' => '@id'],
+               ];
 
                // Preparation for adding possibly missing content to the context
                if (!empty($json['@context']) && is_string($json['@context'])) {
index f49b38cb5539110e3e3e634fa4b766e9e75a1eb0..41758ed4b411a2d8a47990aed9bdf86f5d6cf843 100644 (file)
@@ -55,7 +55,7 @@
 use Friendica\Database\DBA;
 
 if (!defined('DB_UPDATE_VERSION')) {
-       define('DB_UPDATE_VERSION', 1459);
+       define('DB_UPDATE_VERSION', 1460);
 }
 
 return [
@@ -618,6 +618,18 @@ return [
                        "PRIMARY" => ["uri-id"]
                ]
        ],
+       "endpoint" => [
+               "comment" => "ActivityPub endpoints - used in the ActivityPub implementation",
+               "fields" => [
+                       "url" => ["type" => "varbinary(255)", "not null" => "1", "primary" => "1", "comment" => "URL of the contact"],
+                       "type" => ["type" => "varchar(20)", "not null" => "1", "comment" => ""],
+                       "owner-uri-id" => ["type" => "int unsigned", "foreign" => ["item-uri" => "id"], "comment" => "Id of the item-uri table entry that contains the apcontact url"],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["url"],
+                       "owner-uri-id_type" => ["UNIQUE", "owner-uri-id", "type"],
+               ]
+       ],
        "event" => [
                "comment" => "Events",
                "fields" => [