[ActivityPub] Fix bug introduced with 4d171b27

Too few arguments to function Activitypub_notice::create_notice()
This commit is contained in:
Diogo Cordeiro 2020-07-07 17:57:48 +01:00 committed by Diogo Peralta Cordeiro
parent c461030066
commit b5180d6096
2 changed files with 64 additions and 35 deletions

View File

@ -114,7 +114,23 @@ class ActivityPubPlugin extends Plugin
$response = $client->get($url, ACTIVITYPUB_HTTP_CLIENT_HEADERS); $response = $client->get($url, ACTIVITYPUB_HTTP_CLIENT_HEADERS);
$object = json_decode($response->getBody(), true); $object = json_decode($response->getBody(), true);
if (Activitypub_notice::validate_note($object)) { if (Activitypub_notice::validate_note($object)) {
return Activitypub_notice::create_notice($object); // Okay, we've found a valid note object!
// Now we need to find the Actor who authored it
// The right way would be to grab attributed to and check its outbox
// But that would be outright inefficient
// Hence, let's just compare the domain names...
if (isset($object['attributedTo'])) {
$acclaimed_actor_profile = ActivityPub_explorer::get_profile_from_url($object['attributedTo']);
} elseif (isset($object['actor'])) {
$acclaimed_actor_profile = ActivityPub_explorer::get_profile_from_url($object['actor']);
} else {
throw new Exception("A notice can't be created without an actor.");
}
if (parse_url($acclaimed_actor_profile->getUri(), PHP_URL_HOST) == parse_url($object['id'], PHP_URL_HOST)) {
return Activitypub_notice::create_notice($object, $acclaimed_actor_profile);
} else {
throw new Exception("The acclaimed actor didn't create this note.");
}
} else { } else {
throw new Exception("Valid ActivityPub Notice object but unsupported by GNU social."); throw new Exception("Valid ActivityPub Notice object but unsupported by GNU social.");
} }
@ -140,29 +156,37 @@ class ActivityPubPlugin extends Plugin
'application/ld+json' => 3 'application/ld+json' => 3
]; ];
$m->connect('user/:id', $m->connect(
'user/:id',
['action' => 'apActorProfile'], ['action' => 'apActorProfile'],
['id' => '[0-9]+'], ['id' => '[0-9]+'],
true, true,
$acceptHeaders); $acceptHeaders
);
$m->connect(':nickname', $m->connect(
':nickname',
['action' => 'apActorProfile'], ['action' => 'apActorProfile'],
['nickname' => Nickname::DISPLAY_FMT], ['nickname' => Nickname::DISPLAY_FMT],
true, true,
$acceptHeaders); $acceptHeaders
);
$m->connect(':nickname/', $m->connect(
':nickname/',
['action' => 'apActorProfile'], ['action' => 'apActorProfile'],
['nickname' => Nickname::DISPLAY_FMT], ['nickname' => Nickname::DISPLAY_FMT],
true, true,
$acceptHeaders); $acceptHeaders
);
$m->connect('notice/:id', $m->connect(
'notice/:id',
['action' => 'apNotice'], ['action' => 'apNotice'],
['id' => '[0-9]+'], ['id' => '[0-9]+'],
true, true,
$acceptHeaders); $acceptHeaders
);
$m->connect( $m->connect(
'user/:id/liked.json', 'user/:id/liked.json',
@ -240,7 +264,7 @@ class ActivityPubPlugin extends Plugin
* @param Array &$transports list of transports to queue for * @param Array &$transports list of transports to queue for
* @return bool event hook return * @return bool event hook return
*/ */
public function onStartEnqueueNotice(Notice $notice, Array &$transports): bool public function onStartEnqueueNotice(Notice $notice, array &$transports): bool
{ {
try { try {
$id = $notice->getID(); $id = $notice->getID();
@ -264,7 +288,8 @@ class ActivityPubPlugin extends Plugin
* @param Notice &$notice notice to be saved * @param Notice &$notice notice to be saved
* @return bool event hook return * @return bool event hook return
*/ */
public function onStartNoticeSave(Notice &$notice): bool { public function onStartNoticeSave(Notice &$notice): bool
{
if ($notice->reply_to) { if ($notice->reply_to) {
try { try {
$parent = $notice->getParent(); $parent = $notice->getParent();
@ -293,7 +318,8 @@ class ActivityPubPlugin extends Plugin
* @param array &$recipients * @param array &$recipients
* @return void * @return void
*/ */
public function onFillDirectMessageRecipients(User $current, array &$recipients): void { public function onFillDirectMessageRecipients(User $current, array &$recipients): void
{
try { try {
$subs = Activitypub_profile::getSubscribed($current->getProfile()); $subs = Activitypub_profile::getSubscribed($current->getProfile());
foreach ($subs as $sub) { foreach ($subs as $sub) {
@ -317,7 +343,8 @@ class ActivityPubPlugin extends Plugin
* @param Profile $recipient * @param Profile $recipient
* @return bool hook return value * @return bool hook return value
*/ */
public function onDirectMessageProfilePageActions(Profile $recipient): bool { public function onDirectMessageProfilePageActions(Profile $recipient): bool
{
$to = Activitypub_profile::getKV('profile_id', $recipient->getID()); $to = Activitypub_profile::getKV('profile_id', $recipient->getID());
if ($to instanceof Activitypub_profile) { if ($to instanceof Activitypub_profile) {
return false; // we can validate this profile, signal it return false; // we can validate this profile, signal it
@ -779,7 +806,8 @@ class ActivityPubPlugin extends Plugin
* @throws HTTP_Request2_Exception * @throws HTTP_Request2_Exception
* @author Diogo Cordeiro <diogo@fc.up.pt> * @author Diogo Cordeiro <diogo@fc.up.pt>
*/ */
public function onStartSubscribe(Profile $profile, Profile $other) { public function onStartSubscribe(Profile $profile, Profile $other)
{
if (!$profile->isLocal()) { if (!$profile->isLocal()) {
return true; return true;
} }
@ -839,7 +867,8 @@ class ActivityPubPlugin extends Plugin
* @param Notice $message * @param Notice $message
* @return void * @return void
*/ */
public function onSendDirectMessage(Notice $message): void { public function onSendDirectMessage(Notice $message): void
{
$from = $message->getProfile(); $from = $message->getProfile();
if (!$from->isLocal()) { if (!$from->isLocal()) {
// nothing to do // nothing to do