[ActivityPub][NOTICE] Process attachments

This commit is contained in:
Diogo Cordeiro 2020-08-05 17:21:30 +01:00 committed by Diogo Peralta Cordeiro
parent 4c92cc967b
commit 33721c85cd
2 changed files with 23 additions and 1 deletions

View File

@ -97,7 +97,7 @@ class ActivityPubPlugin extends Plugin
// Look for a local notice (unfortunately GNU social doesn't
// provide this functionality natively)
try {
$candidate = Notice::getByID(intval(substr($url, (strlen(common_local_url('apNotice', ['id' => 0]))-1))));
$candidate = Notice::getByID((int)substr($url, (strlen(common_local_url('apNotice', ['id' => 0]))-1)));
if (common_local_url('apNotice', ['id' => $candidate->getID()]) === $url) { // Sanity check
return $candidate;
} else {

View File

@ -211,6 +211,23 @@ class Activitypub_notice
throw new Exception('That\'s too long. Maximum notice size is %d character.');
}*/
// Attachments (first part)
$attachments = [];
if (isset($object['attachment']) && is_array($object['attachment'])) {
foreach ($object['attachment'] as $attachment) {
if (array_key_exists('type', $attachment) && $attachment['type'] == 'Document') {
try {
// throws exception on failure
$attachment = MediaFile::fromUrl($attachment['url'], $actor_profile, $attachment['name']);
$act->enclosures[] = $attachment->getEnclosure();
$attachments[] = $attachment;
} catch (Exception $e) {
// Whatever.
}
}
}
}
$actobj = new ActivityObject();
$actobj->type = ActivityObject::NOTE;
$actobj->content = strip_tags($content, '<p><b><i><u><a><ul><ol><li>');
@ -220,6 +237,11 @@ class Activitypub_notice
$note = Notice::saveActivity($act, $actor_profile, $options);
// Attachments (last part)
foreach($attachments as $attachment) {
$attachment->attachToNotice($note);
}
return $note;
}