ActivityPub: [Post] add attachment support and Smithereen's target field for wall support

This commit is contained in:
veselcraft 2022-02-13 22:07:49 +03:00
parent 966850dc61
commit 71a4e373d1
No known key found for this signature in database
GPG key ID: AED66BC1AC628A4E
2 changed files with 35 additions and 7 deletions

View file

@ -59,4 +59,11 @@ class Photo extends Media
return $photo;
}
function getDimentions()
{
$hash = $this->getRecord()->hash;
return getimagesize($this->pathFromHash($hash));
}
}

View file

@ -311,6 +311,12 @@ final class WallPresenter extends OpenVKPresenter
if($this->isActivityPubClient()) {
$objPost = array(
"@context" => [
"https://www.w3.org/ns/activitystreams",
(object) array(
"sensitive" => "as:sensitive"
)
],
"type" => "Note",
"id" => ovk_scheme(true) . $_SERVER['SERVER_NAME'] . "/wall" . $wall . "_" . $post_id,
"attributedTo" => $post->getOwner()->getFullURL(true),
@ -335,15 +341,30 @@ final class WallPresenter extends OpenVKPresenter
]
],
"sensitive" => false,
"likes" => ovk_scheme(true) . $_SERVER['SERVER_NAME'] . "/wall" . $wall . "_" . $post_id . "/likes",
"@context" => [
"https://www.w3.org/ns/activitystreams",
(object) array(
"sensitive" => "as:sensitive"
)
]
"likes" => ovk_scheme(true) . $_SERVER['SERVER_NAME'] . "/wall" . $wall . "_" . $post_id . "/likes"
);
if($post->getTargetWall() != $post->getOwner())
{
$objPost["target"] = array(
"type" => "Collection",
"id" => ovk_scheme(true) . $_SERVER['SERVER_NAME'] . "/wall" . $post->getTargetWall(),
"attributedTo" => ovk_scheme(true) . $_SERVER['SERVER_NAME'] . ($post->getTargetWall() > 0 ? "/id" . $post->getTargetWall() : "club" . abs($post->getTargetWall()))
);
}
foreach($post->getChildren() as $attachment) {
if($attachment instanceof \openvk\Web\Models\Entities\Photo) {
$objPost["attachment"][] = array(
"type" => "Image",
"mediaType" => "image/jpeg",
"width" => $attachment->getDimentions()[0],
"height" => $attachment->getDimentions()[1],
"url" => $attachment->getURL()
);
}
}
$this->returnJson($objPost, CT_AP);
}