diff --git a/ActivityPubPlugin.php b/ActivityPubPlugin.php index abe6f46..474d8f6 100644 --- a/ActivityPubPlugin.php +++ b/ActivityPubPlugin.php @@ -219,6 +219,36 @@ class ActivityPubPlugin extends Plugin return true; } + + /** + * Notify remote users when their notices get deleted + * + * @return boolean hook flag + */ + public function onEndDeleteOwnNotice ($user, $notice) + { + $profile = $user->getProfile (); + + // Only distribute local users' delete actions, remote users + // will have already distributed theirs. + if (!$profile->isLocal ()) { + return true; + } + + $other = array (); + foreach ($notice->getAttentionProfileIDs () as $to_id) { + try { + $other[] = Activitypub_profile::from_profile (Profile::getById ($to_id)); + } catch (Exception $e) { + // Local user can be ignored + } + } + $postman = new Activitypub_postman ($profile, $other); + + $postman->delete ($notice); + + return true; + } } /** diff --git a/actions/inbox/Delete.php b/actions/inbox/Delete.php index 44a3936..19cb891 100644 --- a/actions/inbox/Delete.php +++ b/actions/inbox/Delete.php @@ -30,7 +30,7 @@ if (!defined ('GNUSOCIAL')) { } try { - Activitypub_notice::getByUri ($data->object)->deleteAs ($actor_profile); + Activitypub_notice::getKV ("url", $data->object)->deleteAs ($actor_profile); $res = array ("@context" => "https://www.w3.org/ns/activitystreams", "type" => "Delete", "actor" => $data->actor, diff --git a/utils/postman.php b/utils/postman.php index 347c7c6..fca622d 100644 --- a/utils/postman.php +++ b/utils/postman.php @@ -96,7 +96,7 @@ class Activitypub_postman /** * Send a Like notification to remote instances holding the notice - * + * * @param Notice $notice */ public function like ($notice) @@ -113,7 +113,7 @@ class Activitypub_postman /** * Send a Undo Like notification to remote instances holding the notice - * + * * @param Notice $notice */ public function undo_like ($notice) @@ -125,20 +125,43 @@ class Activitypub_postman "type" => "Like", "object" => $notice->getUrl () ) - ); + ); $this->client->setBody (json_encode ($data)); foreach ($this->to_inbox () as $inbox) { $this->client->post ($inbox, $this->headers); } } + /** + * Send a Delete notification to remote instances holding the notice + * + * @param Notice $notice + */ + public function delete ($notice) + { + $data = array ("@context" => "https://www.w3.org/ns/activitystreams", + "type" => "Delete", + "actor" => $this->actor->getUrl (), + "object" => $notice->getUrl () + ); + $this->client->setBody (json_encode ($data)); + foreach ($this->to_inbox () as $inbox) { + $this->client->post ($inbox, $this->headers); + } + } + + /** + * Clean list of inboxes to deliver messages + * + * @return array To Inbox URLs + */ private function to_inbox () { $to_inboxes = array (); foreach ($this->to as $to_profile) { $to_inboxes[] = $to_profile->get_inbox (); } - + return array_unique ($to_inboxes); } }