[ActivityPub] Ensuring Notice Favor/Disfavor
ActivityPubPlugin: - Minor re-write of favor/disfavor event handlers Activitypub_postman: like/undo-like: - fix proper getUrl() call misc: - make all activities accumulate errors (may be needed later) and log some information about it
This commit is contained in:
parent
233bdf57ac
commit
87423a0191
@ -624,33 +624,32 @@ class ActivityPubPlugin extends Plugin
|
|||||||
}
|
}
|
||||||
|
|
||||||
$other = [];
|
$other = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$other[] = Activitypub_profile::from_profile($notice->getProfile());
|
$other[] = Activitypub_profile::from_profile($notice->getProfile());
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
// Local user can be ignored
|
// Local user can be ignored
|
||||||
}
|
}
|
||||||
foreach ($notice->getAttentionProfiles() as $to_profile) {
|
|
||||||
try {
|
$other = array_merge($other,
|
||||||
$other[] = Activitypub_profile::from_profile($to_profile);
|
Activitypub_profile::from_profile_collection(
|
||||||
} catch (Exception $e) {
|
$notice->getAttentionProfiles()
|
||||||
// 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();
|
||||||
} catch (Exception $e) {
|
|
||||||
// Local user can be ignored
|
try {
|
||||||
}
|
$other[] = Activitypub_profile::from_profile($parent_notice->getProfile());
|
||||||
try {
|
} catch (Exception $e) {
|
||||||
$mentions = $notice->getParent()->getAttentionProfiles();
|
// Local user can be ignored
|
||||||
foreach ($mentions as $to_profile) {
|
|
||||||
try {
|
|
||||||
$other[] = Activitypub_profile::from_profile($to_profile);
|
|
||||||
} catch (Exception $e) {
|
|
||||||
// Local user can be ignored
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$other = array_merge($other,
|
||||||
|
Activitypub_profile::from_profile_collection(
|
||||||
|
$parent_notice->getAttentionProfiles()
|
||||||
|
));
|
||||||
} 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) {
|
||||||
@ -660,7 +659,6 @@ class ActivityPubPlugin extends Plugin
|
|||||||
}
|
}
|
||||||
|
|
||||||
$postman = new Activitypub_postman($profile, $other);
|
$postman = new Activitypub_postman($profile, $other);
|
||||||
|
|
||||||
$postman->like($notice);
|
$postman->like($notice);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -685,33 +683,32 @@ class ActivityPubPlugin extends Plugin
|
|||||||
}
|
}
|
||||||
|
|
||||||
$other = [];
|
$other = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$other[] = Activitypub_profile::from_profile($notice->getProfile());
|
$other[] = Activitypub_profile::from_profile($notice->getProfile());
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
// Local user can be ignored
|
// Local user can be ignored
|
||||||
}
|
}
|
||||||
foreach ($notice->getAttentionProfiles() as $to_profile) {
|
|
||||||
try {
|
$other = array_merge($other,
|
||||||
$other[] = Activitypub_profile::from_profile($to_profile);
|
Activitypub_profile::from_profile_collection(
|
||||||
} catch (Exception $e) {
|
$notice->getAttentionProfiles()
|
||||||
// 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();
|
||||||
} catch (Exception $e) {
|
|
||||||
// Local user can be ignored
|
try {
|
||||||
}
|
$other[] = Activitypub_profile::from_profile($parent_notice->getProfile());
|
||||||
try {
|
} catch (Exception $e) {
|
||||||
$mentions = $notice->getParent()->getAttentionProfiles();
|
// Local user can be ignored
|
||||||
foreach ($mentions as $to_profile) {
|
|
||||||
try {
|
|
||||||
$other[] = Activitypub_profile::from_profile($to_profile);
|
|
||||||
} catch (Exception $e) {
|
|
||||||
// Local user can be ignored
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$other = array_merge($other,
|
||||||
|
Activitypub_profile::from_profile_collection(
|
||||||
|
$parent_notice->getAttentionProfiles()
|
||||||
|
));
|
||||||
} 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) {
|
||||||
@ -721,7 +718,6 @@ class ActivityPubPlugin extends Plugin
|
|||||||
}
|
}
|
||||||
|
|
||||||
$postman = new Activitypub_postman($profile, $other);
|
$postman = new Activitypub_postman($profile, $other);
|
||||||
|
|
||||||
$postman->undo_like($notice);
|
$postman->undo_like($notice);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -215,12 +215,23 @@ class Activitypub_postman
|
|||||||
{
|
{
|
||||||
$data = Activitypub_like::like_to_array(
|
$data = Activitypub_like::like_to_array(
|
||||||
ActivityPubPlugin::actor_uri($this->actor),
|
ActivityPubPlugin::actor_uri($this->actor),
|
||||||
$notice->getUrl()
|
Activitypub_notice::getUrl($notice)
|
||||||
);
|
);
|
||||||
$data = json_encode($data, JSON_UNESCAPED_SLASHES);
|
$data = json_encode($data, JSON_UNESCAPED_SLASHES);
|
||||||
|
|
||||||
foreach ($this->to_inbox() as $inbox) {
|
foreach ($this->to_inbox() as $inbox) {
|
||||||
$this->send($data, $inbox);
|
$res = $this->send($data, $inbox);
|
||||||
|
|
||||||
|
// accummulate errors for later use, if needed
|
||||||
|
if (!($res->getStatus() == 200 || $res->getStatus() == 202 || $res->getStatus() == 409)) {
|
||||||
|
$res_body = json_decode($res->getBody(), true);
|
||||||
|
$errors[] = isset($res_body[0]['error']) ?
|
||||||
|
$res_body[0]['error'] : "An unknown error occurred.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($errors)) {
|
||||||
|
common_log(LOG_ERR, sizeof($errors) . " instance/s failed to handle the like activity!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -238,13 +249,24 @@ class Activitypub_postman
|
|||||||
$data = Activitypub_undo::undo_to_array(
|
$data = Activitypub_undo::undo_to_array(
|
||||||
Activitypub_like::like_to_array(
|
Activitypub_like::like_to_array(
|
||||||
ActivityPubPlugin::actor_uri($this->actor),
|
ActivityPubPlugin::actor_uri($this->actor),
|
||||||
$notice->getUrl()
|
Activitypub_notice::getUrl($notice)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$data = json_encode($data, JSON_UNESCAPED_SLASHES);
|
$data = json_encode($data, JSON_UNESCAPED_SLASHES);
|
||||||
|
|
||||||
foreach ($this->to_inbox() as $inbox) {
|
foreach ($this->to_inbox() as $inbox) {
|
||||||
$this->send($data, $inbox);
|
$res = $this->send($data, $inbox);
|
||||||
|
|
||||||
|
// accummulate errors for later use, if needed
|
||||||
|
if (!($res->getStatus() == 200 || $res->getStatus() == 202 || $res->getStatus() == 409)) {
|
||||||
|
$res_body = json_decode($res->getBody(), true);
|
||||||
|
$errors[] = isset($res_body[0]['error']) ?
|
||||||
|
$res_body[0]['error'] : "An unknown error occurred.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($errors)) {
|
||||||
|
common_log(LOG_ERR, sizeof($errors) . " instance/s failed to handle the undo-like activity!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -267,7 +289,18 @@ class Activitypub_postman
|
|||||||
$data = json_encode($data, JSON_UNESCAPED_SLASHES);
|
$data = json_encode($data, JSON_UNESCAPED_SLASHES);
|
||||||
|
|
||||||
foreach ($this->to_inbox() as $inbox) {
|
foreach ($this->to_inbox() as $inbox) {
|
||||||
$this->send($data, $inbox);
|
$res = $this->send($data, $inbox);
|
||||||
|
|
||||||
|
// accummulate errors for later use, if needed
|
||||||
|
if (!($res->getStatus() == 200 || $res->getStatus() == 202 || $res->getStatus() == 409)) {
|
||||||
|
$res_body = json_decode($res->getBody(), true);
|
||||||
|
$errors[] = isset($res_body[0]['error']) ?
|
||||||
|
$res_body[0]['error'] : "An unknown error occurred.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($errors)) {
|
||||||
|
common_log(LOG_ERR, sizeof($errors) . " instance/s failed to handle the create-note activity!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,7 +321,18 @@ class Activitypub_postman
|
|||||||
$data = json_encode($data, JSON_UNESCAPED_SLASHES);
|
$data = json_encode($data, JSON_UNESCAPED_SLASHES);
|
||||||
|
|
||||||
foreach ($this->to_inbox() as $inbox) {
|
foreach ($this->to_inbox() as $inbox) {
|
||||||
$this->send($data, $inbox);
|
$res = $this->send($data, $inbox);
|
||||||
|
|
||||||
|
// accummulate errors for later use, if needed
|
||||||
|
if (!($res->getStatus() == 200 || $res->getStatus() == 202 || $res->getStatus() == 409)) {
|
||||||
|
$res_body = json_decode($res->getBody(), true);
|
||||||
|
$errors[] = isset($res_body[0]['error']) ?
|
||||||
|
$res_body[0]['error'] : "An unknown error occurred.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($errors)) {
|
||||||
|
common_log(LOG_ERR, sizeof($errors) . " instance/s failed to handle the announce activity!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -312,13 +356,10 @@ class Activitypub_postman
|
|||||||
$data = json_encode($data, JSON_UNESCAPED_SLASHES);
|
$data = json_encode($data, JSON_UNESCAPED_SLASHES);
|
||||||
foreach ($this->to_inbox() as $inbox) {
|
foreach ($this->to_inbox() as $inbox) {
|
||||||
$res = $this->send($data, $inbox);
|
$res = $this->send($data, $inbox);
|
||||||
if (!$res->getStatus() == 200) {
|
if (!($res->getStatus() == 200 || $res->getStatus() == 202 || $res->getStatus() == 409)) {
|
||||||
$res_body = json_decode($res->getBody(), true);
|
$res_body = json_decode($res->getBody(), true);
|
||||||
if (isset($res_body[0]['error'])) {
|
$errors[] = isset($res_body[0]['error']) ?
|
||||||
$errors[] = ($res_body[0]['error']);
|
$res_body[0]['error'] : "An unknown error occurred.";
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$errors[] = ("An unknown error occurred.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!empty($errors)) {
|
if (!empty($errors)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user