Merge branch 'ostatus' into 'dev'
Beginning of OStatus support, various bug fixes See merge request dansup/ActivityPub!24
This commit is contained in:
commit
f3ebbf472b
@ -151,49 +151,48 @@ class ActivityPubPlugin extends Plugin
|
|||||||
['nickname' => Nickname::DISPLAY_FMT],
|
['nickname' => Nickname::DISPLAY_FMT],
|
||||||
'apActorProfile'
|
'apActorProfile'
|
||||||
);
|
);
|
||||||
|
|
||||||
ActivityPubURLMapperOverwrite::variable(
|
|
||||||
$m,
|
|
||||||
'notice/:id',
|
|
||||||
['id' => '[0-9]+'],
|
|
||||||
'apNotice'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$m->connect(
|
||||||
|
'note/:id.json',
|
||||||
|
['action' => 'apNotice'],
|
||||||
|
['id' => '[0-9]+']
|
||||||
|
);
|
||||||
|
|
||||||
$m->connect(
|
$m->connect(
|
||||||
'user/:id/liked.json',
|
'user/:id/liked.json',
|
||||||
['action' => 'apActorLiked'],
|
['action' => 'apActorLiked'],
|
||||||
['id' => '[0-9]+']
|
['id' => '[0-9]+']
|
||||||
);
|
);
|
||||||
|
|
||||||
$m->connect(
|
$m->connect(
|
||||||
'user/:id/followers.json',
|
'user/:id/followers.json',
|
||||||
['action' => 'apActorFollowers'],
|
['action' => 'apActorFollowers'],
|
||||||
['id' => '[0-9]+']
|
['id' => '[0-9]+']
|
||||||
);
|
);
|
||||||
|
|
||||||
$m->connect(
|
$m->connect(
|
||||||
'user/:id/following.json',
|
'user/:id/following.json',
|
||||||
['action' => 'apActorFollowing'],
|
['action' => 'apActorFollowing'],
|
||||||
['id' => '[0-9]+']
|
['id' => '[0-9]+']
|
||||||
);
|
);
|
||||||
|
|
||||||
$m->connect(
|
$m->connect(
|
||||||
'user/:id/inbox.json',
|
'user/:id/inbox.json',
|
||||||
['action' => 'apInbox'],
|
['action' => 'apInbox'],
|
||||||
['id' => '[0-9]+']
|
['id' => '[0-9]+']
|
||||||
);
|
);
|
||||||
|
|
||||||
$m->connect(
|
$m->connect(
|
||||||
'user/:id/outbox.json',
|
'user/:id/outbox.json',
|
||||||
['action' => 'apActorOutbox'],
|
['action' => 'apActorOutbox'],
|
||||||
['id' => '[0-9]+']
|
['id' => '[0-9]+']
|
||||||
);
|
);
|
||||||
|
|
||||||
$m->connect(
|
$m->connect(
|
||||||
'inbox.json',
|
'inbox.json',
|
||||||
['action' => 'apInbox']
|
['action' => 'apInbox']
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -278,7 +277,7 @@ class ActivityPubPlugin extends Plugin
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Look for profile URLs, with or without scheme:
|
// Look for profile URLs, with or without scheme:
|
||||||
$urls = array();
|
$urls = [];
|
||||||
if (preg_match('!^https?://((?:\w+\.)*\w+(?:\w+\-\w+)*\.\w+(?:/\w+)+)$!', $arg)) {
|
if (preg_match('!^https?://((?:\w+\.)*\w+(?:\w+\-\w+)*\.\w+(?:/\w+)+)$!', $arg)) {
|
||||||
$urls[] = $arg;
|
$urls[] = $arg;
|
||||||
}
|
}
|
||||||
@ -336,7 +335,7 @@ class ActivityPubPlugin extends Plugin
|
|||||||
*/
|
*/
|
||||||
public static function extractUrlMentions($text, $preMention='@')
|
public static function extractUrlMentions($text, $preMention='@')
|
||||||
{
|
{
|
||||||
$wmatches = array();
|
$wmatches = [];
|
||||||
// In the regexp below we need to match / _before_ URL_REGEX_VALID_PATH_CHARS because it otherwise gets merged
|
// In the regexp below we need to match / _before_ URL_REGEX_VALID_PATH_CHARS because it otherwise gets merged
|
||||||
// with the TLD before (but / is in URL_REGEX_VALID_PATH_CHARS anyway, it's just its positioning that is important)
|
// with the TLD before (but / is in URL_REGEX_VALID_PATH_CHARS anyway, it's just its positioning that is important)
|
||||||
$result = preg_match_all(
|
$result = preg_match_all(
|
||||||
@ -386,7 +385,7 @@ class ActivityPubPlugin extends Plugin
|
|||||||
*/
|
*/
|
||||||
public function onEndFindMentions(Profile $sender, $text, &$mentions)
|
public function onEndFindMentions(Profile $sender, $text, &$mentions)
|
||||||
{
|
{
|
||||||
$matches = array();
|
$matches = [];
|
||||||
|
|
||||||
foreach (self::extractWebfingerIds($text, '@') as $wmatch) {
|
foreach (self::extractWebfingerIds($text, '@') as $wmatch) {
|
||||||
list($target, $pos) = $wmatch;
|
list($target, $pos) = $wmatch;
|
||||||
@ -547,7 +546,7 @@ class ActivityPubPlugin extends Plugin
|
|||||||
try {
|
try {
|
||||||
$other = Activitypub_profile::from_profile($other);
|
$other = Activitypub_profile::from_profile($other);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return true;
|
return true; // Let other plugin handle this instead
|
||||||
}
|
}
|
||||||
|
|
||||||
$postman = new Activitypub_postman($profile, array($other));
|
$postman = new Activitypub_postman($profile, array($other));
|
||||||
@ -574,7 +573,7 @@ class ActivityPubPlugin extends Plugin
|
|||||||
try {
|
try {
|
||||||
$other = Activitypub_profile::from_profile($other);
|
$other = Activitypub_profile::from_profile($other);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return true;
|
return true; // Let other plugin handle this instead
|
||||||
}
|
}
|
||||||
|
|
||||||
$postman = new Activitypub_postman($profile, array($other));
|
$postman = new Activitypub_postman($profile, array($other));
|
||||||
@ -585,7 +584,7 @@ class ActivityPubPlugin extends Plugin
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notify remote users when their notices get favorited.
|
* Notify remote users when their notices get favourited.
|
||||||
*
|
*
|
||||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||||
* @param Profile $profile of local user doing the faving
|
* @param Profile $profile of local user doing the faving
|
||||||
@ -600,7 +599,7 @@ class ActivityPubPlugin extends Plugin
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$other = array();
|
$other = [];
|
||||||
try {
|
try {
|
||||||
$other[] = Activitypub_profile::from_profile($notice->getProfile());
|
$other[] = Activitypub_profile::from_profile($notice->getProfile());
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
@ -644,7 +643,7 @@ class ActivityPubPlugin extends Plugin
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notify remote users when their notices get de-favorited.
|
* Notify remote users when their notices get de-favourited.
|
||||||
*
|
*
|
||||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||||
* @param Profile $profile of local user doing the de-faving
|
* @param Profile $profile of local user doing the de-faving
|
||||||
@ -659,7 +658,7 @@ class ActivityPubPlugin extends Plugin
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$other = array();
|
$other = [];
|
||||||
try {
|
try {
|
||||||
$other[] = Activitypub_profile::from_profile($notice->getProfile());
|
$other[] = Activitypub_profile::from_profile($notice->getProfile());
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
@ -718,7 +717,7 @@ class ActivityPubPlugin extends Plugin
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$other = array();
|
$other = [];
|
||||||
|
|
||||||
foreach ($notice->getAttentionProfiles() as $to_profile) {
|
foreach ($notice->getAttentionProfiles() as $to_profile) {
|
||||||
try {
|
try {
|
||||||
@ -771,7 +770,7 @@ class ActivityPubPlugin extends Plugin
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$other = array();
|
$other = [];
|
||||||
try {
|
try {
|
||||||
$other[] = Activitypub_profile::from_profile($notice->getProfile());
|
$other[] = Activitypub_profile::from_profile($notice->getProfile());
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
|
@ -116,7 +116,7 @@ class apActorFollowersAction extends ManagedAction
|
|||||||
* @param int32 $limit
|
* @param int32 $limit
|
||||||
* @return Array of URIs
|
* @return Array of URIs
|
||||||
*/
|
*/
|
||||||
public function generate_followers($profile, $since, $limit)
|
public static function generate_followers($profile, $since, $limit)
|
||||||
{
|
{
|
||||||
/* Fetch Followers */
|
/* Fetch Followers */
|
||||||
try {
|
try {
|
||||||
@ -130,6 +130,7 @@ class apActorFollowersAction extends ManagedAction
|
|||||||
while ($sub->fetch()) {
|
while ($sub->fetch()) {
|
||||||
$subs[] = ActivityPubPlugin::actor_uri($sub);
|
$subs[] = ActivityPubPlugin::actor_uri($sub);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $subs;
|
return $subs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ class Activitypub_notice extends Managed_DataObject
|
|||||||
|
|
||||||
$item = [
|
$item = [
|
||||||
'@context' => 'https://www.w3.org/ns/activitystreams',
|
'@context' => 'https://www.w3.org/ns/activitystreams',
|
||||||
'id' => $notice->getUrl(),
|
'id' => common_local_url('apNotice', ['id' => $notice->getID()]),
|
||||||
'type' => 'Note',
|
'type' => 'Note',
|
||||||
'published' => str_replace(' ', 'T', $notice->getCreated()).'Z',
|
'published' => str_replace(' ', 'T', $notice->getCreated()).'Z',
|
||||||
'url' => $notice->getUrl(),
|
'url' => $notice->getUrl(),
|
||||||
@ -210,7 +210,7 @@ class Activitypub_notice extends Managed_DataObject
|
|||||||
$discovery = new Activitypub_explorer;
|
$discovery = new Activitypub_explorer;
|
||||||
foreach ($mentions as $mention) {
|
foreach ($mentions as $mention) {
|
||||||
try {
|
try {
|
||||||
$mentions_profiles[] = array_merge($mentions_profiles, $discovery->lookup($mention));
|
$mentions_profiles[] = $discovery->lookup($mention)[0];
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
// Invalid actor found, just let it go. // TODO: Fallback to OStatus
|
// Invalid actor found, just let it go. // TODO: Fallback to OStatus
|
||||||
}
|
}
|
||||||
|
@ -239,9 +239,13 @@ class Activitypub_profile extends Managed_DataObject
|
|||||||
*/
|
*/
|
||||||
private static function create_from_local_profile(Profile $profile)
|
private static function create_from_local_profile(Profile $profile)
|
||||||
{
|
{
|
||||||
$url = $profile->getURL();
|
$url = $profile->getUri();
|
||||||
$inboxes = Activitypub_explorer::get_actor_inboxes_uri($url);
|
$inboxes = Activitypub_explorer::get_actor_inboxes_uri($url);
|
||||||
|
|
||||||
|
if ($inboxes == null) {
|
||||||
|
throw new Exception ('This is not an ActivityPub user thus AProfile is politely refusing to proceed.');
|
||||||
|
}
|
||||||
|
|
||||||
$aprofile->created = $aprofile->modified = common_sql_now();
|
$aprofile->created = $aprofile->modified = common_sql_now();
|
||||||
|
|
||||||
$aprofile = new Activitypub_profile;
|
$aprofile = new Activitypub_profile;
|
||||||
|
@ -103,7 +103,7 @@ class Activitypub_inbox_handler
|
|||||||
case 'Like':
|
case 'Like':
|
||||||
case 'Announce':
|
case 'Announce':
|
||||||
if (!filter_var($this->object, FILTER_VALIDATE_URL)) {
|
if (!filter_var($this->object, FILTER_VALIDATE_URL)) {
|
||||||
throw new Exception("Object is not a valid Object URI for Activity.");
|
throw new Exception('Object is not a valid Object URI for Activity.');
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'Undo':
|
case 'Undo':
|
||||||
|
@ -63,15 +63,19 @@ class Activitypub_postman
|
|||||||
public function __construct($from, $to = [])
|
public function __construct($from, $to = [])
|
||||||
{
|
{
|
||||||
$this->actor = $from;
|
$this->actor = $from;
|
||||||
|
|
||||||
$discovery = new Activitypub_explorer();
|
$discovery = new Activitypub_explorer();
|
||||||
$this->to = array_merge(
|
$this->to = $to;
|
||||||
$to,
|
$followers = apActorFollowersAction::generate_followers($this->actor, 0, null);
|
||||||
$discovery->lookup(common_local_url(
|
foreach ($followers as $sub) {
|
||||||
'apActorFollowers',
|
try {
|
||||||
['id' => $from->getID()]
|
$to[]= Activitypub_profile::from_profile($discovery->lookup($sub)[0]);
|
||||||
))
|
} catch (Exception $e) {
|
||||||
);
|
// Not an ActivityPub Remote Follower, let it go
|
||||||
|
}
|
||||||
|
}
|
||||||
unset($discovery);
|
unset($discovery);
|
||||||
|
|
||||||
$this->actor_uri = ActivityPubPlugin::actor_uri($this->actor);
|
$this->actor_uri = ActivityPubPlugin::actor_uri($this->actor);
|
||||||
|
|
||||||
$actor_private_key = new Activitypub_rsa();
|
$actor_private_key = new Activitypub_rsa();
|
||||||
|
Reference in New Issue
Block a user