[ActivityPub][QUEUES] Handle Create (AS1 POST) verb properly

Fixes a bug introduced in e504d13120
This commit is contained in:
t3nma 2020-08-03 18:21:47 +01:00
parent a38c608420
commit 1675916fda
1 changed files with 54 additions and 51 deletions

View File

@ -68,11 +68,16 @@ class ActivityPubQueueHandler extends QueueHandler
common_log(LOG_ERR, "Ignoring distribution of notice:{$notice->id}: activity source"); common_log(LOG_ERR, "Ignoring distribution of notice:{$notice->id}: activity source");
return true; return true;
} }
$other = Activitypub_profile::from_profile_collection( $other = Activitypub_profile::from_profile_collection(
$notice->getAttentionProfiles() $notice->getAttentionProfiles()
); );
// Handling a Create?
if (ActivityUtils::compareVerbs($notice->verb, [ActivityVerb::POST])) {
return $this->handle_create($profile, $notice, $other);
}
// Handling a Like? // Handling a Like?
if (ActivityUtils::compareVerbs($notice->verb, [ActivityVerb::FAVORITE])) { if (ActivityUtils::compareVerbs($notice->verb, [ActivityVerb::FAVORITE])) {
return $this->onEndFavorNotice($profile, $notice, $other); return $this->onEndFavorNotice($profile, $notice, $other);
@ -88,42 +93,66 @@ class ActivityPubQueueHandler extends QueueHandler
return $this->onStartDeleteOwnNotice($profile, $notice, $other); return $this->onStartDeleteOwnNotice($profile, $notice, $other);
} }
return true;
}
private function handle_create($profile, $notice, $other)
{
// Handling a reply? // Handling a reply?
if ($notice->reply_to) { if ($notice->reply_to) {
return $this->handle_reply($profile, $notice, $other); try {
$parent_notice = $notice->getParent();
try {
$other[] = Activitypub_profile::from_profile($parent_notice->getProfile());
} catch (Exception $e) {
// Local user can be ignored
}
foreach ($parent_notice->getAttentionProfiles() as $mention) {
try {
$other[] = Activitypub_profile::from_profile($mention);
} catch (Exception $e) {
// Local user can be ignored
}
}
} 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()
);
}
} }
// Handling an Announce? // Handling an Announce?
if ($notice->isRepeat()) { if ($notice->isRepeat()) {
return $this->handle_announce($profile, $notice, $other); $repeated_notice = Notice::getKV('id', $notice->repeat_of);
} if ($repeated_notice instanceof Notice) {
$other = array_merge(
$other,
Activitypub_profile::from_profile_collection(
$repeated_notice->getAttentionProfiles()
)
);
return true;
}
private function handle_reply($profile, $notice, $other)
{
try {
$parent_notice = $notice->getParent();
try {
$other[] = Activitypub_profile::from_profile($parent_notice->getProfile());
} catch (Exception $e) {
// Local user can be ignored
}
foreach ($parent_notice->getAttentionProfiles() as $mention) {
try { try {
$other[] = Activitypub_profile::from_profile($mention); $other[] = Activitypub_profile::from_profile(
$repeated_notice->getProfile()
);
} catch (Exception $e) { } catch (Exception $e) {
// Local user can be ignored // Local user can be ignored
} }
// That was it
$postman = new Activitypub_postman($profile, $other);
$postman->announce($repeated_notice);
} }
} catch (NoParentNoticeException $e) {
// This is not a reply to something (has no parent) // either made the announce or found nothing to repeat
} catch (NoResultException $e) { return true;
// Parent author's profile not found! Complain louder?
common_log(LOG_ERR, "Parent notice's author not found: ".$e->getMessage());
} }
// That was it // That was it
@ -132,32 +161,6 @@ class ActivityPubQueueHandler extends QueueHandler
return true; return true;
} }
private function handle_announce($profile, $notice, $other)
{
$repeated_notice = Notice::getKV('id', $notice->repeat_of);
if ($repeated_notice instanceof Notice) {
$other = array_merge(
$other,
Activitypub_profile::from_profile_collection(
$repeated_notice->getAttentionProfiles()
)
);
try {
$other[] = Activitypub_profile::from_profile($repeated_notice->getProfile());
} catch (Exception $e) {
// Local user can be ignored
}
// That was it
$postman = new Activitypub_postman($profile, $other);
$postman->announce($repeated_notice);
}
// either made the announce or found nothing to repeat
return true;
}
/** /**
* Notify remote users when their notices get favourited. * Notify remote users when their notices get favourited.
* *