Some small fixes

This commit is contained in:
Michael Vogel 2022-12-11 11:21:02 +01:00
parent a10f55bb85
commit 884a265c5a
7 changed files with 37 additions and 18 deletions

View file

@ -159,8 +159,13 @@ class Cron
*/ */
private static function deliverPosts() 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)) { 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) { if ($delivery['failed'] == 0) {
$result = ActivityPub\Delivery::deliver($delivery['inbox']); $result = ActivityPub\Delivery::deliver($delivery['inbox']);
Logger::info('Directly deliver inbox', ['inbox' => $delivery['inbox'], 'result' => $result['success']]); Logger::info('Directly deliver inbox', ['inbox' => $delivery['inbox'], 'result' => $result['success']]);
@ -175,12 +180,7 @@ class Cron
$priority = PRIORITY_NEGLIGIBLE; $priority = PRIORITY_NEGLIGIBLE;
} }
if ($delivery['failed'] >= DI::config()->get('system', 'worker_defer_limit')) { if (Worker::add(['priority' => $priority, 'force_priority' => true], 'APDelivery', '', 0, $delivery['inbox'], 0)) {
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)) {
Logger::info('Missing APDelivery worker added for inbox', ['inbox' => $delivery['inbox'], 'failed' => $delivery['failed'], 'priority' => $priority]); Logger::info('Missing APDelivery worker added for inbox', ['inbox' => $delivery['inbox'], 'failed' => $delivery['failed'], 'priority' => $priority]);
} }
} }

View file

@ -2203,7 +2203,12 @@ class Item
return; 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; return;
} }

View file

@ -401,10 +401,10 @@ class Post
AND ((NOT `contact-readonly` AND NOT `contact-pending` AND (`contact-rel` IN (?, ?))) AND ((NOT `contact-readonly` AND NOT `contact-pending` AND (`contact-rel` IN (?, ?)))
OR `self` OR `gravity` != ? OR `contact-uid` = ?) 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 `" . $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 `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 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 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 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]); 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)); $select_string = implode(', ', array_map([DBA::class, 'quoteIdentifier'], $selected));

View file

@ -58,7 +58,7 @@ class PublicTimeline extends BaseApi
$params = ['order' => ['uri-id' => true], 'limit' => $request['limit']]; $params = ['order' => ['uri-id' => true], 'limit' => $request['limit']];
$condition = ['gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT], 'private' => Item::PUBLIC, $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']) { if ($request['local']) {
$condition = DBA::mergeConditions($condition, ["`uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE `origin`)"]); $condition = DBA::mergeConditions($condition, ["`uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE `origin`)"]);

View 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 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)) { 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'])) { if (empty($item['id'])) {
Logger::warning('Item not found, removing delivery', ['uri-id' => $uri_id, 'uid' => $uid, 'cmd' => $cmd, 'inbox' => $inbox]); Logger::warning('Item not found, removing delivery', ['uri-id' => $uri_id, 'uid' => $uid, 'cmd' => $cmd, 'inbox' => $inbox]);
Post\Delivery::remove($uri_id, $inbox); Post\Delivery::remove($uri_id, $inbox);
return ['success' => true, 'serverfailure' => false, 'drop' => false]; 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 { } else {
$item_id = $item['id']; $item_id = $item['id'];
} }
@ -162,6 +166,8 @@ class Delivery
Post\Delivery::incrementFailed($uri_id, $inbox); Post\Delivery::incrementFailed($uri_id, $inbox);
} }
} }
} elseif ($uri_id) {
Post\Delivery::remove($uri_id, $inbox);
} }
} }

View file

@ -559,6 +559,11 @@ class Receiver
return true; 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')) { if (!JsonLD::fetchElement($activity, 'as:object', '@id')) {
Logger::info('Empty object', ['activity' => $activity]); Logger::info('Empty object', ['activity' => $activity]);
return true; return true;

View file

@ -764,18 +764,21 @@ class Notifier
$relay_inboxes = ActivityPub\Transmitter::addRelayServerInboxes(); $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'])) { } 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' => []]; 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']); $inboxes = ActivityPub\Transmitter::fetchTargetInboxes($parent, $uid, false, $target_item['id']);
if (in_array($target_item['private'], [Item::PUBLIC])) { if (in_array($target_item['private'], [Item::PUBLIC])) {
$inboxes = ActivityPub\Transmitter::addRelayServerInboxesForItem($parent['id'], $inboxes); $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)) { if (empty($inboxes) && empty($relay_inboxes)) {