]> git.mxchange.org Git - friendica.git/commitdiff
Don't queue relay posts
authorMichael <heluecht@pirati.ca>
Sun, 8 Apr 2018 09:46:47 +0000 (09:46 +0000)
committerMichael <heluecht@pirati.ca>
Sun, 8 Apr 2018 09:46:47 +0000 (09:46 +0000)
boot.php
src/Protocol/Diaspora.php
src/Worker/Queue.php

index e3b94a8c9a4b82baff98bdfc58521123d3dab145..65867593df34008db274d34a4a7210d57bd85d73 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -212,12 +212,16 @@ define('PAGE_PRVGROUP',          5);
  *
  * 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);
 /**
  * @}
  */
index 3e53626bf34b9149a11d1e82a955a70e853abd54..75e3820754dba65d93e721a5dea2bd2fcab8f9fe 100644 (file)
@@ -103,7 +103,10 @@ class Diaspora
                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;
+                               }
                        }
                }
 
@@ -120,11 +123,30 @@ class Diaspora
        {
                $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(),
@@ -132,6 +154,7 @@ class Diaspora
                                '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);
 
@@ -3299,7 +3322,7 @@ class Diaspora
                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);
index aaf8df752d68f7145371f998f4174305c66a458c..46f6faf95d31334561ec54061bf88cca172bc6ef 100644 (file)
@@ -136,7 +136,8 @@ class Queue
                                logger('queue: diaspora_delivery: item ' . $q_item['id'] . ' for ' . $contact['name'] . ' <' . $contact['url'] . '>');
                                $deliver_status = Diaspora::transmit($owner, $contact, $data, $public, true, 'Queue:' . $q_item['id'], true);
 
-                               if (($deliver_status >= 200) && ($deliver_status <= 299)) {
+                               if ((($deliver_status >= 200) && ($deliver_status <= 299)) ||
+                                       ($contact['contact-type'] == ACCOUNT_TYPE_RELAY)) {
                                        QueueModel::removeItem($q_item['id']);
                                } else {
                                        QueueModel::updateTime($q_item['id']);