From 25064b6e4f78e45df37514764e28665db9ff1cb6 Mon Sep 17 00:00:00 2001 From: veselcraft Date: Sat, 23 Jul 2022 02:24:34 +0300 Subject: [PATCH] VKAPI: Add new Wall.repost method --- VKAPI/Handlers/Wall.php | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/VKAPI/Handlers/Wall.php b/VKAPI/Handlers/Wall.php index 11fb11b9..48d59c91 100644 --- a/VKAPI/Handlers/Wall.php +++ b/VKAPI/Handlers/Wall.php @@ -1,7 +1,7 @@ $post->getVirtualId()]; } + + function repost(string $object, string $message) { + $this->requireUser(); + + $postArray; + if(preg_match('/wall((?:-?)[0-9]+)_([0-9]+)/', $object, $postArray) == 0) + $this->fail(100, "One of the parameters specified was missing or invalid: object is incorrect"); + + $post = (new PostsRepo)->getPostById((int) $postArray[1], (int) $postArray[2]); + if(!$post || $post->isDeleted()) $this->fail(100, "One of the parameters specified was missing or invalid"); + + $nPost = new Post; + $nPost->setOwner($this->user->getId()); + $nPost->setWall($this->user->getId()); + $nPost->setContent($message); + $nPost->save(); + $nPost->attach($post); + + if($post->getOwner(false)->getId() !== $this->user->getId() && !($post->getOwner() instanceof Club)) + (new RepostNotification($post->getOwner(false), $post, $this->user->identity))->emit(); + + return (object) [ + "success" => 1, // 👍 + "post_id" => $nPost->getVirtualId(), + "reposts_count" => $post->getRepostCount(), + "likes_count" => $post->getLikesCount() + ]; + } }