From c8ef5ccd6417b28f5dddc8762aa8e70c0593d108 Mon Sep 17 00:00:00 2001 From: lalka2016 <99399973+lalka2016@users.noreply.github.com> Date: Tue, 15 Aug 2023 10:21:06 +0300 Subject: [PATCH] Improvements 2 api --- VKAPI/Handlers/Groups.php | 35 ++++++++++++++++- VKAPI/Handlers/Newsfeed.php | 2 +- VKAPI/Handlers/Wall.php | 41 +++++++++++++++++--- Web/Presenters/templates/@layout.xml | 2 +- Web/Presenters/templates/Group/Suggested.xml | 14 ++++--- 5 files changed, 80 insertions(+), 14 deletions(-) diff --git a/VKAPI/Handlers/Groups.php b/VKAPI/Handlers/Groups.php index 2937795a..5a5487da 100644 --- a/VKAPI/Handlers/Groups.php +++ b/VKAPI/Handlers/Groups.php @@ -2,6 +2,7 @@ namespace openvk\VKAPI\Handlers; use openvk\Web\Models\Repositories\Clubs as ClubsRepo; use openvk\Web\Models\Repositories\Users as UsersRepo; +use openvk\Web\Models\Repositories\Posts as PostsRepo; use openvk\Web\Models\Entities\Club; final class Groups extends VKAPIRequestHandler @@ -81,6 +82,22 @@ final class Groups extends VKAPIRequestHandler case "members_count": $rClubs[$i]->members_count = $usr->getFollowersCount(); break; + case "can_suggest": + $rClubs[$i]->can_suggest = !$usr->canBeModifiedBy($this->getUser()) && $usr->getWallType() == 2; + break; + # unstandard feild + case "suggested_count": + if($usr->getWallType() != 2) { + $rClubs[$i]->suggested_count = NULL; + break; + } + + if($usr->canBeModifiedBy($this->getUser())) + $rClubs[$i]->suggested_count = $usr->getSuggestedPostsCount(); + else + $rClubs[$i]->suggested_count = (new PostsRepo)->getSuggestedPostsCountByUser($usr->getId(), $this->getUser()->getId()); + + break; } } } @@ -188,7 +205,23 @@ final class Groups extends VKAPIRequestHandler case "description": $response[$i]->description = $clb->getDescription(); break; - case "contacts": + case "can_suggest": + $response[$i]->can_suggest = !$clb->canBeModifiedBy($this->getUser()) && $clb->getWallType() == 2; + break; + # unstandard feild + case "suggested_count": + if($clb->getWallType() != 2) { + $response[$i]->suggested_count = NULL; + break; + } + + if($clb->canBeModifiedBy($this->getUser())) + $response[$i]->suggested_count = $clb->getSuggestedPostsCount(); + else + $response[$i]->suggested_count = (new PostsRepo)->getSuggestedPostsCountByUser($clb->getId(), $this->getUser()->getId()); + + break; + case "contacts": $contacts; $contactTmp = $clb->getManagers(1, true); diff --git a/VKAPI/Handlers/Newsfeed.php b/VKAPI/Handlers/Newsfeed.php index d9992430..4833e7be 100644 --- a/VKAPI/Handlers/Newsfeed.php +++ b/VKAPI/Handlers/Newsfeed.php @@ -51,7 +51,7 @@ final class Newsfeed extends VKAPIRequestHandler { $this->requireUser(); - $queryBase = "FROM `posts` LEFT JOIN `groups` ON GREATEST(`posts`.`wall`, 0) = 0 AND `groups`.`id` = ABS(`posts`.`wall`) WHERE (`groups`.`hide_from_global_feed` = 0 OR `groups`.`name` IS NULL) AND `posts`.`deleted` = 0"; + $queryBase = "FROM `posts` LEFT JOIN `groups` ON GREATEST(`posts`.`wall`, 0) = 0 AND `groups`.`id` = ABS(`posts`.`wall`) WHERE (`groups`.`hide_from_global_feed` = 0 OR `groups`.`name` IS NULL) AND `posts`.`deleted` = 0 AND `posts`.`suggested` = 0"; if($this->getUser()->getNsfwTolerance() === User::NSFW_INTOLERANT) $queryBase .= " AND `nsfw` = 0"; diff --git a/VKAPI/Handlers/Wall.php b/VKAPI/Handlers/Wall.php index 3b8a9d3d..4242d46e 100644 --- a/VKAPI/Handlers/Wall.php +++ b/VKAPI/Handlers/Wall.php @@ -49,13 +49,13 @@ final class Wall extends VKAPIRequestHandler $cnt = $posts->getPostCountOnUserWall($owner_id); break; case "owner": - $this->fail(66666, "Not implemented :("); + $this->fail(66666, "Not implemented"); break; case "others": - $this->fail(66666, "Not implemented :("); + $this->fail(66666, "Not implemented"); break; case "postponed": - $this->fail(66666, "Otlojka is not implemented :)"); + $this->fail(66666, "Postponed posts are not implemented."); break; case "suggests": if($owner_id < 0) { @@ -149,12 +149,23 @@ final class Wall extends VKAPIRequestHandler ]; } + $postType = "post"; + $signerId = NULL; + if($post->getSuggestionType() != 0) { + $postType = "suggest"; + } + + if($post->isSigned()) { + $actualAuthor = $post->getOwner(false); + $signerId = $actualAuthor->getId(); + } + $items[] = (object)[ "id" => $post->getVirtualId(), "from_id" => $from_id, "owner_id" => $post->getTargetWall(), "date" => $post->getPublicationTime()->timestamp(), - "post_type" => "post", + "post_type" => $postType, "text" => $post->getText(false), "copy_history" => $repost, "can_edit" => 0, # TODO @@ -166,6 +177,7 @@ final class Wall extends VKAPIRequestHandler "is_explicit" => $post->isExplicit(), "attachments" => $attachments, "post_source" => $post_source, + "signer_id" => $signerId, "comments" => (object)[ "count" => $post->getCommentsCount(), "can_post" => 1 @@ -187,6 +199,9 @@ final class Wall extends VKAPIRequestHandler else $groups[] = $from_id * -1; + /*if($post->isSigned()) + $profiles[] = $post->getOwner(false)->getId();*/ + $attachments = NULL; # free attachments so it will not clone everythingg } @@ -324,12 +339,24 @@ final class Wall extends VKAPIRequestHandler ]; } + # TODO: $post->getVkApiType() + $postType = "post"; + $signerId = NULL; + if($post->getSuggestionType() != 0) { + $postType = "suggest"; + } + + if($post->isSigned()) { + $actualAuthor = $post->getOwner(false); + $signerId = $actualAuthor->getId(); + } + $items[] = (object)[ "id" => $post->getVirtualId(), "from_id" => $from_id, "owner_id" => $post->getTargetWall(), "date" => $post->getPublicationTime()->timestamp(), - "post_type" => "post", + "post_type" => $postType, "text" => $post->getText(false), "copy_history" => $repost, "can_edit" => 0, # TODO @@ -340,6 +367,7 @@ final class Wall extends VKAPIRequestHandler "is_pinned" => $post->isPinned(), "is_explicit" => $post->isExplicit(), "post_source" => $post_source, + "signer_id" => $signerId, "attachments" => $attachments, "comments" => (object)[ "count" => $post->getCommentsCount(), @@ -362,6 +390,9 @@ final class Wall extends VKAPIRequestHandler else $groups[] = $from_id * -1; + /*if($post->isSigned()) + $profiles[] = $post->getOwner(false)->getId();*/ + $attachments = NULL; # free attachments so it will not clone everything $repost = NULL; # same } diff --git a/Web/Presenters/templates/@layout.xml b/Web/Presenters/templates/@layout.xml index ccb6994a..389415bb 100644 --- a/Web/Presenters/templates/@layout.xml +++ b/Web/Presenters/templates/@layout.xml @@ -234,7 +234,7 @@ {$club->getName()} - + ({$club->getSuggestedPostsCount()}) diff --git a/Web/Presenters/templates/Group/Suggested.xml b/Web/Presenters/templates/Group/Suggested.xml index 56e836ef..a7c824f6 100644 --- a/Web/Presenters/templates/Group/Suggested.xml +++ b/Web/Presenters/templates/Group/Suggested.xml @@ -12,14 +12,16 @@ {include "../components/error.xml", title => "", description => $type == "my" ? tr("no_suggested_posts_by_you") : tr("no_suggested_posts_by_people")} {else}

