ActivityPub: Add support for avatars, verify barges and statuses

This commit is contained in:
veselcraft 2021-12-28 21:00:23 +03:00
parent 57d4f9da2d
commit 2fa2a61057
No known key found for this signature in database
GPG key ID: AED66BC1AC628A4E
4 changed files with 20 additions and 10 deletions

View file

@ -109,18 +109,18 @@ class User extends RowModel
return ovk_scheme(true) . $_SERVER["SERVER_NAME"] . "/id" . $this->getId(); 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"]; $serverUrl = ovk_scheme(true) . $_SERVER["SERVER_NAME"];
if($this->getRecord()->deleted) 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()) else if($this->isBanned())
return "$serverUrl/assets/packages/static/openvk/img/banned.jpg"; return "$serverUrl/assets/packages/static/openvk/img/banned.jpg";
$avPhoto = $this->getAvatarPhoto(); $avPhoto = $this->getAvatarPhoto();
if(is_null($avPhoto)) 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 else
return $avPhoto->getURL(); return $avPhoto->getURL();
} }

View file

@ -59,11 +59,9 @@ final class ActivityPubPresenter extends OpenVKPresenter
$response->openRegistrations = OPENVK_ROOT_CONF['openvk']['preferences']['registration']['enable']; $response->openRegistrations = OPENVK_ROOT_CONF['openvk']['preferences']['registration']['enable'];
$response->software = array('name' => 'openvk', $response->software = array('name' => 'openvk',
'version' => OPENVK_VERSION); 'version' => OPENVK_VERSION);
$response->usage = array('localPosts' => $stats->posts, $response->usage = array('localPosts' => $stats->posts,
'localComments' => $stats->comments, 'localComments' => $stats->comments,
'users' => array( 'users' => array('total' => $stats->all));
'total' => $stats->all
));
$response->metadata = (object)array(); $response->metadata = (object)array();
$this->returnJson((array) $response); $this->returnJson((array) $response);

View file

@ -301,6 +301,8 @@ abstract class OpenVKPresenter extends SimplePresenter
"@id": "sm:groups", "@id": "sm:groups",
"@type": "@id" "@type": "@id"
}, },
"verified": "sm:verified",
"status": "sm:status",
"vcard": "http://www.w3.org/2006/vcard/ns#" "vcard": "http://www.w3.org/2006/vcard/ns#"
}, },
"https://w3id.org/security/v1" "https://w3id.org/security/v1"

View file

@ -35,6 +35,7 @@ final class UserPresenter extends OpenVKPresenter
/* ActivityPub quirks :DDDD */ /* ActivityPub quirks :DDDD */
if($this->isActivityPubClient()) { if($this->isActivityPubClient()) {
$objUser = array( $objUser = array(
"@context" => $this->getPersonContext(),
"type" => "Person", "type" => "Person",
"id" => $user->getFullURL(true), "id" => $user->getFullURL(true),
"name" => $user->getFullName(), "name" => $user->getFullName(),
@ -55,12 +56,21 @@ final class UserPresenter extends OpenVKPresenter
"middleName" => $user->getPseudo(), // Unlike Smithereen, the Middle name in OpenVK is a Nickname "middleName" => $user->getPseudo(), // Unlike Smithereen, the Middle name in OpenVK is a Nickname
"vcard:bday" => $user->getBirthday()->format('%Y-%m-%d'), "vcard:bday" => $user->getBirthday()->format('%Y-%m-%d'),
"gender" => "http://schema.org#" . $user->isFemale() ? "Male" : "Female", "gender" => "http://schema.org#" . $user->isFemale() ? "Male" : "Female",
"verified" => $user->isVerified(),
"status" => $user->getStatus(),
"supportsFriendRequests" => true, "supportsFriendRequests" => true,
"friends" => ovk_scheme(true) . $_SERVER['SERVER_NAME'] . "/friends" . $user->getId(), "friends" => ovk_scheme(true) . $_SERVER['SERVER_NAME'] . "/friends" . $user->getId(),
"groups" => ovk_scheme(true) . $_SERVER['SERVER_NAME'] . "/groups" . $user->getId(), "groups" => ovk_scheme(true) . $_SERVER['SERVER_NAME'] . "/groups" . $user->getId()
"@context" => $this->getPersonContext()
); );
if($user->getAvatarUrl(true) !== null) {
$objUser['image'] = array(
"type" => "Image",
"mediaType" => "image/jpg",
"url" => $user->getAvatarUrl(true)
);
}
$this->returnJson($objUser); $this->returnJson($objUser);
} }