// All servers who wants content with this tag
$tagserverlist = [];
- $tagserver = dba::select('gserver-tag', ['gserver-id'], ['tag' => $taglist]);
- while ($server = dba::fetch($tagserver)) {
- $tagserverlist[] = $server['gserver-id'];
+ if (!empty($taglist)) {
+ $tagserver = dba::select('gserver-tag', ['gserver-id'], ['tag' => $taglist]);
+ while ($server = dba::fetch($tagserver)) {
+ $tagserverlist[] = $server['gserver-id'];
+ }
}
// All adresses with the given id
- $servers = dba::select('gserver', ['url'], ['relay-subscribe' => true, 'relay-scope' => 'tags', 'id' => $tagserverlist]);
- while ($server = dba::fetch($servers)) {
- $serverlist[$server['url']] = $server['url'];
+ if (!empty($tagserverlist)) {
+ $servers = dba::select('gserver', ['url'], ['relay-subscribe' => true, 'relay-scope' => 'tags', 'id' => $tagserverlist]);
+ while ($server = dba::fetch($servers)) {
+ $serverlist[$server['url']] = $server['url'];
+ }
}
}
foreach ($serverlist as $server_url) {
// We don't send messages to ourselves
if (!link_compare($server_url, System::baseUrl())) {
- $contacts[] = self::getRelayContactId($server_url);
+ $cid = self::getRelayContactId($server_url);
+ if (!is_bool($cid)) {
+ $contacts[] = $cid;
+ }
}
}
{
$batch = $server_url . '/receive/public';
- $fields = ['batch', 'id', 'name', 'network'];
+ $fields = ['batch', 'id', 'name', 'network', 'archive', 'blocked'];
+
+ // Fetch the relay contact
$condition = ['uid' => 0, 'network' => NETWORK_DIASPORA, 'batch' => $batch,
- 'archive' => false, 'blocked' => false];
+ '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(),
'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);
*
* @return string The message that will be transmitted to other servers
*/
- private static function buildMessage($msg, $user, $contact, $prvkey, $pubkey, $public = false)
+ public static function buildMessage($msg, $user, $contact, $prvkey, $pubkey, $public = false)
{
// The message is put into an envelope with the sender's signature
$envelope = self::buildMagicEnvelope($msg, $user);
$logid = random_string(4);
+ $dest_url = ($public_batch ? $contact["batch"] : $contact["notify"]);
+
// We always try to use the data from the fcontact table.
// This is important for transmitting data to Friendica servers.
- if (!empty($contact['addr']) && ($contact['network'] != NETWORK_DIASPORA)) {
+ if (!empty($contact['addr'])) {
$fcontact = self::personByHandle($contact['addr']);
- $dest_url = ($public_batch ? $fcontact["batch"] : $fcontact["notify"]);
- } else {
- $dest_url = ($public_batch ? $contact["batch"] : $contact["notify"]);
+ if (!empty($fcontact)) {
+ $dest_url = ($public_batch ? $fcontact["batch"] : $fcontact["notify"]);
+ }
}
if (!$dest_url) {
logger("transmit: ".$logid."-".$guid." returns: ".$return_code);
if (!$return_code || (($return_code == 503) && (stristr($a->get_curl_headers(), "retry-after")))) {
- if (!$no_queue) {
+ if (!$no_queue && ($contact['contact-type'] != ACCOUNT_TYPE_RELAY)) {
logger("queue message");
// queue message for redelivery
Queue::add($contact["id"], NETWORK_DIASPORA, $envelope, $public_batch, $guid);