]> git.mxchange.org Git - friendica.git/commitdiff
Merge branch 'issue-4816' of github.com:annando/friendica into issue-4816
authorMichael <heluecht@pirati.ca>
Wed, 11 Apr 2018 19:21:23 +0000 (19:21 +0000)
committerMichael <heluecht@pirati.ca>
Wed, 11 Apr 2018 19:21:23 +0000 (19:21 +0000)
src/Protocol/Diaspora.php
src/Worker/Notifier.php

index 0e5f0c27f1f52d426d5138e483666fe9e212b151..f8e4c11b241b382b6d362a38f859b16a110bdb43 100644 (file)
@@ -49,10 +49,12 @@ class Diaspora
         *
         * The list contains not only the official relays but also servers that we serve directly
         *
-        * @param integer $item_id   The id of the item that is sent
+        * @param integer $item_id  The id of the item that is sent
+        * @param array   $contacts The previously fetched contacts
+        *
         * @return array of relay servers
         */
-       public static function relayList($item_id)
+       public static function relayList($item_id, $contacts = [])
        {
                $serverlist = [];
 
@@ -99,15 +101,26 @@ class Diaspora
                }
 
                // Now we are collecting all relay contacts
-               $contacts = [];
                foreach ($serverlist as $server_url) {
                        // We don't send messages to ourselves
-                       if (!link_compare($server_url, System::baseUrl())) {
-                               $cid = self::getRelayContactId($server_url);
-                               if (!is_bool($cid)) {
-                                       $contacts[] = $cid;
+                       if (link_compare($server_url, System::baseUrl())) {
+                               continue;
+                       }
+                       $contact = self::getRelayContact($server_url);
+                       if (is_bool($contact)) {
+                               continue;
+                       }
+
+                       $exists = false;
+                       foreach ($contacts as $entry) {
+                               if ($entry['batch'] == $contact['batch']) {
+                                       $exists = true;
                                }
                        }
+
+                       if (!$exists) {
+                               $contacts[] = $contact;
+                       }
                }
 
                return $contacts;
@@ -119,7 +132,7 @@ class Diaspora
         * @param string $server_url The url of the server
         * @return array with the contact
         */
-       private static function getRelayContactId($server_url)
+       private static function getRelayContact($server_url)
        {
                $batch = $server_url . '/receive/public';
 
index e4e72023616bf28d4c4b1e2d7bfb5017ec12ae2e..422adafede712452f84c77177437a984c62b14eb 100644 (file)
@@ -479,15 +479,9 @@ class Notifier {
 
 
                if ($public_message) {
-
-                       $r0 = [];
                        $r1 = [];
 
                        if ($diaspora_delivery) {
-                               if (!$followup) {
-                                       $r0 = Diaspora::relayList($item_id);
-                               }
-
                                $r1 = q("SELECT `batch`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`name`) AS `name`, ANY_VALUE(`network`) AS `network`
                                        FROM `contact` WHERE `network` = '%s' AND `batch` != ''
                                        AND `uid` = %d AND `rel` != %d AND NOT `blocked` AND NOT `pending` AND NOT `archive` GROUP BY `batch`",
@@ -500,17 +494,17 @@ class Notifier {
                                // The function will ensure that there are no duplicates
                                $r1 = Diaspora::participantsForThread($item_id, $r1);
 
+                               // Add the relay to the list, avoid duplicates
+                               if (!$followup) {
+                                       $r1 = Diaspora::relayList($item_id, $r1);
+                               }
                        }
 
-                       $r2 = q("SELECT `id`, `name`,`network` FROM `contact`
-                               WHERE `network` in ('%s') AND `uid` = %d AND NOT `blocked` AND NOT `pending` AND NOT `archive` AND `rel` != %d",
-                               dbesc(NETWORK_DFRN),
-                               intval($owner['uid']),
-                               intval(CONTACT_IS_SHARING)
-                       );
-
+                       $condition = ['network' => NETWORK_DFRN, 'uid' => $owner['uid'], 'blocked' => false,
+                               'pending' => false, 'archive' => false, 'rel' => [CONTACT_IS_FOLLOWER, CONTACT_IS_FRIEND]];
+                       $r2 = dba::inArray(dba::select('contact', ['id', 'name', 'network'], $condition));
 
-                       $r = array_merge($r2, $r1, $r0);
+                       $r = array_merge($r2, $r1);
 
                        if (DBM::is_result($r)) {
                                logger('pubdeliver '.$target_item["guid"].': '.print_r($r,true), LOGGER_DEBUG);