mirror of
https://github.com/openvk/openvk
synced 2024-11-15 03:31:18 +03:00
ActivityPub: Add post implementation
Tested on Pleroma
This commit is contained in:
parent
01d7c682fe
commit
966850dc61
2 changed files with 46 additions and 9 deletions
|
@ -46,12 +46,12 @@ final class UserPresenter extends OpenVKPresenter
|
|||
"outbox" => $user->getFullURL() . "/outbox",
|
||||
"followers" => ovk_scheme(true) . $_SERVER['SERVER_NAME'] . "/friends" . $user->getId() . '?act=incoming',
|
||||
"following" => ovk_scheme(true) . $_SERVER['SERVER_NAME'] . "/friends" . $user->getId() . '?act=outcoming',
|
||||
"endpoints" => array("sharedInbox" => ovk_scheme(true) . $_SERVER['SERVER_NAME'] . "/activitypub/sharedInbox"),
|
||||
"publicKey" => array(
|
||||
"endpoints" => ["sharedInbox" => ovk_scheme(true) . $_SERVER['SERVER_NAME'] . "/activitypub/sharedInbox"],
|
||||
"publicKey" => [
|
||||
"id" => $user->getFullURL(true) . "#main-key",
|
||||
"owner" => $user->getFullURL(true),
|
||||
"publicKeyPem" => $this->getKey()
|
||||
),
|
||||
],
|
||||
"wall" => ovk_scheme(true) . $_SERVER['SERVER_NAME'] . "/wall" . $user->getId(),
|
||||
"firstName" => $user->getFirstName(),
|
||||
"lastName" => $user->getLastName(),
|
||||
|
|
|
@ -303,15 +303,50 @@ final class WallPresenter extends OpenVKPresenter
|
|||
|
||||
function renderPost(int $wall, int $post_id): void
|
||||
{
|
||||
$this->assertUserLoggedIn();
|
||||
|
||||
$post = $this->posts->getPostById($wall, $post_id);
|
||||
if(!$post || $post->isDeleted())
|
||||
$this->notFound();
|
||||
|
||||
$this->logPostView($post, $wall);
|
||||
|
||||
$this->template->post = $post;
|
||||
if($this->isActivityPubClient()) {
|
||||
$objPost = array(
|
||||
"type" => "Note",
|
||||
"id" => ovk_scheme(true) . $_SERVER['SERVER_NAME'] . "/wall" . $wall . "_" . $post_id,
|
||||
"attributedTo" => $post->getOwner()->getFullURL(true),
|
||||
"content" => $post->getText(),
|
||||
"published" => $post->getPublicationTime()->format('%Y-%m-%dT%H:%M:%SZ'),
|
||||
"url" => ovk_scheme(true) . $_SERVER['SERVER_NAME'] . "/wall" . $wall . "_" . $post_id,
|
||||
"to" => [
|
||||
"https://www.w3.org/ns/activitystreams#Public"
|
||||
],
|
||||
"cc" => [
|
||||
ovk_scheme(true) . $_SERVER['SERVER_NAME'] . "/friends" . $post->getOwner()->getId() . "?act=incoming"
|
||||
],
|
||||
"replies" => [
|
||||
"type" => "Collection",
|
||||
"id" => ovk_scheme(true) . $_SERVER['SERVER_NAME'] . "/wall" . $wall . "_" . $post_id . "#comments",
|
||||
"first" => [
|
||||
"type" => "CollectionPage",
|
||||
"items" => [
|
||||
],
|
||||
"partOf" => ovk_scheme(true) . $_SERVER['SERVER_NAME'] . "/wall" . $wall . "_" . $post_id . "#comments",
|
||||
"next" => ovk_scheme(true) . $_SERVER['SERVER_NAME'] . "/wall" . $wall . "_" . $post_id . "?p=2#comments"
|
||||
]
|
||||
],
|
||||
"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"
|
||||
)
|
||||
]
|
||||
);
|
||||
|
||||
$this->returnJson($objPost, CT_AP);
|
||||
}
|
||||
|
||||
if ($post->getTargetWall() > 0) {
|
||||
$this->template->wallOwner = (new Users)->get($post->getTargetWall());
|
||||
$this->template->isWallOfGroup = false;
|
||||
|
@ -321,6 +356,8 @@ final class WallPresenter extends OpenVKPresenter
|
|||
$this->template->wallOwner = (new Clubs)->get(abs($post->getTargetWall()));
|
||||
$this->template->isWallOfGroup = true;
|
||||
}
|
||||
|
||||
$this->template->post = $post;
|
||||
$this->template->cCount = $post->getCommentsCount();
|
||||
$this->template->cPage = (int) ($_GET["p"] ?? 1);
|
||||
$this->template->comments = iterator_to_array($post->getComments($this->template->cPage));
|
||||
|
|
Loading…
Reference in a new issue