2023-07-06 13:20:49 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace openvk\ServiceAPI;
|
|
|
|
use openvk\Web\Models\Entities\User;
|
|
|
|
use openvk\Web\Models\Repositories\Notes as NoteRepo;
|
|
|
|
|
|
|
|
class Notes implements Handler
|
|
|
|
{
|
|
|
|
protected $user;
|
|
|
|
protected $notes;
|
|
|
|
|
|
|
|
function __construct(?User $user)
|
|
|
|
{
|
|
|
|
$this->user = $user;
|
|
|
|
$this->notes = new NoteRepo;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getNote(int $noteId, callable $resolve, callable $reject): void
|
|
|
|
{
|
|
|
|
$note = $this->notes->get($noteId);
|
|
|
|
if(!$note || $note->isDeleted())
|
2023-07-07 14:46:20 +03:00
|
|
|
$reject(83, "Note is gone");
|
2023-07-06 13:20:49 +03:00
|
|
|
|
|
|
|
$noteOwner = $note->getOwner();
|
|
|
|
assert($noteOwner instanceof User);
|
|
|
|
if(!$noteOwner->getPrivacyPermission("notes.read", $this->user))
|
2023-07-07 14:46:20 +03:00
|
|
|
$reject(160, "You don't have permission to access this note");
|
2023-07-06 13:20:49 +03:00
|
|
|
|
|
|
|
$resolve([
|
|
|
|
"title" => $note->getName(),
|
|
|
|
"link" => "/note" . $note->getPrettyId(),
|
|
|
|
"html" => $note->getText(),
|
|
|
|
"created" => (string) $note->getPublicationTime(),
|
|
|
|
"author" => [
|
|
|
|
"name" => $noteOwner->getCanonicalName(),
|
|
|
|
"ava" => $noteOwner->getAvatarUrl(),
|
|
|
|
"link" => $noteOwner->getURL(),
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
2023-07-07 14:46:20 +03:00
|
|
|
}
|