{if $type == "my"}{tr("suggested_posts_in_group_by_you", $count)}{else}{tr("suggested_posts_in_group", $count)}{/if}

-
+
{var $microblog = $thisUser->hasMicroblogEnabled()} {foreach $posts as $post} - {if $microblog} - {include "../components/post/microblogpost.xml", post => $post, commentSection => false, suggestion => true, forceNoCommentsLink => true, forceNoPinLink => true, forceNoLike => true, forceNoShareLink => true, forceNoDeleteLink => false} - {else} - {include "../components/post/oldpost.xml", post => $post, commentSection => false, suggestion => true, forceNoCommentsLink => true, forceNoPinLink => true, forceNoLike => true, forceNoShareLink => true, forceNoDeleteLink => false} - {/if} +
+ {if $microblog} + {include "../components/post/microblogpost.xml", post => $post, commentSection => false, suggestion => true, forceNoCommentsLink => true, forceNoPinLink => true, forceNoLike => true, forceNoShareLink => true, forceNoDeleteLink => false} + {else} + {include "../components/post/oldpost.xml", post => $post, commentSection => false, suggestion => true, forceNoCommentsLink => true, forceNoPinLink => true, forceNoLike => true, forceNoShareLink => true, forceNoDeleteLink => false} + {/if} +
{/foreach} {include "../components/paginator.xml", conf => (object) [