+ return $contacts;
+ }
+
+ /**
+ * @brief Return a contact for a given server address or creates a dummy entry
+ *
+ * @param string $server_url The url of the server
+ * @return array with the contact
+ */
+ private static function getRelayContact($server_url)
+ {
+ $batch = $server_url . '/receive/public';
+
+ $fields = ['batch', 'id', 'name', 'network', 'archive', 'blocked'];
+
+ // Fetch the relay contact
+ $condition = ['uid' => 0, 'network' => NETWORK_DIASPORA, 'batch' => $batch,
+ 'contact-type' => ACCOUNT_TYPE_RELAY];
+ $contact = dba::selectFirst('contact', $fields, $condition);
+
+ // If there is nothing found, we check if there is some unmarked relay
+ // This code segment can be removed before the release 2018-05
+ if (!DBM::is_result($contact)) {
+ $condition = ['uid' => 0, 'network' => NETWORK_DIASPORA, 'batch' => $batch,
+ 'name' => 'relay', 'nick' => 'relay', 'url' => $server_url];
+ $contact = dba::selectFirst('contact', $fields, $condition);
+
+ if (DBM::is_result($contact)) {
+ // Mark the relay account as a relay account
+ $fields = ['contact-type' => ACCOUNT_TYPE_RELAY];
+ dba::update('contact', $fields, ['id' => $contact['id']]);
+ }
+ }
+ if (DBM::is_result($contact)) {
+ if ($contact['archive'] || $contact['blocked']) {
+ return false;
+ }
+ return $contact;
+ } else {
+ $fields = ['uid' => 0, 'created' => DateTimeFormat::utcNow(),
+ 'name' => 'relay', 'nick' => 'relay',
+ 'url' => $server_url, 'nurl' => normalise_link($server_url),
+ 'batch' => $batch, 'network' => NETWORK_DIASPORA,
+ 'rel' => CONTACT_IS_FOLLOWER, 'blocked' => false,
+ 'contact-type' => ACCOUNT_TYPE_RELAY,
+ 'pending' => false, 'writable' => true];
+ dba::insert('contact', $fields);
+
+ $fields = ['batch', 'id', 'name', 'network'];
+ $contact = dba::selectFirst('contact', $fields, $condition);
+ if (DBM::is_result($contact)) {
+ return $contact;
+ }
+
+ }
+
+ // It should never happen that we arrive here
+ return [];