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;
|
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 {
|
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",
|
$res = array ("@context" => "https://www.w3.org/ns/activitystreams",
|
||||||
"type" => "Delete",
|
"type" => "Delete",
|
||||||
"actor" => $data->actor,
|
"actor" => $data->actor,
|
||||||
|
@ -96,7 +96,7 @@ class Activitypub_postman
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a Like notification to remote instances holding the notice
|
* Send a Like notification to remote instances holding the notice
|
||||||
*
|
*
|
||||||
* @param Notice $notice
|
* @param Notice $notice
|
||||||
*/
|
*/
|
||||||
public function like ($notice)
|
public function like ($notice)
|
||||||
@ -113,7 +113,7 @@ class Activitypub_postman
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a Undo Like notification to remote instances holding the notice
|
* Send a Undo Like notification to remote instances holding the notice
|
||||||
*
|
*
|
||||||
* @param Notice $notice
|
* @param Notice $notice
|
||||||
*/
|
*/
|
||||||
public function undo_like ($notice)
|
public function undo_like ($notice)
|
||||||
@ -125,20 +125,43 @@ class Activitypub_postman
|
|||||||
"type" => "Like",
|
"type" => "Like",
|
||||||
"object" => $notice->getUrl ()
|
"object" => $notice->getUrl ()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$this->client->setBody (json_encode ($data));
|
$this->client->setBody (json_encode ($data));
|
||||||
foreach ($this->to_inbox () as $inbox) {
|
foreach ($this->to_inbox () as $inbox) {
|
||||||
$this->client->post ($inbox, $this->headers);
|
$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 ()
|
private function to_inbox ()
|
||||||
{
|
{
|
||||||
$to_inboxes = array ();
|
$to_inboxes = array ();
|
||||||
foreach ($this->to as $to_profile) {
|
foreach ($this->to as $to_profile) {
|
||||||
$to_inboxes[] = $to_profile->get_inbox ();
|
$to_inboxes[] = $to_profile->get_inbox ();
|
||||||
}
|
}
|
||||||
|
|
||||||
return array_unique ($to_inboxes);
|
return array_unique ($to_inboxes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user