ActivityPub: Add post implementation

Tested on Pleroma
This commit is contained in:
veselcraft 2022-02-13 12:49:03 +03:00
parent 01d7c682fe
commit 966850dc61
No known key found for this signature in database
GPG key ID: AED66BC1AC628A4E
2 changed files with 46 additions and 9 deletions

View file

@ -46,12 +46,12 @@ final class UserPresenter extends OpenVKPresenter
"outbox" => $user->getFullURL() . "/outbox", "outbox" => $user->getFullURL() . "/outbox",
"followers" => ovk_scheme(true) . $_SERVER['SERVER_NAME'] . "/friends" . $user->getId() . '?act=incoming', "followers" => ovk_scheme(true) . $_SERVER['SERVER_NAME'] . "/friends" . $user->getId() . '?act=incoming',
"following" => ovk_scheme(true) . $_SERVER['SERVER_NAME'] . "/friends" . $user->getId() . '?act=outcoming', "following" => ovk_scheme(true) . $_SERVER['SERVER_NAME'] . "/friends" . $user->getId() . '?act=outcoming',
"endpoints" => array("sharedInbox" => ovk_scheme(true) . $_SERVER['SERVER_NAME'] . "/activitypub/sharedInbox"), "endpoints" => ["sharedInbox" => ovk_scheme(true) . $_SERVER['SERVER_NAME'] . "/activitypub/sharedInbox"],
"publicKey" => array( "publicKey" => [
"id" => $user->getFullURL(true) . "#main-key", "id" => $user->getFullURL(true) . "#main-key",
"owner" => $user->getFullURL(true), "owner" => $user->getFullURL(true),
"publicKeyPem" => $this->getKey() "publicKeyPem" => $this->getKey()
), ],
"wall" => ovk_scheme(true) . $_SERVER['SERVER_NAME'] . "/wall" . $user->getId(), "wall" => ovk_scheme(true) . $_SERVER['SERVER_NAME'] . "/wall" . $user->getId(),
"firstName" => $user->getFirstName(), "firstName" => $user->getFirstName(),
"lastName" => $user->getLastName(), "lastName" => $user->getLastName(),

View file

@ -303,16 +303,51 @@ final class WallPresenter extends OpenVKPresenter
function renderPost(int $wall, int $post_id): void function renderPost(int $wall, int $post_id): void
{ {
$this->assertUserLoggedIn();
$post = $this->posts->getPostById($wall, $post_id); $post = $this->posts->getPostById($wall, $post_id);
if(!$post || $post->isDeleted()) if(!$post || $post->isDeleted())
$this->notFound(); $this->notFound();
$this->logPostView($post, $wall); $this->logPostView($post, $wall);
$this->template->post = $post; if($this->isActivityPubClient()) {
if ($post->getTargetWall() > 0) { $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->wallOwner = (new Users)->get($post->getTargetWall());
$this->template->isWallOfGroup = false; $this->template->isWallOfGroup = false;
if($this->template->wallOwner->isBanned()) if($this->template->wallOwner->isBanned())
@ -321,10 +356,12 @@ final class WallPresenter extends OpenVKPresenter
$this->template->wallOwner = (new Clubs)->get(abs($post->getTargetWall())); $this->template->wallOwner = (new Clubs)->get(abs($post->getTargetWall()));
$this->template->isWallOfGroup = true; $this->template->isWallOfGroup = true;
} }
$this->template->post = $post;
$this->template->cCount = $post->getCommentsCount(); $this->template->cCount = $post->getCommentsCount();
$this->template->cPage = (int) ($_GET["p"] ?? 1); $this->template->cPage = (int) ($_GET["p"] ?? 1);
$this->template->comments = iterator_to_array($post->getComments($this->template->cPage)); $this->template->comments = iterator_to_array($post->getComments($this->template->cPage));
} }
function renderLike(int $wall, int $post_id): void function renderLike(int $wall, int $post_id): void
{ {