*
* ACCOUNT_TYPE_COMMUNITY - the account is community forum
* Associated page types: PAGE_COMMUNITY, PAGE_PRVGROUP
+ *
+ * ACCOUNT_TYPE_RELAY - the account is a relay
+ * This will only be assigned to contacts, not to user accounts
* @{
*/
define('ACCOUNT_TYPE_PERSON', 0);
define('ACCOUNT_TYPE_ORGANISATION', 1);
define('ACCOUNT_TYPE_NEWS', 2);
define('ACCOUNT_TYPE_COMMUNITY', 3);
+define('ACCOUNT_TYPE_RELAY', 4);
/**
* @}
*/
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', 'nick',
+ 'url', 'archive', 'blocked', 'contact-type'];
+ // Fetch the first unarchived, unblocked account
$condition = ['uid' => 0, 'network' => NETWORK_DIASPORA, 'batch' => $batch,
- 'archive' => false, 'blocked' => false];
+ 'archive' => false, 'blocked' => false];
$contact = dba::selectFirst('contact', $fields, $condition);
+
+ // If there is nothing found, we check if there is already a relay account
+ if (!DBM::is_result($contact)) {
+ $condition = ['uid' => 0, 'network' => NETWORK_DIASPORA, 'batch' => $batch,
+ 'contact-type' => ACCOUNT_TYPE_RELAY];
+ $contact = dba::selectFirst('contact', $fields, $condition);
+ }
if (DBM::is_result($contact)) {
+ if ($contact['archive'] || $contact['blocked']) {
+ return false;
+ }
+
+ // Mark relay accounts as a relay, if this hadn't been the case before
+ if (($contact['url'] == $server_url) && ($contact['nick'] == 'relay') &&
+ ($contact['name'] == 'relay') && ($contact['contact-type'] != ACCOUNT_TYPE_RELAY)) {
+ $fields = ['contact-type' => ACCOUNT_TYPE_RELAY];
+ dba::update('contact', $fields, ['id' => $contact['id']]);
+ }
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);
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);