]> git.mxchange.org Git - friendica.git/commitdiff
Some small fixes
authorMichael Vogel <icarus@dabo.de>
Sun, 11 Dec 2022 10:21:02 +0000 (11:21 +0100)
committerMichael Vogel <icarus@dabo.de>
Sun, 11 Dec 2022 10:21:02 +0000 (11:21 +0100)
src/Core/Worker/Cron.php
src/Model/Item.php
src/Model/Post.php
src/Module/Api/Mastodon/Timelines/PublicTimeline.php
src/Protocol/ActivityPub/Delivery.php
src/Protocol/ActivityPub/Receiver.php
src/Worker/Notifier.php

index 0f2c4b41e7157e24e926f909a1517f4e83b40a92..30b5c9dcc7639ef51f5a5ce3cc16558888b2a5d2 100644 (file)
@@ -159,8 +159,13 @@ class Cron
         */
        private static function deliverPosts()
        {
-               $deliveries = DBA::p("SELECT `item-uri`.`uri` AS `inbox`, MAX(`failed`) AS `failed` FROM `post-delivery` INNER JOIN `item-uri` ON `item-uri`.`id` = `post-delivery`.`inbox-id` GROUP BY `inbox`");
+               $deliveries = DBA::p("SELECT `item-uri`.`uri` AS `inbox`, MAX(`failed`) AS `failed` FROM `post-delivery` INNER JOIN `item-uri` ON `item-uri`.`id` = `post-delivery`.`inbox-id` GROUP BY `inbox` ORDER BY RAND()");
                while ($delivery = DBA::fetch($deliveries)) {
+                       if ($delivery['failed'] > 0) {
+                               Logger::info('Removing failed deliveries', ['inbox' => $delivery['inbox'], 'failed' => $delivery['failed']]);
+                               Post\Delivery::removeFailed($delivery['inbox']);
+                       }
+
                        if ($delivery['failed'] == 0) {
                                $result = ActivityPub\Delivery::deliver($delivery['inbox']);
                                Logger::info('Directly deliver inbox', ['inbox' => $delivery['inbox'], 'result' => $result['success']]);
@@ -175,12 +180,7 @@ class Cron
                                $priority = PRIORITY_NEGLIGIBLE;
                        }
 
-                       if ($delivery['failed'] >= DI::config()->get('system', 'worker_defer_limit')) {
-                               Logger::info('Removing failed deliveries', ['inbox' => $delivery['inbox'], 'failed' => $delivery['failed']]);
-                               Post\Delivery::removeFailed($delivery['inbox']);
-                       }
-
-                       if (Worker::add($priority, 'APDelivery', '', 0, $delivery['inbox'], 0)) {
+                       if (Worker::add(['priority' => $priority, 'force_priority' => true], 'APDelivery', '', 0, $delivery['inbox'], 0)) {
                                Logger::info('Missing APDelivery worker added for inbox', ['inbox' => $delivery['inbox'], 'failed' => $delivery['failed'], 'priority' => $priority]);
                        }
                }
index 38191853551dc37203cfc8904a209369095042c7..c28adfdc57f3a8da04a17b8de68d76290646b01a 100644 (file)
@@ -2203,7 +2203,12 @@ class Item
                        return;
                }
 
-               if (!DBA::exists('contact', ['id' => $item['contact-id'], 'remote_self' => Contact::MIRROR_NATIVE_RESHARE])) {
+               $cdata = Contact::getPublicAndUserContactID($item['author-id'], $item['uid']);
+               if (empty($cdata['user']) || ($cdata['user'] != $item['contact-id'])) {
+                       return;
+               }
+
+               if (!DBA::exists('contact', ['id' => $cdata['user'], 'remote_self' => Contact::MIRROR_NATIVE_RESHARE])) {
                        return;
                }
 
index 4b1d70ae96eb90ad2214d567a3f43ab3eac678bf..74a56264f05e9ca138dd244a37089c8151ffb674 100644 (file)
@@ -401,10 +401,10 @@ class Post
                        AND ((NOT `contact-readonly` AND NOT `contact-pending` AND (`contact-rel` IN (?, ?)))
                                OR `self` OR `gravity` != ? OR `contact-uid` = ?)
                        AND NOT `" . $view . "`.`uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE `uid` = ? AND `hidden`)
-                       AND NOT `author-id` IN (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `blocked`)
-                       AND NOT `owner-id` IN (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `blocked`)
-                       AND NOT (`gravity` = ? AND `author-id` IN (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `ignored`))
-                       AND NOT (`gravity` = ? AND `owner-id` IN (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `ignored`))",
+                       AND NOT `author-id` IN (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `blocked` AND `cid` = `author-id`)
+                       AND NOT `owner-id` IN (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `blocked` AND `cid` = `owner-id`)
+                       AND NOT (`gravity` = ? AND `author-id` IN (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `ignored` AND `cid` = `author-id`))
+                       AND NOT (`gravity` = ? AND `owner-id` IN (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `ignored` AND `cid` = `owner-id`))",
                        0, Contact::SHARING, Contact::FRIEND, GRAVITY_PARENT, 0, $uid, $uid, $uid, GRAVITY_PARENT, $uid, GRAVITY_PARENT, $uid]);
 
                $select_string = implode(', ', array_map([DBA::class, 'quoteIdentifier'], $selected));
index d34deac079b91d40086564ca0a7b431b2eb08397..1cb75b66918521a8ec267714b0738a3382c670c9 100644 (file)
@@ -58,7 +58,7 @@ class PublicTimeline extends BaseApi
                $params = ['order' => ['uri-id' => true], 'limit' => $request['limit']];
 
                $condition = ['gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT], 'private' => Item::PUBLIC,
-                       'network' => Protocol::FEDERATED, 'parent-author-blocked' => false, 'parent-author-hidden' => false];
+                       'network' => Protocol::FEDERATED, 'author-blocked' => false, 'author-hidden' => false];
 
                if ($request['local']) {
                        $condition = DBA::mergeConditions($condition, ["`uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE `origin`)"]);
index 3b8e539e9e3bc8d4986e719accf05c96a05f088a..2bc4a09536d513d73e60ad4f7c341cf367815b5f 100644 (file)
@@ -82,11 +82,15 @@ class Delivery
        public static function deliverToInbox(string $cmd, int $item_id, string $inbox, int $uid, array $receivers, int $uri_id): array
        {
                if (empty($item_id) && !empty($uri_id) && !empty($uid)) {
-                       $item = Post::selectFirst(['id', 'parent', 'origin'], ['uri-id' => $uri_id, 'uid' => [$uid, 0]], ['order' => ['uid' => true]]);
+                       $item = Post::selectFirst(['id', 'parent', 'origin', 'gravity'], ['uri-id' => $uri_id, 'uid' => [$uid, 0]], ['order' => ['uid' => true]]);
                        if (empty($item['id'])) {
                                Logger::warning('Item not found, removing delivery', ['uri-id' => $uri_id, 'uid' => $uid, 'cmd' => $cmd, 'inbox' => $inbox]);
                                Post\Delivery::remove($uri_id, $inbox);
                                return ['success' => true, 'serverfailure' => false, 'drop' => false];
+                       } elseif (!$item['origin'] && ($item['gravity'] == GRAVITY_ACTIVITY)) {
+                               Logger::notice('Activities are not relayed, removing delivery', ['uri-id' => $uri_id, 'uid' => $uid, 'cmd' => $cmd, 'inbox' => $inbox]);
+                               Post\Delivery::remove($uri_id, $inbox);
+                               return ['success' => true, 'serverfailure' => false, 'drop' => false];
                        } else {
                                $item_id = $item['id'];
                        }
@@ -162,6 +166,8 @@ class Delivery
                                                Post\Delivery::incrementFailed($uri_id, $inbox);
                                        }
                                }
+                       } elseif ($uri_id) {
+                               Post\Delivery::remove($uri_id, $inbox);
                        }
                }
 
index 30348c7adeb1142feba3bac60394634b8a7441f1..d97e4bd1682e199034b01d6e7542e552f0d9ac80 100644 (file)
@@ -559,6 +559,11 @@ class Receiver
                        return true;
                }
 
+               if ($type == 'as:View') {
+                       Logger::info('View activities are ignored.', ['signer' => $signer, 'http_signer' => $http_signer]);
+                       return true;
+               }
+
                if (!JsonLD::fetchElement($activity, 'as:object', '@id')) {
                        Logger::info('Empty object', ['activity' => $activity]);
                        return true;
index 7d3d3d6b7cc7033a1a8d06d18d78361d7e893c42..042fa9ead08142e722aa794f34952ec433caffc9 100644 (file)
@@ -764,18 +764,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'] != GRAVITY_ACTIVITY)) {
                        $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)) {