]> git.mxchange.org Git - friendica.git/blobdiff - src/Worker/Notifier.php
Merge pull request #12482 from annando/fix-reachable
[friendica.git] / src / Worker / Notifier.php
index 9898eed1a015cc36c2c29219ee9e51d2910ff2e5..7bf3696a538c59b4a2c1b546b42fa503af608fad 100644 (file)
@@ -30,6 +30,7 @@ use Friendica\DI;
 use Friendica\Model\Contact;
 use Friendica\Model\Conversation;
 use Friendica\Model\Group;
+use Friendica\Model\GServer;
 use Friendica\Model\Item;
 use Friendica\Model\Post;
 use Friendica\Model\PushSubscriber;
@@ -99,7 +100,7 @@ class Notifier
                        $uid = $target_id;
 
                        $condition = ['uid' => $target_id, 'self' => false, 'network' => [Protocol::DFRN, Protocol::DIASPORA]];
-                       $delivery_contacts_stmt = DBA::select('contact', ['id', 'url', 'addr', 'network', 'protocol', 'batch'], $condition);
+                       $delivery_contacts_stmt = DBA::select('contact', ['id', 'url', 'addr', 'network', 'protocol', 'baseurl', 'gsid', 'batch'], $condition);
                } else {
                        $post = Post::selectFirst(['id'], ['uri-id' => $post_uriid, 'uid' => $sender_uid]);
                        if (!DBA::isResult($post)) {
@@ -191,7 +192,7 @@ class Notifier
                        // when the original comment author does support the Diaspora protocol.
                        if ($thr_parent['author-link'] && $target_item['parent-uri'] != $target_item['thr-parent']) {
                                $diaspora_delivery = Diaspora::isSupportedByContactUrl($thr_parent['author-link']);
-                               if ($diaspora_delivery &&  empty($target_item['signed_text'])) {
+                               if ($diaspora_delivery && empty($target_item['signed_text'])) {
                                        Logger::debug('Post has got no Diaspora signature, so there will be no Diaspora delivery', ['guid' => $target_item['guid'], 'uri-id' => $target_item['uri-id']]);
                                        $diaspora_delivery = false;
                                }
@@ -336,7 +337,7 @@ class Notifier
                                foreach ($items as $item) {
                                        $recipients[] = $item['contact-id'];
                                        // pull out additional tagged people to notify (if public message)
-                                       if ($public_message && strlen($item['inform'])) {
+                                       if ($public_message && $item['inform']) {
                                                $people = explode(',',$item['inform']);
                                                foreach ($people as $person) {
                                                        if (substr($person,0,4) === 'cid:') {
@@ -425,7 +426,7 @@ class Notifier
                        if (!empty($networks)) {
                                $condition['network'] = $networks;
                        }
-                       $delivery_contacts_stmt = DBA::select('contact', ['id', 'addr', 'url', 'network', 'protocol', 'batch'], $condition);
+                       $delivery_contacts_stmt = DBA::select('contact', ['id', 'addr', 'url', 'network', 'protocol', 'baseurl', 'gsid', 'batch'], $condition);
                }
 
                $conversants = [];
@@ -437,7 +438,7 @@ class Notifier
                        if ($diaspora_delivery && !$unlisted) {
                                $batch_delivery = true;
 
-                               $participants = DBA::selectToArray('contact', ['batch', 'network', 'protocol', 'id', 'url', 'name'],
+                               $participants = DBA::selectToArray('contact', ['batch', 'network', 'protocol', 'baseurl', 'gsid', 'id', 'url', 'name'],
                                        ["`network` = ? AND `batch` != '' AND `uid` = ? AND `rel` != ? AND NOT `blocked` AND NOT `pending` AND NOT `archive`", Protocol::DIASPORA, $owner['uid'], Contact::SHARING],
                                        ['group_by' => ['batch', 'network', 'protocol']]);
 
@@ -449,7 +450,7 @@ class Notifier
                        $condition = ['network' => Protocol::DFRN, 'uid' => $owner['uid'], 'blocked' => false,
                                'pending' => false, 'archive' => false, 'rel' => [Contact::FOLLOWER, Contact::FRIEND]];
 
-                       $contacts = DBA::selectToArray('contact', ['id', 'url', 'addr', 'name', 'network', 'protocol'], $condition);
+                       $contacts = DBA::selectToArray('contact', ['id', 'url', 'addr', 'name', 'network', 'protocol', 'baseurl', 'gsid'], $condition);
 
                        $conversants = array_merge($contacts, $participants);
 
@@ -563,6 +564,11 @@ class Notifier
                                continue;
                        }
 
+                       if (!GServer::reachable($contact)) {
+                               Logger::info('Server is not reachable', ['id' => $post_uriid, 'uid' => $sender_uid, 'contact' => $contact]);
+                               continue;
+                       }
+
                        Logger::info('Delivery', ['batch' => $in_batch, 'target' => $post_uriid, 'uid' => $sender_uid, 'guid' => $target_item['guid'] ?? '', 'to' => $contact]);
 
                        // Ensure that posts with our own protocol arrives before Diaspora posts arrive.
@@ -771,18 +777,21 @@ class Notifier
                                $relay_inboxes = ActivityPub\Transmitter::addRelayServerInboxes();
                        }
 
-                       Logger::info('Origin item ' . $target_item['id'] . ' with URL ' . $target_item['uri'] . ' will be distributed.');
+                       Logger::info('Origin item will be distributed', ['id' => $target_item['id'], 'url' => $target_item['uri'], 'verb' => $target_item['verb']]);
                } elseif (!Post\Activity::exists($target_item['uri-id'])) {
-                       Logger::info('Remote item ' . $target_item['id'] . ' with URL ' . $target_item['uri'] . ' is no AP post. It will not be distributed.');
+                       Logger::info('Remote item is no AP post. It will not be distributed.', ['id' => $target_item['id'], 'url' => $target_item['uri'], 'verb' => $target_item['verb']]);
                        return ['count' => 0, 'contacts' => []];
-               } elseif ($parent['origin']) {
+               } elseif ($parent['origin'] && (($target_item['gravity'] != Item::GRAVITY_ACTIVITY) || DI::config()->get('system', 'redistribute_activities'))) {
                        $inboxes = ActivityPub\Transmitter::fetchTargetInboxes($parent, $uid, false, $target_item['id']);
 
                        if (in_array($target_item['private'], [Item::PUBLIC])) {
                                $inboxes = ActivityPub\Transmitter::addRelayServerInboxesForItem($parent['id'], $inboxes);
                        }
 
-                       Logger::info('Remote item ' . $target_item['id'] . ' with URL ' . $target_item['uri'] . ' will be distributed.');
+                       Logger::info('Remote item will be distributed', ['id' => $target_item['id'], 'url' => $target_item['uri'], 'verb' => $target_item['verb']]);
+               } else {
+                       Logger::info('Remote activity will not be distributed', ['id' => $target_item['id'], 'url' => $target_item['uri'], 'verb' => $target_item['verb']]);
+                       return ['count' => 0, 'contacts' => []];
                }
 
                if (empty($inboxes) && empty($relay_inboxes)) {