From: Michael Vogel Date: Sun, 11 Dec 2022 10:21:02 +0000 (+0100) Subject: Some small fixes X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=884a265c5a1a45c997483bee7f65b9ebdfe240a3;p=friendica.git Some small fixes --- diff --git a/src/Core/Worker/Cron.php b/src/Core/Worker/Cron.php index 0f2c4b41e7..30b5c9dcc7 100644 --- a/src/Core/Worker/Cron.php +++ b/src/Core/Worker/Cron.php @@ -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]); } } diff --git a/src/Model/Item.php b/src/Model/Item.php index 3819185355..c28adfdc57 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -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; } diff --git a/src/Model/Post.php b/src/Model/Post.php index 4b1d70ae96..74a56264f0 100644 --- a/src/Model/Post.php +++ b/src/Model/Post.php @@ -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)); diff --git a/src/Module/Api/Mastodon/Timelines/PublicTimeline.php b/src/Module/Api/Mastodon/Timelines/PublicTimeline.php index d34deac079..1cb75b6691 100644 --- a/src/Module/Api/Mastodon/Timelines/PublicTimeline.php +++ b/src/Module/Api/Mastodon/Timelines/PublicTimeline.php @@ -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`)"]); diff --git a/src/Protocol/ActivityPub/Delivery.php b/src/Protocol/ActivityPub/Delivery.php index 3b8e539e9e..2bc4a09536 100644 --- a/src/Protocol/ActivityPub/Delivery.php +++ b/src/Protocol/ActivityPub/Delivery.php @@ -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); } } diff --git a/src/Protocol/ActivityPub/Receiver.php b/src/Protocol/ActivityPub/Receiver.php index 30348c7ade..d97e4bd168 100644 --- a/src/Protocol/ActivityPub/Receiver.php +++ b/src/Protocol/ActivityPub/Receiver.php @@ -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; diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php index 7d3d3d6b7c..042fa9ead0 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -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)) {