forked from GNUsocial/gnu-social
[ActivityPub] Fix bug introduced with 4d171b27
Too few arguments to function Activitypub_notice::create_notice()
This commit is contained in:
parent
08283f6c54
commit
3a2ec3ef9c
@ -110,11 +110,27 @@ class ActivityPubPlugin extends Plugin
|
|||||||
|
|
||||||
if ($grab_online) {
|
if ($grab_online) {
|
||||||
/* Online Grabbing */
|
/* Online Grabbing */
|
||||||
$client = new HTTPClient();
|
$client = new HTTPClient();
|
||||||
$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(
|
||||||
['action' => 'apActorProfile'],
|
'user/:id',
|
||||||
['id' => '[0-9]+'],
|
['action' => 'apActorProfile'],
|
||||||
true,
|
['id' => '[0-9]+'],
|
||||||
$acceptHeaders);
|
true,
|
||||||
|
$acceptHeaders
|
||||||
|
);
|
||||||
|
|
||||||
$m->connect(':nickname',
|
$m->connect(
|
||||||
['action' => 'apActorProfile'],
|
':nickname',
|
||||||
['nickname' => Nickname::DISPLAY_FMT],
|
['action' => 'apActorProfile'],
|
||||||
true,
|
['nickname' => Nickname::DISPLAY_FMT],
|
||||||
$acceptHeaders);
|
true,
|
||||||
|
$acceptHeaders
|
||||||
|
);
|
||||||
|
|
||||||
$m->connect(':nickname/',
|
$m->connect(
|
||||||
['action' => 'apActorProfile'],
|
':nickname/',
|
||||||
['nickname' => Nickname::DISPLAY_FMT],
|
['action' => 'apActorProfile'],
|
||||||
true,
|
['nickname' => Nickname::DISPLAY_FMT],
|
||||||
$acceptHeaders);
|
true,
|
||||||
|
$acceptHeaders
|
||||||
|
);
|
||||||
|
|
||||||
$m->connect('notice/:id',
|
$m->connect(
|
||||||
['action' => 'apNotice'],
|
'notice/:id',
|
||||||
['id' => '[0-9]+'],
|
['action' => 'apNotice'],
|
||||||
true,
|
['id' => '[0-9]+'],
|
||||||
$acceptHeaders);
|
true,
|
||||||
|
$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();
|
||||||
@ -273,8 +298,8 @@ class ActivityPubPlugin extends Plugin
|
|||||||
// if we're replying unlisted/followers-only notices received by AP
|
// if we're replying unlisted/followers-only notices received by AP
|
||||||
// or replying to replies of such notices, then we make sure to set
|
// or replying to replies of such notices, then we make sure to set
|
||||||
// the correct type flag.
|
// the correct type flag.
|
||||||
if ( ($parent->source === 'ActivityPub' && $is_local === Notice::GATEWAY) ||
|
if (($parent->source === 'ActivityPub' && $is_local === Notice::GATEWAY) ||
|
||||||
($parent->source === 'web' && $is_local === Notice::LOCAL_NONPUBLIC) ) {
|
($parent->source === 'web' && $is_local === Notice::LOCAL_NONPUBLIC)) {
|
||||||
$this->log(LOG_INFO, "Enforcing type flag LOCAL_NONPUBLIC for new notice");
|
$this->log(LOG_INFO, "Enforcing type flag LOCAL_NONPUBLIC for new notice");
|
||||||
$notice->is_local = Notice::LOCAL_NONPUBLIC;
|
$notice->is_local = Notice::LOCAL_NONPUBLIC;
|
||||||
}
|
}
|
||||||
@ -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
|
||||||
@ -551,7 +578,7 @@ class ActivityPubPlugin extends Plugin
|
|||||||
$text,
|
$text,
|
||||||
$wmatches,
|
$wmatches,
|
||||||
PREG_OFFSET_CAPTURE
|
PREG_OFFSET_CAPTURE
|
||||||
);
|
);
|
||||||
if ($result === false) {
|
if ($result === false) {
|
||||||
common_log(LOG_ERR, __METHOD__ . ': Error parsing webfinger IDs from text (preg_last_error=='.preg_last_error().').');
|
common_log(LOG_ERR, __METHOD__ . ': Error parsing webfinger IDs from text (preg_last_error=='.preg_last_error().').');
|
||||||
return [];
|
return [];
|
||||||
@ -579,7 +606,7 @@ class ActivityPubPlugin extends Plugin
|
|||||||
$text,
|
$text,
|
||||||
$wmatches,
|
$wmatches,
|
||||||
PREG_OFFSET_CAPTURE
|
PREG_OFFSET_CAPTURE
|
||||||
);
|
);
|
||||||
if ($result === false) {
|
if ($result === false) {
|
||||||
common_log(LOG_ERR, __METHOD__ . ': Error parsing profile URL mentions from text (preg_last_error=='.preg_last_error().').');
|
common_log(LOG_ERR, __METHOD__ . ': Error parsing profile URL mentions from text (preg_last_error=='.preg_last_error().').');
|
||||||
return [];
|
return [];
|
||||||
@ -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
|
||||||
|
@ -125,9 +125,9 @@ class Activitypub_notice
|
|||||||
*/
|
*/
|
||||||
public static function create_notice(array $object, Profile $actor_profile, bool $directMessage = false): Notice
|
public static function create_notice(array $object, Profile $actor_profile, bool $directMessage = false): Notice
|
||||||
{
|
{
|
||||||
$id = $object['id']; // int
|
$id = $object['id']; // int
|
||||||
$url = isset($object['url']) ? $object['url'] : $id; // string
|
$url = isset($object['url']) ? $object['url'] : $id; // string
|
||||||
$content = $object['content']; // string
|
$content = $object['content']; // string
|
||||||
|
|
||||||
// possible keys: ['inReplyTo', 'latitude', 'longitude']
|
// possible keys: ['inReplyTo', 'latitude', 'longitude']
|
||||||
$settings = [];
|
$settings = [];
|
||||||
|
Loading…
Reference in New Issue
Block a user