Merge branch 'ostatus' into 'dev'

Beginning of OStatus support, various bug fixes

See merge request dansup/ActivityPub!24
This commit is contained in:
Diogo Cordeiro 2018-08-06 07:10:37 +00:00
commit f3ebbf472b
6 changed files with 55 additions and 47 deletions

View File

@ -151,15 +151,14 @@ class ActivityPubPlugin extends Plugin
['nickname' => Nickname::DISPLAY_FMT],
'apActorProfile'
);
ActivityPubURLMapperOverwrite::variable(
$m,
'notice/:id',
['id' => '[0-9]+'],
'apNotice'
);
}
$m->connect(
'note/:id.json',
['action' => 'apNotice'],
['id' => '[0-9]+']
);
$m->connect(
'user/:id/liked.json',
['action' => 'apActorLiked'],
@ -278,7 +277,7 @@ class ActivityPubPlugin extends Plugin
}
// Look for profile URLs, with or without scheme:
$urls = array();
$urls = [];
if (preg_match('!^https?://((?:\w+\.)*\w+(?:\w+\-\w+)*\.\w+(?:/\w+)+)$!', $arg)) {
$urls[] = $arg;
}
@ -336,7 +335,7 @@ class ActivityPubPlugin extends Plugin
*/
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
// 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(
@ -386,7 +385,7 @@ class ActivityPubPlugin extends Plugin
*/
public function onEndFindMentions(Profile $sender, $text, &$mentions)
{
$matches = array();
$matches = [];
foreach (self::extractWebfingerIds($text, '@') as $wmatch) {
list($target, $pos) = $wmatch;
@ -547,7 +546,7 @@ class ActivityPubPlugin extends Plugin
try {
$other = Activitypub_profile::from_profile($other);
} catch (Exception $e) {
return true;
return true; // Let other plugin handle this instead
}
$postman = new Activitypub_postman($profile, array($other));
@ -574,7 +573,7 @@ class ActivityPubPlugin extends Plugin
try {
$other = Activitypub_profile::from_profile($other);
} catch (Exception $e) {
return true;
return true; // Let other plugin handle this instead
}
$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>
* @param Profile $profile of local user doing the faving
@ -600,7 +599,7 @@ class ActivityPubPlugin extends Plugin
return true;
}
$other = array();
$other = [];
try {
$other[] = Activitypub_profile::from_profile($notice->getProfile());
} 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>
* @param Profile $profile of local user doing the de-faving
@ -659,7 +658,7 @@ class ActivityPubPlugin extends Plugin
return true;
}
$other = array();
$other = [];
try {
$other[] = Activitypub_profile::from_profile($notice->getProfile());
} catch (Exception $e) {
@ -718,7 +717,7 @@ class ActivityPubPlugin extends Plugin
return true;
}
$other = array();
$other = [];
foreach ($notice->getAttentionProfiles() as $to_profile) {
try {
@ -771,7 +770,7 @@ class ActivityPubPlugin extends Plugin
return true;
}
$other = array();
$other = [];
try {
$other[] = Activitypub_profile::from_profile($notice->getProfile());
} catch (Exception $e) {

View File

@ -116,7 +116,7 @@ class apActorFollowersAction extends ManagedAction
* @param int32 $limit
* @return Array of URIs
*/
public function generate_followers($profile, $since, $limit)
public static function generate_followers($profile, $since, $limit)
{
/* Fetch Followers */
try {
@ -130,6 +130,7 @@ class apActorFollowersAction extends ManagedAction
while ($sub->fetch()) {
$subs[] = ActivityPubPlugin::actor_uri($sub);
}
return $subs;
}
}

View File

@ -73,7 +73,7 @@ class Activitypub_notice extends Managed_DataObject
$item = [
'@context' => 'https://www.w3.org/ns/activitystreams',
'id' => $notice->getUrl(),
'id' => common_local_url('apNotice', ['id' => $notice->getID()]),
'type' => 'Note',
'published' => str_replace(' ', 'T', $notice->getCreated()).'Z',
'url' => $notice->getUrl(),
@ -210,7 +210,7 @@ class Activitypub_notice extends Managed_DataObject
$discovery = new Activitypub_explorer;
foreach ($mentions as $mention) {
try {
$mentions_profiles[] = array_merge($mentions_profiles, $discovery->lookup($mention));
$mentions_profiles[] = $discovery->lookup($mention)[0];
} catch (Exception $e) {
// Invalid actor found, just let it go. // TODO: Fallback to OStatus
}

View File

@ -239,9 +239,13 @@ class Activitypub_profile extends Managed_DataObject
*/
private static function create_from_local_profile(Profile $profile)
{
$url = $profile->getURL();
$url = $profile->getUri();
$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 = new Activitypub_profile;

View File

@ -103,7 +103,7 @@ class Activitypub_inbox_handler
case 'Like':
case 'Announce':
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;
case 'Undo':

View File

@ -63,15 +63,19 @@ class Activitypub_postman
public function __construct($from, $to = [])
{
$this->actor = $from;
$discovery = new Activitypub_explorer();
$this->to = array_merge(
$to,
$discovery->lookup(common_local_url(
'apActorFollowers',
['id' => $from->getID()]
))
);
$this->to = $to;
$followers = apActorFollowersAction::generate_followers($this->actor, 0, null);
foreach ($followers as $sub) {
try {
$to[]= Activitypub_profile::from_profile($discovery->lookup($sub)[0]);
} catch (Exception $e) {
// Not an ActivityPub Remote Follower, let it go
}
}
unset($discovery);
$this->actor_uri = ActivityPubPlugin::actor_uri($this->actor);
$actor_private_key = new Activitypub_rsa();