[ActivityPub] Ensuring notice deletion

ActivityPubPlugin:
- Minor onDeleteOwnNotice rewrite

Activitypub_inbox_handler:
- Add deletion check to incoming notice

Activitypub_postman:
- Call the correct getUrl function
This commit is contained in:
brunoccast 2019-07-25 03:29:11 +01:00 committed by Diogo Cordeiro
parent b19ee7b894
commit 067cc81ebb
3 changed files with 35 additions and 23 deletions

View File

@ -743,30 +743,31 @@ class ActivityPubPlugin extends Plugin
return true; return true;
} }
$other = []; // 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()
);
foreach ($notice->getAttentionProfiles() as $to_profile) {
try {
$other[] = Activitypub_profile::from_profile($to_profile);
} catch (Exception $e) {
// Local user can be ignored
}
}
if ($notice->reply_to) { if ($notice->reply_to) {
try { try {
$other[] = Activitypub_profile::from_profile($notice->getParent()->getProfile()); $parent_notice = $notice->getParent();
try {
$other[] = Activitypub_profile::from_profile($parent_notice->getProfile());
} catch (Exception $e) { } catch (Exception $e) {
// Local user can be ignored // Local user can be ignored
} }
try {
$mentions = $notice->getParent()->getAttentionProfiles(); $other = array_merge($other,
foreach ($mentions as $to_profile) { Activitypub_profile::from_profile_collection(
try { $parent_notice->getAttentionProfiles()
$other[] = Activitypub_profile::from_profile($to_profile); ));
} catch (Exception $e) {
// Local user can be ignored
}
}
} catch (NoParentNoticeException $e) { } catch (NoParentNoticeException $e) {
// This is not a reply to something (has no parent) // This is not a reply to something (has no parent)
} catch (NoResultException $e) { } catch (NoResultException $e) {

View File

@ -213,9 +213,20 @@ class Activitypub_inbox_handler
*/ */
private function handle_delete($actor, $object) private function handle_delete($actor, $object)
{ {
$notice = ActivityPubPlugin::grab_notice_from_url($object['object']); // 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); $notice->deleteAs($actor);
} }
}
/** /**
* Handles a Follow Activity received by our inbox. * Handles a Follow Activity received by our inbox.

View File

@ -350,7 +350,7 @@ class Activitypub_postman
{ {
$data = Activitypub_delete::delete_to_array( $data = Activitypub_delete::delete_to_array(
ActivityPubPlugin::actor_uri($notice->getProfile()), ActivityPubPlugin::actor_uri($notice->getProfile()),
$notice->getUrl() Activitypub_notice::getUrl($notice)
); );
$errors = []; $errors = [];
$data = json_encode($data, JSON_UNESCAPED_SLASHES); $data = json_encode($data, JSON_UNESCAPED_SLASHES);