Add Delete delivery and some minor bug fixes
This commit is contained in:
parent
2d4e634fad
commit
a5b56b3089
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user