+ 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]);
+ }
+ }
+