[ActivityPub] Ensuring notice distribution

ActivityPubPlugin:
- Fix of accepted activity verbs to include SHARES
- Add attention profiles to delivery when announcing

Activitypub_notice:
- New local function to retrieve original URL
- Removal of unnecessary 'Atom*' attributes
- Small fix to the ensuring of actor profile

Activitypub_profile:
- New local function to fetch AP profiles from a collection

Activitypub_postman:
- Fix url passed in the announce activity
This commit is contained in:
brunoccast
2019-07-17 16:25:24 +01:00
committed by Diogo Cordeiro
parent 94a4059b4a
commit 1b356d3bf2
4 changed files with 66 additions and 32 deletions

View File

@@ -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 <brunoccast@fc.up.pt>
*/
public static function getUrl(Notice $notice): string {
if ($notice->isLocal()) {
return common_local_url('apNotice', ['id' => $notice->getID()]);
} else {
return $notice->getUrl();
}
}
}

View File

@@ -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