From 5bbcb8bdf49252c9ea2360aa085469d215dcdb85 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 24 Mar 2021 22:22:14 +0000 Subject: [PATCH] ActivityPub: Delete Comments --- src/Model/Item.php | 2 +- src/Module/Objects.php | 14 ++++++-- src/Object/Post.php | 9 ++--- src/Protocol/ActivityPub/Transmitter.php | 42 +++++++++++++----------- 4 files changed, 37 insertions(+), 30 deletions(-) diff --git a/src/Model/Item.php b/src/Model/Item.php index d303938dd6..6488e479e5 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -241,7 +241,7 @@ class Item if ($item['uid'] == $uid) { self::markForDeletionById($item['id'], PRIORITY_HIGH); } elseif ($item['uid'] != 0) { - Logger::log('Wrong ownership. Not deleting item ' . $item['id']); + Logger::notice('Wrong ownership. Not deleting item', ['id' => $item['id']]); } } DBA::close($items); diff --git a/src/Module/Objects.php b/src/Module/Objects.php index 18830339fb..6233117564 100644 --- a/src/Module/Objects.php +++ b/src/Module/Objects.php @@ -69,7 +69,7 @@ class Objects extends BaseModule } } - $item = Post::selectFirst(['id', 'uid', 'origin', 'author-link', 'changed', 'private', 'psid', 'gravity'], + $item = Post::selectFirst(['id', 'uid', 'origin', 'author-link', 'changed', 'private', 'psid', 'gravity', 'deleted', 'parent-uri-id'], ['uri-id' => $itemuri['id']], ['order' => ['origin' => true]]); if (!DBA::isResult($item)) { @@ -93,8 +93,16 @@ class Objects extends BaseModule } } - // Valid items are original post or posted from this node (including in the case of a forum) - if (!$validated || !$item['origin'] && (parse_url($item['author-link'], PHP_URL_HOST) != parse_url(DI::baseUrl()->get(), PHP_URL_HOST))) { + if ($validated) { + // Valid items are original post or posted from this node (including in the case of a forum) + $validated = ($item['origin'] || (parse_url($item['author-link'], PHP_URL_HOST) == parse_url(DI::baseUrl()->get(), PHP_URL_HOST))); + + if (!$validated && $item['deleted']) { + $validated = Post::exists(['origin' => true, 'uri-id' => $item['parent-uri-id']]); + } + } + + if (!$validated) { throw new HTTPException\NotFoundException(); } diff --git a/src/Object/Post.php b/src/Object/Post.php index 389fac8770..2cf18ecd27 100644 --- a/src/Object/Post.php +++ b/src/Object/Post.php @@ -214,13 +214,8 @@ class Post $pinned = DI::l10n()->t('pinned item'); } - if ($origin && ($item['gravity'] != GRAVITY_PARENT) && ($item['network'] == Protocol::ACTIVITYPUB)) { - // ActivityPub doesn't allow removal of remote comments - $delete = DI::l10n()->t('Delete locally'); - } else { - // Showing the one or the other text, depending upon if we can only hide it or really delete it. - $delete = $origin ? DI::l10n()->t('Delete globally') : DI::l10n()->t('Remove locally'); - } + // Showing the one or the other text, depending upon if we can only hide it or really delete it. + $delete = $origin ? DI::l10n()->t('Delete globally') : DI::l10n()->t('Remove locally'); $drop = false; $block = false; diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index 62bdb7c4ac..18a39ef3cc 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -1069,25 +1069,27 @@ class Transmitter return false; } - $condition = ['item-uri' => $item['uri'], 'protocol' => Conversation::PARCEL_ACTIVITYPUB]; - $conversation = DBA::selectFirst('conversation', ['source'], $condition); - if (!$item['origin'] && DBA::isResult($conversation)) { - $data = json_decode($conversation['source'], true); - if (!empty($data['type'])) { - if (in_array($data['type'], ['Create', 'Update'])) { - if ($object_mode) { - unset($data['@context']); - unset($data['signature']); + if (!$item['deleted']) { + $condition = ['item-uri' => $item['uri'], 'protocol' => Conversation::PARCEL_ACTIVITYPUB]; + $conversation = DBA::selectFirst('conversation', ['source'], $condition); + if (!$item['origin'] && DBA::isResult($conversation)) { + $data = json_decode($conversation['source'], true); + if (!empty($data['type'])) { + if (in_array($data['type'], ['Create', 'Update'])) { + if ($object_mode) { + unset($data['@context']); + unset($data['signature']); + } + Logger::info('Return stored conversation', ['item' => $item_id]); + return $data; + } elseif (in_array('as:' . $data['type'], Receiver::CONTENT_TYPES)) { + if (!empty($data['@context'])) { + $context = $data['@context']; + unset($data['@context']); + } + unset($data['actor']); + $object = $data; } - Logger::info('Return stored conversation', ['item' => $item_id]); - return $data; - } elseif (in_array('as:' . $data['type'], Receiver::CONTENT_TYPES)) { - if (!empty($data['@context'])) { - $context = $data['@context']; - unset($data['@context']); - } - unset($data['actor']); - $object = $data; } } } @@ -1106,7 +1108,9 @@ class Transmitter $data = []; } - if (($item['gravity'] == GRAVITY_ACTIVITY) && ($type != 'Undo')) { + if ($type == 'Delete') { + $data['id'] = Item::newURI($item['uid'], $item['guid']) . '/' . $type;; + } elseif (($item['gravity'] == GRAVITY_ACTIVITY) && ($type != 'Undo')) { $data['id'] = $item['uri']; } else { $data['id'] = $item['uri'] . '/' . $type;