From cf0b4be3fbcdd55826157fd9750563250e7934ad Mon Sep 17 00:00:00 2001 From: mrilyew <99399973+mrilyew@users.noreply.github.com> Date: Fri, 22 Nov 2024 19:34:25 +0300 Subject: [PATCH] feat(wall): add new route /{type}/{id}/likes --- Web/Models/Entities/Comment.php | 5 ++ Web/Models/Entities/Post.php | 5 ++ Web/Models/Entities/Video.php | 5 ++ Web/Presenters/WallPresenter.php | 100 +++++++++-------------- Web/Presenters/templates/Wall/Likers.xml | 51 ++++++++++++ Web/routes.yml | 2 + locales/en.strings | 3 + locales/ru.strings | 3 + 8 files changed, 114 insertions(+), 60 deletions(-) create mode 100644 Web/Presenters/templates/Wall/Likers.xml diff --git a/Web/Models/Entities/Comment.php b/Web/Models/Entities/Comment.php index c0460dd5..acd5d7b5 100644 --- a/Web/Models/Entities/Comment.php +++ b/Web/Models/Entities/Comment.php @@ -28,6 +28,11 @@ class Comment extends Post return $entity; } + function getPageURL(): string + { + return '#'; + } + /** * May return fake owner (group), if flags are [1, (*)] * diff --git a/Web/Models/Entities/Post.php b/Web/Models/Entities/Post.php index e86d5904..dacced18 100644 --- a/Web/Models/Entities/Post.php +++ b/Web/Models/Entities/Post.php @@ -336,6 +336,11 @@ class Post extends Postable { return $this->getRecord()->suggested; } + + function getPageURL(): string + { + return "/wall".$this->getPrettyId(); + } function toNotifApiStruct() { diff --git a/Web/Models/Entities/Video.php b/Web/Models/Entities/Video.php index 8e3c18f0..d134645e 100644 --- a/Web/Models/Entities/Video.php +++ b/Web/Models/Entities/Video.php @@ -309,6 +309,11 @@ class Video extends Media ); } + function getPageURL(): string + { + return "/video".$this->getPrettyId(); + } + function canBeViewedBy(?User $user = NULL): bool { if($this->isDeleted() || $this->getOwner()->isDeleted()) { diff --git a/Web/Presenters/WallPresenter.php b/Web/Presenters/WallPresenter.php index 17cc12e1..dc0b2936 100644 --- a/Web/Presenters/WallPresenter.php +++ b/Web/Presenters/WallPresenter.php @@ -549,66 +549,6 @@ final class WallPresenter extends OpenVKPresenter $this->flashFail("succ", tr("information_-1"), tr("changes_saved_comment")); } - function renderEdit() - { - $this->assertUserLoggedIn(); - $this->willExecuteWriteAction(); - - if($_SERVER["REQUEST_METHOD"] !== "POST") - $this->redirect("/id0"); - - if($this->postParam("type") == "post") - $post = $this->posts->get((int)$this->postParam("postid")); - else - $post = (new Comments)->get((int)$this->postParam("postid")); - - if(!$post || $post->isDeleted()) - $this->returnJson(["error" => "Invalid post"]); - - if(!$post->canBeEditedBy($this->user->identity)) - $this->returnJson(["error" => "Access denied"]); - - $attachmentsCount = sizeof(iterator_to_array($post->getChildren())); - - if(empty($this->postParam("newContent")) && $attachmentsCount < 1) - $this->returnJson(["error" => "Empty post"]); - - $post->setEdited(time()); - - try { - $post->setContent($this->postParam("newContent")); - } catch(\LengthException $e) { - $this->returnJson(["error" => $e->getMessage()]); - } - - if($this->postParam("type") === "post") { - $post->setNsfw($this->postParam("nsfw") == "true"); - $flags = 0; - - if($post->getTargetWall() < 0 && $post->getWallOwner()->canBeModifiedBy($this->user->identity)) { - if($this->postParam("fromgroup") == "true") { - $flags |= 0b10000000; - $post->setFlags($flags); - } else - $post->setFlags($flags); - } - } - - $post->save(true); - - $this->returnJson(["error" => "no", - "new_content" => $post->getText(), - "new_edited" => (string)$post->getEditTime(), - "nsfw" => $this->postParam("type") === "post" ? (int)$post->isExplicit() : 0, - "from_group" => $this->postParam("type") === "post" && $post->getTargetWall() < 0 ? - ((int)$post->isPostedOnBehalfOfGroup()) : "false", - "new_text" => $post->getText(false), - "author" => [ - "name" => $post->getOwner()->getCanonicalName(), - "avatar" => $post->getOwner()->getAvatarUrl() - ]]); - } - function renderAccept() { $this->assertUserLoggedIn(); $this->willExecuteWriteAction(true); @@ -697,4 +637,44 @@ final class WallPresenter extends OpenVKPresenter "new_count" => (new Posts)->getSuggestedPostsCount($post->getWallOwner()->getId()) ]); } + + function renderLikers(string $type, int $owner_id, int $item_id) + { + $this->assertUserLoggedIn(); + + $item = NULL; + $display_name = $type; + switch($type) { + default: + $this->notFound(); + break; + case 'wall': + $item = $this->posts->getPostById($owner_id, $item_id); + $display_name = 'post'; + break; + case 'comment': + $item = (new \openvk\Web\Models\Repositories\Comments)->get($item_id); + break; + case 'photo': + $item = (new \openvk\Web\Models\Repositories\Photos)->getByOwnerAndVID($owner_id, $item_id); + break; + case 'video': + $item = (new \openvk\Web\Models\Repositories\Videos)->getByOwnerAndVID($owner_id, $item_id); + break; + } + + if(!$item || $item->isDeleted() || !$item->canBeViewedBy($this->user->identity)) + $this->notFound(); + + $page = (int)($this->queryParam('p') ?? 1); + $count = $item->getLikesCount(); + $likers = iterator_to_array($item->getLikers($page, OPENVK_DEFAULT_PER_PAGE)); + + $this->template->item = $item; + $this->template->type = $display_name; + $this->template->iterator = $likers; + $this->template->count = $count; + $this->template->page = $page; + $this->template->perPage = OPENVK_DEFAULT_PER_PAGE; + } } diff --git a/Web/Presenters/templates/Wall/Likers.xml b/Web/Presenters/templates/Wall/Likers.xml new file mode 100644 index 00000000..8df7e9a9 --- /dev/null +++ b/Web/Presenters/templates/Wall/Likers.xml @@ -0,0 +1,51 @@ +{extends "../@listView.xml"} + +{block title} + {_likers_list} +{/block} + +{block header} + {tr($type)} » + {_likers_list} +{/block} + +{block tabs} +
+ {_liked_verb} +
+{/block} + +{block link|strip|stripHtml} + {$x->getURL()} +{/block} + +{block preview} + +{/block} + +{block name} + {$x->getCanonicalName()} + +{/block} + +{block description} + + + + + + + + + + + + + + + +
{_pronouns}: {$x->isFemale() ? tr("female") : ($x->isNeutral() ? tr("neutral") : tr("male"))}
{_relationship}:{$x->getLocalizedMaritalStatus()}
{_registration_date}: {$x->getRegistrationTime()}
+{/block} diff --git a/Web/routes.yml b/Web/routes.yml index 1c1ef075..59b470c5 100644 --- a/Web/routes.yml +++ b/Web/routes.yml @@ -143,6 +143,8 @@ routes: handler: "Wall->accept" - url: "/wall/decline" handler: "Wall->decline" + - url: "/{text}/{num}_{num}/likes" + handler: "Wall->likers" - url: "/blob_{text}/{?path}.{text}" handler: "Blob->file" placeholders: diff --git a/locales/en.strings b/locales/en.strings index c1ff0822..90873e09 100644 --- a/locales/en.strings +++ b/locales/en.strings @@ -272,6 +272,9 @@ "show_more" = "Show more"; "has_repost" = "Has repost"; +"likers_list" = "Likers list"; +"liked_verb" = "Liked by"; + /* Friends */ "friends" = "Friends"; diff --git a/locales/ru.strings b/locales/ru.strings index 8a2d4e8c..45da0eb0 100644 --- a/locales/ru.strings +++ b/locales/ru.strings @@ -251,6 +251,9 @@ "show_more" = "Показать больше"; "has_repost" = "Содержит репост"; +"likers_list" = "Список лайкнувших"; +"liked_verb" = "Понравилось"; + /* Friends */ "friends" = "Друзья";