[ActivityPub][QUEUES] Add Like, Undo and Delete
This commit is contained in:
@@ -821,182 +821,6 @@ class ActivityPubPlugin extends Plugin
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify remote users when their notices get favourited.
|
||||
*
|
||||
* @param Profile $profile of local user doing the faving
|
||||
* @param Notice $notice Notice being favored
|
||||
* @return bool return value
|
||||
* @throws HTTP_Request2_Exception
|
||||
* @throws InvalidUrlException
|
||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||
*/
|
||||
public function onEndFavorNotice(Profile $profile, Notice $notice)
|
||||
{
|
||||
// Only distribute local users' favor actions, remote users
|
||||
// will have already distributed theirs.
|
||||
if (!$profile->isLocal()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$other = [];
|
||||
|
||||
try {
|
||||
$other[] = Activitypub_profile::from_profile($notice->getProfile());
|
||||
} catch (Exception $e) {
|
||||
// Local user can be ignored
|
||||
}
|
||||
|
||||
$other = array_merge($other,
|
||||
Activitypub_profile::from_profile_collection(
|
||||
$notice->getAttentionProfiles()
|
||||
));
|
||||
|
||||
if ($notice->reply_to) {
|
||||
try {
|
||||
$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) {
|
||||
// Parent author's profile not found! Complain louder?
|
||||
common_log(LOG_ERR, "Parent notice's author not found: ".$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
$postman = new Activitypub_postman($profile, $other);
|
||||
$postman->like($notice);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify remote users when their notices get de-favourited.
|
||||
*
|
||||
* @param Profile $profile of local user doing the de-faving
|
||||
* @param Notice $notice Notice being favored
|
||||
* @return bool return value
|
||||
* @throws HTTP_Request2_Exception
|
||||
* @throws InvalidUrlException
|
||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||
*/
|
||||
public function onEndDisfavorNotice(Profile $profile, Notice $notice)
|
||||
{
|
||||
// Only distribute local users' favor actions, remote users
|
||||
// will have already distributed theirs.
|
||||
if (!$profile->isLocal()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$other = [];
|
||||
|
||||
try {
|
||||
$other[] = Activitypub_profile::from_profile($notice->getProfile());
|
||||
} catch (Exception $e) {
|
||||
// Local user can be ignored
|
||||
}
|
||||
|
||||
$other = array_merge($other,
|
||||
Activitypub_profile::from_profile_collection(
|
||||
$notice->getAttentionProfiles()
|
||||
));
|
||||
|
||||
if ($notice->reply_to) {
|
||||
try {
|
||||
$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) {
|
||||
// Parent author's profile not found! Complain louder?
|
||||
common_log(LOG_ERR, "Parent notice's author not found: ".$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
$postman = new Activitypub_postman($profile, $other);
|
||||
$postman->undo_like($notice);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify remote users when their notices get deleted
|
||||
*
|
||||
* @param $user
|
||||
* @param $notice
|
||||
* @return boolean hook flag
|
||||
* @throws HTTP_Request2_Exception
|
||||
* @throws InvalidUrlException
|
||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||
*/
|
||||
public function onStartDeleteOwnNotice($user, $notice)
|
||||
{
|
||||
$profile = $user->getProfile();
|
||||
|
||||
// Only distribute local users' delete actions, remote users
|
||||
// will have already distributed theirs.
|
||||
if (!$profile->isLocal()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Handle delete locally either because:
|
||||
// 1. There's no undo-share logic yet
|
||||
// 2. The deleting user has previleges to do so (locally)
|
||||
if ($notice->isRepeat() || ($notice->getProfile()->getID() != $profile->getID())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$other = Activitypub_profile::from_profile_collection(
|
||||
$notice->getAttentionProfiles()
|
||||
);
|
||||
|
||||
if ($notice->reply_to) {
|
||||
try {
|
||||
$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) {
|
||||
// Parent author's profile not found! Complain louder?
|
||||
common_log(LOG_ERR, "Parent notice's author not found: ".$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
$postman = new Activitypub_postman($profile, $other);
|
||||
$postman->delete_note($notice);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify remote followers when a user gets deleted
|
||||
*
|
||||
|
Reference in New Issue
Block a user