]> git.mxchange.org Git - friendica.git/commitdiff
Added server discovery for their relais configuration
authorMichael <heluecht@pirati.ca>
Mon, 26 Mar 2018 05:44:53 +0000 (05:44 +0000)
committerMichael <heluecht@pirati.ca>
Mon, 26 Mar 2018 05:44:53 +0000 (05:44 +0000)
boot.php
database.sql
src/Database/DBStructure.php
src/Protocol/PortableContact.php

index 71050fe4d7831ccfec23ccc1e63c747335677a3c..e3b94a8c9a4b82baff98bdfc58521123d3dab145 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -41,7 +41,7 @@ define('FRIENDICA_PLATFORM',     'Friendica');
 define('FRIENDICA_CODENAME',     'The Tazmans Flax-lily');
 define('FRIENDICA_VERSION',      '2018-05-dev');
 define('DFRN_PROTOCOL_VERSION',  '2.23');
-define('DB_UPDATE_VERSION',      1258);
+define('DB_UPDATE_VERSION',      1259);
 define('NEW_UPDATE_ROUTINE_VERSION', 1170);
 
 /**
index e8662f95c8d86888e10104c20ef8e8d051e1f55d..aa87247db35c57dc2f68a079a1abe70995d28e6c 100644 (file)
@@ -1,6 +1,6 @@
 -- ------------------------------------------
 -- Friendica 2018-05-dev (The Tazmans Flax-lily)
--- DB_UPDATE_VERSION 1258
+-- DB_UPDATE_VERSION 1259
 -- ------------------------------------------
 
 
@@ -397,6 +397,8 @@ CREATE TABLE IF NOT EXISTS `gserver` (
        `noscrape` varchar(255) NOT NULL DEFAULT '' COMMENT '',
        `network` char(4) NOT NULL DEFAULT '' COMMENT '',
        `platform` varchar(255) NOT NULL DEFAULT '' COMMENT '',
+       `relay-subscribe` boolean NOT NULL DEFAULT '0' COMMENT 'Has the server subscribed to the relay system',
+       `relay-scope` varchar(10) NOT NULL DEFAULT '' COMMENT 'The scope of messages that the server wants to get',
        `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
        `last_poco_query` datetime DEFAULT '0001-01-01 00:00:00' COMMENT '',
        `last_contact` datetime DEFAULT '0001-01-01 00:00:00' COMMENT '',
@@ -405,6 +407,16 @@ CREATE TABLE IF NOT EXISTS `gserver` (
         UNIQUE INDEX `nurl` (`nurl`(190))
 ) DEFAULT COLLATE utf8mb4_general_ci;
 
+--
+-- TABLE gserver-tag
+--
+CREATE TABLE IF NOT EXISTS `gserver-tag` (
+       `gserver-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'The id of the gserver',
+       `tag` varchar(100) NOT NULL DEFAULT '' COMMENT 'Tag that the server has subscribed',
+        PRIMARY KEY(`gserver-id`,`tag`),
+        INDEX `tag` (`tag`)
+) DEFAULT COLLATE utf8mb4_general_ci;
+
 --
 -- TABLE hook
 --
index 5d527aac60a50dfbcd3ec057628fd613e0d86d23..67c8d7b8a646a49bbb0cf44f49747cd72088ba32 100644 (file)
@@ -1074,6 +1074,8 @@ class DBStructure
                                                "noscrape" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
                                                "network" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => ""],
                                                "platform" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                                               "relay-subscribe" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Has the server subscribed to the relay system"],
+                                               "relay-scope" => ["type" => "varchar(10)", "not null" => "1", "default" => "", "comment" => "The scope of messages that the server wants to get"],
                                                "created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
                                                "last_poco_query" => ["type" => "datetime", "default" => NULL_DATE, "comment" => ""],
                                                "last_contact" => ["type" => "datetime", "default" => NULL_DATE, "comment" => ""],
@@ -1084,6 +1086,17 @@ class DBStructure
                                                "nurl" => ["UNIQUE", "nurl(190)"],
                                                ]
                                ];
+               $database["gserver-tag"] = [
+                               "comment" => "Tags that the server has subscribed",
+                               "fields" => [
+                                               "gserver-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["gserver" => "id"], "primary" => "1", "comment" => "The id of the gserver"],
+                                               "tag" => ["type" => "varchar(100)", "not null" => "1", "default" => "", "primary" => "1", "comment" => "Tag that the server has subscribed"],
+                                               ],
+                               "indexes" => [
+                                               "PRIMARY" => ["gserver-id", "tag"],
+                                               "tag" => ["tag"],
+                                               ]
+                               ];
                $database["hook"] = [
                                "comment" => "addon hook registry",
                                "fields" => [
index ff2b2fca6179bfeb0dd66979abb96901a1cf3d68..c7f58b9fb2adb67c7033100b06cf4ee2b309e01c 100644 (file)
@@ -1377,11 +1377,44 @@ class PortableContact
                        $fields['created'] = DateTimeFormat::utcNow();
                        dba::insert('gserver', $fields);
                }
+
+               if (in_array($fields['network'], [NETWORK_DFRN, NETWORK_DIASPORA])) {
+                       self::discoverRelay(server_url);
+               }
+
                logger("End discovery for server " . $server_url, LOGGER_DEBUG);
 
                return !$failure;
        }
 
+       private static function discoverRelay($server_url)
+       {
+               logger("Discover relay data for server " . $server_url, LOGGER_DEBUG);
+
+               $serverret = Network::curl($server_url."/.well-known/x-social-relay");
+               if (!$serverret["success"]) {
+                       return;
+               }
+
+               $data = json_decode($serverret['body']);
+               if (!is_object($data)) {
+                       return;
+               }
+
+               $gserver = dba::selectFirst('gserver', ['id'], ['nurl' => normalise_link($server_url)]);
+               if (!DBM::is_result($gserver)) {
+                       return;
+               }
+
+               $fields = ['relay-subscribe' => $data->subscribe, 'relay-scope' => $data->scope];
+               dba::update('gserver', $fields, ['id' => $gserver['id']]);
+
+               dba::delete('gserver-tag', ['gserver-id' => $gserver['id']]);
+               foreach ($data->tags as $tag) {
+                       dba::insert('gserver-tag', ['gserver-id' => $gserver['id'], 'tag' => $tag]);
+               }
+       }
+
        /**
         * @brief Returns a list of all known servers
         * @return array List of server urls
@@ -1463,8 +1496,8 @@ class PortableContact
                                $header = ['Authorization: Bearer '.$accesstoken];
                                $serverdata = Network::curl($api, false, $redirects, ['headers' => $header]);
                                if ($serverdata['success']) {
-                                       $servers = json_decode($serverdata['body']);
-                                       foreach ($servers->instances as $server) {
+                                       $servers = json_decode($serverdata['body']);
+                                       foreach ($servers->instances as $server) {
                                                $url = (is_null($server->https_score) ? 'http' : 'https').'://'.$server->name;
                                                Worker::add(PRIORITY_LOW, "DiscoverPoCo", "server", $url);
                                        }