From 2fa2a6105721dddd0af542058742c722510e0c78 Mon Sep 17 00:00:00 2001 From: veselcraft Date: Tue, 28 Dec 2021 21:00:23 +0300 Subject: [PATCH] ActivityPub: Add support for avatars, verify barges and statuses --- Web/Models/Entities/User.php | 6 +++--- Web/Presenters/ActivityPubPresenter.php | 8 +++----- Web/Presenters/OpenVKPresenter.php | 2 ++ Web/Presenters/UserPresenter.php | 14 ++++++++++++-- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/Web/Models/Entities/User.php b/Web/Models/Entities/User.php index 3911bf3c..2afd7453 100644 --- a/Web/Models/Entities/User.php +++ b/Web/Models/Entities/User.php @@ -109,18 +109,18 @@ class User extends RowModel return ovk_scheme(true) . $_SERVER["SERVER_NAME"] . "/id" . $this->getId(); } - function getAvatarUrl(): string + function getAvatarUrl(bool $nullForDel = false): string { $serverUrl = ovk_scheme(true) . $_SERVER["SERVER_NAME"]; if($this->getRecord()->deleted) - return "$serverUrl/assets/packages/static/openvk/img/camera_200.png"; + return $nullForDel ? null : "$serverUrl/assets/packages/static/openvk/img/camera_200.png"; else if($this->isBanned()) return "$serverUrl/assets/packages/static/openvk/img/banned.jpg"; $avPhoto = $this->getAvatarPhoto(); if(is_null($avPhoto)) - return "$serverUrl/assets/packages/static/openvk/img/camera_200.png"; + return $nullForDel ? null : "$serverUrl/assets/packages/static/openvk/img/camera_200.png"; else return $avPhoto->getURL(); } diff --git a/Web/Presenters/ActivityPubPresenter.php b/Web/Presenters/ActivityPubPresenter.php index 3f800114..1cb6320f 100755 --- a/Web/Presenters/ActivityPubPresenter.php +++ b/Web/Presenters/ActivityPubPresenter.php @@ -59,11 +59,9 @@ final class ActivityPubPresenter extends OpenVKPresenter $response->openRegistrations = OPENVK_ROOT_CONF['openvk']['preferences']['registration']['enable']; $response->software = array('name' => 'openvk', 'version' => OPENVK_VERSION); - $response->usage = array('localPosts' => $stats->posts, - 'localComments' => $stats->comments, - 'users' => array( - 'total' => $stats->all - )); + $response->usage = array('localPosts' => $stats->posts, + 'localComments' => $stats->comments, + 'users' => array('total' => $stats->all)); $response->metadata = (object)array(); $this->returnJson((array) $response); diff --git a/Web/Presenters/OpenVKPresenter.php b/Web/Presenters/OpenVKPresenter.php index 621f56de..1c9fdf08 100755 --- a/Web/Presenters/OpenVKPresenter.php +++ b/Web/Presenters/OpenVKPresenter.php @@ -301,6 +301,8 @@ abstract class OpenVKPresenter extends SimplePresenter "@id": "sm:groups", "@type": "@id" }, + "verified": "sm:verified", + "status": "sm:status", "vcard": "http://www.w3.org/2006/vcard/ns#" }, "https://w3id.org/security/v1" diff --git a/Web/Presenters/UserPresenter.php b/Web/Presenters/UserPresenter.php index 39d025f2..0c322212 100644 --- a/Web/Presenters/UserPresenter.php +++ b/Web/Presenters/UserPresenter.php @@ -35,6 +35,7 @@ final class UserPresenter extends OpenVKPresenter /* ActivityPub quirks :DDDD */ if($this->isActivityPubClient()) { $objUser = array( + "@context" => $this->getPersonContext(), "type" => "Person", "id" => $user->getFullURL(true), "name" => $user->getFullName(), @@ -55,11 +56,20 @@ final class UserPresenter extends OpenVKPresenter "middleName" => $user->getPseudo(), // Unlike Smithereen, the Middle name in OpenVK is a Nickname "vcard:bday" => $user->getBirthday()->format('%Y-%m-%d'), "gender" => "http://schema.org#" . $user->isFemale() ? "Male" : "Female", + "verified" => $user->isVerified(), + "status" => $user->getStatus(), "supportsFriendRequests" => true, "friends" => ovk_scheme(true) . $_SERVER['SERVER_NAME'] . "/friends" . $user->getId(), - "groups" => ovk_scheme(true) . $_SERVER['SERVER_NAME'] . "/groups" . $user->getId(), - "@context" => $this->getPersonContext() + "groups" => ovk_scheme(true) . $_SERVER['SERVER_NAME'] . "/groups" . $user->getId() ); + + if($user->getAvatarUrl(true) !== null) { + $objUser['image'] = array( + "type" => "Image", + "mediaType" => "image/jpg", + "url" => $user->getAvatarUrl(true) + ); + } $this->returnJson($objUser); }