From 9de1c34bc088b3fb14da97ff8f2079ec1b9c2106 Mon Sep 17 00:00:00 2001 From: brunoccast Date: Thu, 25 Jul 2019 03:29:11 +0100 Subject: [PATCH] [ActivityPub] Ensuring notice deletion ActivityPubPlugin: - Minor onDeleteOwnNotice rewrite Activitypub_inbox_handler: - Add deletion check to incoming notice Activitypub_postman: - Call the correct getUrl function --- plugins/ActivityPub/ActivityPubPlugin.php | 41 ++++++++++++----------- plugins/ActivityPub/lib/inbox_handler.php | 15 +++++++-- plugins/ActivityPub/lib/postman.php | 2 +- 3 files changed, 35 insertions(+), 23 deletions(-) diff --git a/plugins/ActivityPub/ActivityPubPlugin.php b/plugins/ActivityPub/ActivityPubPlugin.php index ed666a3187..fa00b57119 100644 --- a/plugins/ActivityPub/ActivityPubPlugin.php +++ b/plugins/ActivityPub/ActivityPubPlugin.php @@ -743,30 +743,31 @@ class ActivityPubPlugin extends Plugin return true; } - $other = []; - - foreach ($notice->getAttentionProfiles() as $to_profile) { - try { - $other[] = Activitypub_profile::from_profile($to_profile); - } catch (Exception $e) { - // Local user can be ignored - } + // The deleting user must have permission to do so, but + // it still doesn't own the notitce, so we just need to + // handle things locally + if (!$notice->isLocal()) { + return true; } + + $other = Activitypub_profile::from_profile_collection( + $notice->getAttentionProfiles() + ); + if ($notice->reply_to) { try { - $other[] = Activitypub_profile::from_profile($notice->getParent()->getProfile()); - } catch (Exception $e) { - // Local user can be ignored - } - try { - $mentions = $notice->getParent()->getAttentionProfiles(); - foreach ($mentions as $to_profile) { - try { - $other[] = Activitypub_profile::from_profile($to_profile); - } catch (Exception $e) { - // Local user can be ignored - } + $parent_notice = $notice->getParent(); + + try { + $other[] = Activitypub_profile::from_profile($parent_notice->getProfile()); + } catch (Exception $e) { + // Local user can be ignored } + + $other = array_merge($other, + Activitypub_profile::from_profile_collection( + $parent_notice->getAttentionProfiles() + )); } catch (NoParentNoticeException $e) { // This is not a reply to something (has no parent) } catch (NoResultException $e) { diff --git a/plugins/ActivityPub/lib/inbox_handler.php b/plugins/ActivityPub/lib/inbox_handler.php index a83ac6f80e..c602815737 100644 --- a/plugins/ActivityPub/lib/inbox_handler.php +++ b/plugins/ActivityPub/lib/inbox_handler.php @@ -213,8 +213,19 @@ class Activitypub_inbox_handler */ private function handle_delete($actor, $object) { - $notice = ActivityPubPlugin::grab_notice_from_url($object['object']); - $notice->deleteAs($actor); + // some moderator could already have deleted the + // notice, so we test it first + try { + $found = Deleted_notice::getByUri($object); + $deleted = ($found instanceof Deleted_notice); + } catch (NoResultException $e) { + $deleted = false; + } + + if (!$deleted) { + $notice = ActivityPubPlugin::grab_notice_from_url($object); + $notice->deleteAs($actor); + } } /** diff --git a/plugins/ActivityPub/lib/postman.php b/plugins/ActivityPub/lib/postman.php index 8bab477022..92a36228a8 100644 --- a/plugins/ActivityPub/lib/postman.php +++ b/plugins/ActivityPub/lib/postman.php @@ -350,7 +350,7 @@ class Activitypub_postman { $data = Activitypub_delete::delete_to_array( ActivityPubPlugin::actor_uri($notice->getProfile()), - $notice->getUrl() + Activitypub_notice::getUrl($notice) ); $errors = []; $data = json_encode($data, JSON_UNESCAPED_SLASHES);