From 4c9061827cdf8274be7ee3b2caf8cbf1b3c28b59 Mon Sep 17 00:00:00 2001 From: n1rwana Date: Tue, 15 Aug 2023 11:52:54 +0300 Subject: [PATCH] =?UTF-8?q?[Wall]=20=D0=A1=D0=BF=D0=B8=D1=81=D0=BE=D0=BA?= =?UTF-8?q?=20=D0=BB=D0=B0=D0=B9=D0=BA=D0=BD=D1=83=D0=B2=D1=88=D0=B8=D1=85?= =?UTF-8?q?=20=D0=B8=20=D0=BF=D0=BE=D0=B4=D0=B5=D0=BB=D0=B8=D0=B2=D1=88?= =?UTF-8?q?=D0=B8=D1=85=D1=81=D1=8F=20=D0=B7=D0=B0=D0=BF=D0=B8=D1=81=D1=8C?= =?UTF-8?q?=D1=8E/=D0=BA=D0=BE=D0=BC=D0=BC=D0=B5=D0=BD=D1=82=D0=B0=D1=80?= =?UTF-8?q?=D0=B8=D0=B5=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Web/Models/Entities/Postable.php | 19 ++++++ Web/Presenters/WallPresenter.php | 62 ++++++++++++++++++- Web/Presenters/templates/Photos/Photo.xml | 1 - .../templates/components/comment.xml | 2 +- .../templates/components/post/oldpost.xml | 6 +- Web/routes.yml | 6 ++ Web/static/js/al_wall.js | 43 ++++++++++++- 7 files changed, 132 insertions(+), 7 deletions(-) diff --git a/Web/Models/Entities/Postable.php b/Web/Models/Entities/Postable.php index 23981cc1..bc59e7b1 100644 --- a/Web/Models/Entities/Postable.php +++ b/Web/Models/Entities/Postable.php @@ -1,5 +1,6 @@ get($like->origin); } + + function getReposters(): \Traversable + { + $sel = $this->getRecord() + ->related("attachments.attachable_id") + ->where([ + "attachable_type" => get_class($this), + "attachable_id" => $this->getId(), + "target_type" => get_class(new Post), + ]); + + foreach ($sel as $repost) { + $post = (new Posts)->get($repost->target_id); + if ($post && !$post->isDeleted()) { + yield $post->getOwner(); + } + } + } function isAnonymous(): bool { diff --git a/Web/Presenters/WallPresenter.php b/Web/Presenters/WallPresenter.php index 3e115ec7..c900f480 100644 --- a/Web/Presenters/WallPresenter.php +++ b/Web/Presenters/WallPresenter.php @@ -3,7 +3,7 @@ namespace openvk\Web\Presenters; use openvk\Web\Models\Exceptions\TooMuchOptionsException; use openvk\Web\Models\Entities\{Poll, Post, Photo, Video, Club, User}; use openvk\Web\Models\Entities\Notifications\{MentionNotification, RepostNotification, WallPostNotification}; -use openvk\Web\Models\Repositories\{Posts, Users, Clubs, Albums, Notes}; +use openvk\Web\Models\Repositories\{Comments, Posts, Users, Clubs, Albums, Notes}; use Chandler\Database\DatabaseConnection; use Nette\InvalidStateException as ISE; use Bhaktaraz\RSSGenerator\Item; @@ -498,4 +498,64 @@ final class WallPresenter extends OpenVKPresenter # TODO localize message based on language and ?act=(un)pin $this->flashFail("succ", tr("information_-1"), tr("changes_saved_comment")); } + + private function fetchLikers($object): array + { + if (!$object || $object->isDeleted()) + return ["success" => false, "error" => "Объект не найден"]; + + $response = []; + foreach ($object->getLikers() as $liker) { + $liker = [ + "url" => $liker->getURL(), + "fname" => $liker->getFirstName(), + "lname" => $liker->getLastName(), + "avatar" => $liker->getAvatarURL() + ]; + + if (!in_array($liker, $response)) { + $response[] = $liker; + } + } + + return ["success" => true, "payload" => [count($response), $response]]; + } + + function renderLikers(int $wall, int $post_id): void + { + $this->returnJson($this->fetchLikers($this->posts->getPostById($wall, $post_id))); + } + + function renderReposters(int $wall, int $post_id): void + { + $post = $this->posts->getPostById($wall, $post_id); + if (!$post || $post->isDeleted()) { + $this->returnJson(["success" => false, "error" => "Запись не найдена"]); + } + + $response = []; + foreach ($post->getReposters() as $reposter) { + $_reposter = $reposter instanceof User ? [ + "fname" => $reposter->getFirstName(), + "lname" => $reposter->getLastName() + ] : [ + "fname" => $reposter->getCanonicalName(), + "lname" => "" + ]; + + $_reposter["url"] = $reposter->getURL(); + $_reposter["avatar"] = $reposter->getAvatarURL(); + + if (!in_array($_reposter, $response)) { + $response[] = $_reposter; + } + } + + $this->returnJson(["success" => true, "payload" => [count($response), $response]]); + } + + function renderCommentLikers(int $comment_id): void + { + $this->returnJson($this->fetchLikers((new Comments)->get($comment_id))); + } } diff --git a/Web/Presenters/templates/Photos/Photo.xml b/Web/Presenters/templates/Photos/Photo.xml index 047f382a..666f1ecb 100644 --- a/Web/Presenters/templates/Photos/Photo.xml +++ b/Web/Presenters/templates/Photos/Photo.xml @@ -49,7 +49,6 @@ {_edit} {_delete} - {_"open_original"} {_report}