diff --git a/plugins/ActivityPub/ActivityPubPlugin.php b/plugins/ActivityPub/ActivityPubPlugin.php index 22a11ab1d9..aaa847406e 100644 --- a/plugins/ActivityPub/ActivityPubPlugin.php +++ b/plugins/ActivityPub/ActivityPubPlugin.php @@ -805,37 +805,37 @@ class ActivityPubPlugin extends Plugin return true; } - // Ignore for activity/non-post-verb notices + // Ignore for activity/non-(post/share)-verb notices if (method_exists('ActivityUtils', 'compareVerbs')) { - $is_post_verb = ActivityUtils::compareVerbs( - $notice->verb, - [ActivityVerb::POST] - ); + $is_valid_verb = ActivityUtils::compareVerbs($notice->verb, + [ActivityVerb::POST, + ActivityVerb::SHARE]); } else { - $is_post_verb = ($notice->verb == ActivityVerb::POST ? true : false); + $is_valid_verb = ($notice->verb == ActivityVerb::POST || + $notice->verb == ActivityVerb::SHARE); } - if ($notice->source == 'activity' || !$is_post_verb) { + + if ($notice->source == 'activity' || !$is_valid_verb) { + common_log(LOG_DEBUG, "Ignoring distribution of notice with id {$notice->id} due to invalid Verb"); return true; } - $other = []; - foreach ($notice->getAttentionProfiles() as $mention) { - try { - $other[] = Activitypub_profile::from_profile($mention); - } catch (Exception $e) { - // Local user can be ignored - } - } + $other = Activitypub_profile::from_profile_collection( + $notice->getAttentionProfiles() + ); // Is a reply? if ($notice->reply_to) { try { - $other[] = Activitypub_profile::from_profile($notice->getParent()->getProfile()); - } catch (Exception $e) { - // Local user can be ignored - } - try { - foreach ($notice->getParent()->getAttentionProfiles() as $mention) { + $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) { @@ -854,6 +854,11 @@ class ActivityPubPlugin extends Plugin if ($notice->isRepeat()) { $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) { @@ -863,8 +868,10 @@ class ActivityPubPlugin extends Plugin // That was it $postman = new Activitypub_postman($profile, $other); $postman->announce($repeated_notice); - return true; } + + // either made the announce or found nothing to repeat + return true; } // That was it diff --git a/plugins/ActivityPub/classes/Activitypub_notice.php b/plugins/ActivityPub/classes/Activitypub_notice.php index 883d768c70..368e95b3f7 100644 --- a/plugins/ActivityPub/classes/Activitypub_notice.php +++ b/plugins/ActivityPub/classes/Activitypub_notice.php @@ -72,14 +72,13 @@ class Activitypub_notice extends Managed_DataObject $item = [ '@context' => 'https://www.w3.org/ns/activitystreams', - 'id' => common_local_url('apNotice', ['id' => $notice->getID()]), + 'id' => self::getUrl($notice), 'type' => 'Note', 'published' => str_replace(' ', 'T', $notice->getCreated()).'Z', - 'url' => $notice->getUrl(), + 'url' => self::getUrl($notice), 'attributedTo' => ActivityPubPlugin::actor_uri($profile), 'to' => ['https://www.w3.org/ns/activitystreams#Public'], 'cc' => $cc, - 'atomUri' => $notice->getUrl(), 'conversation' => $notice->getConversationUrl(), 'content' => $notice->getRendered(), 'isLocal' => $notice->isLocal(), @@ -89,8 +88,7 @@ class Activitypub_notice extends Managed_DataObject // Is this a reply? if (!empty($notice->reply_to)) { - $item['inReplyTo'] = common_local_url('apNotice', ['id' => $notice->getID()]); - $item['inReplyToAtomUri'] = Notice::getById($notice->reply_to)->getUrl(); + $item['inReplyTo'] = self::getUrl(Notice::getById($notice->reply_to)); } // Do we have a location for this notice? @@ -135,7 +133,7 @@ class Activitypub_notice extends Managed_DataObject // Ensure Actor Profile if (is_null($actor_profile)) { - $actor_profile = ActivityPub_explorer::get_profile_from_url($object['actor']); + $actor_profile = ActivityPub_explorer::get_profile_from_url($object['attributedTo']); } $act = new Activity(); @@ -192,9 +190,9 @@ class Activitypub_notice extends Managed_DataObject } /* Reject notice if it is too long (without the HTML) - if (Notice::contentTooLong($content)) { - throw new Exception('That\'s too long. Maximum notice size is %d character.'); - }*/ + if (Notice::contentTooLong($content)) { + throw new Exception('That\'s too long. Maximum notice size is %d character.'); + }*/ $actobj = new ActivityObject(); $actobj->type = ActivityObject::NOTE; @@ -249,4 +247,19 @@ class Activitypub_notice extends Managed_DataObject } return true; } + + /** + * Get the original representation URL of a given notice. + * + * @param Notice $notice notice from which to retrieve the URL + * @return string URL + * @author Bruno Casteleiro + */ + public static function getUrl(Notice $notice): string { + if ($notice->isLocal()) { + return common_local_url('apNotice', ['id' => $notice->getID()]); + } else { + return $notice->getUrl(); + } + } } diff --git a/plugins/ActivityPub/classes/Activitypub_profile.php b/plugins/ActivityPub/classes/Activitypub_profile.php index 721ca97f07..9beec0058c 100644 --- a/plugins/ActivityPub/classes/Activitypub_profile.php +++ b/plugins/ActivityPub/classes/Activitypub_profile.php @@ -229,6 +229,20 @@ class Activitypub_profile extends Managed_DataObject return $aprofile; } + public static function from_profile_collection(array $profiles): array { + $ap_profiles = []; + + foreach ($profiles as $profile) { + try { + $ap_profiles[] = self::from_profile($profile); + } catch (Exception $e) { + // Don't mind local profiles + } + } + + return $ap_profiles; + } + /** * Given an existent local profile creates an ActivityPub profile. * One must be careful not to give a user profile to this function diff --git a/plugins/ActivityPub/lib/postman.php b/plugins/ActivityPub/lib/postman.php index 235c551b61..f11ab40454 100644 --- a/plugins/ActivityPub/lib/postman.php +++ b/plugins/ActivityPub/lib/postman.php @@ -283,7 +283,7 @@ class Activitypub_postman { $data = Activitypub_announce::announce_to_array( ActivityPubPlugin::actor_uri($this->actor), - $notice->getUri() + Activitypub_notice::getUrl($notice) ); $data = json_encode($data, JSON_UNESCAPED_SLASHES);