FIX NEWSFEED and polls

This commit is contained in:
lalka2016 2023-07-22 21:06:22 +03:00
parent 8495f493d0
commit 8b857b9f15
5 changed files with 28 additions and 10 deletions

View file

@ -51,8 +51,8 @@ final class Newsfeed extends VKAPIRequestHandler
{ {
$this->requireUser(); $this->requireUser();
$queryBase = "FROM `posts` JOIN `profiles` ON `profiles`.`id` = ABS(`posts`.`wall`) LEFT JOIN `groups` ON GREATEST(`posts`.`wall`, 0) = 0 AND `groups`.`id` = ABS(`posts`.`wall`)"; $queryBase = "FROM `posts` LEFT JOIN `groups` ON GREATEST(`posts`.`wall`, 0) = 0 AND `groups`.`id` = ABS(`posts`.`wall`) LEFT JOIN `profiles` ON LEAST(`posts`.`wall`, 0) = 0 AND `profiles`.`id` = ABS(`posts`.`wall`)";
$queryBase .= "WHERE (`profiles`.`profile_type` = 0 OR `profiles`.`first_name` IS NULL) AND (`groups`.`hide_from_global_feed` = 0 OR `groups`.`name` IS NULL) AND `posts`.`deleted` = 0"; $queryBase .= "WHERE (`groups`.`hide_from_global_feed` = 0 OR `groups`.`name` IS NULL) AND (`profiles`.`profile_type` = 0 OR `profiles`.`first_name` IS NULL) AND `posts`.`deleted` = 0";
if($this->getUser()->getNsfwTolerance() === User::NSFW_INTOLERANT) if($this->getUser()->getNsfwTolerance() === User::NSFW_INTOLERANT)
$queryBase .= " AND `nsfw` = 0"; $queryBase .= " AND `nsfw` = 0";

View file

@ -35,7 +35,11 @@ final class Polls extends VKAPIRequestHandler
foreach($poll->getUserVote($this->getUser()) as $vote) foreach($poll->getUserVote($this->getUser()) as $vote)
$userVote[] = $vote[0]; $userVote[] = $vote[0];
$ownerr = $poll->getAttachedPost()->getOwner() instanceof User ? $poll->getAttachedPost()->getOwner()->getId() : $poll->getAttachedPost()->getOwner()->getId() * -1; $ownerr = 0;
if(!is_null($poll->getAttachedPost())) {
$ownerr = $poll->getAttachedPost()->getOwner() instanceof User ? $poll->getAttachedPost()->getOwner()->getId() : $poll->getAttachedPost()->getOwner()->getId() * -1;
}
$response = [ $response = [
"multiple" => $poll->isMultipleChoice(), "multiple" => $poll->isMultipleChoice(),
"end_date" => $poll->endsAt() == NULL ? 0 : $poll->endsAt()->timestamp(), "end_date" => $poll->endsAt() == NULL ? 0 : $poll->endsAt()->timestamp(),
@ -45,7 +49,7 @@ final class Polls extends VKAPIRequestHandler
"can_vote" => $poll->canVote($this->getUser()), "can_vote" => $poll->canVote($this->getUser()),
"can_report" => false, "can_report" => false,
"can_share" => true, "can_share" => true,
"created" => $poll->getAttachedPost()->getPublicationTime()->timestamp(), "created" => $poll->getAttachedPost() ? $poll->getAttachedPost()->getPublicationTime()->timestamp() : 0,
"id" => $poll->getId(), "id" => $poll->getId(),
"owner_id" => $ownerr, "owner_id" => $ownerr,
"question" => $poll->getTitle(), "question" => $poll->getTitle(),

View file

@ -879,7 +879,12 @@ final class Wall extends VKAPIRequestHandler
foreach($attachment->getUserVote($user) as $vote) foreach($attachment->getUserVote($user) as $vote)
$userVote[] = $vote[0]; $userVote[] = $vote[0];
$ownerr = $attachment->getAttachedPost()->getOwner() instanceof User ? $attachment->getAttachedPost()->getOwner()->getId() : $attachment->getAttachedPost()->getOwner()->getId() * -1; $ownerr = 0;
if(!is_null($attachment->getAttachedPost())) {
$ownerr = $attachment->getAttachedPost()->getOwner() instanceof User ? $attachment->getAttachedPost()->getOwner()->getId() : $attachment->getAttachedPost()->getOwner()->getId() * -1;
}
return [ return [
"type" => "poll", "type" => "poll",
"poll" => [ "poll" => [
@ -891,7 +896,7 @@ final class Wall extends VKAPIRequestHandler
"can_vote" => $attachment->canVote($user), "can_vote" => $attachment->canVote($user),
"can_report" => false, "can_report" => false,
"can_share" => true, "can_share" => true,
"created" => $attachment->getAttachedPost()->getPublicationTime()->timestamp(), "created" => $attachment->getAttachedPost() ? $attachment->getAttachedPost()->getPublicationTime()->timestamp() : 0,
"id" => $attachment->getId(), "id" => $attachment->getId(),
"owner_id" => $ownerr, "owner_id" => $ownerr,
"question" => $attachment->getTitle(), "question" => $attachment->getTitle(),

View file

@ -300,11 +300,20 @@ class Poll extends Attachable
["attachable_type" => static::class, ["attachable_type" => static::class,
"attachable_id" => $this->getId()])->fetch(); "attachable_id" => $this->getId()])->fetch();
return (new Posts)->get($post->target_id); if(!is_null($post->target_id)) {
return (new Posts)->get($post->target_id);
} else {
return NULL;
}
} }
function canBeViewedBy(?User $user = NULL): bool function canBeViewedBy(?User $user = NULL): bool
{ {
return $this->getAttachedPost()->canBeViewedBy($user); if(!is_null($this->getAttachedPost())) {
return $this->getAttachedPost()->canBeViewedBy($user);
} else {
return true;
}
} }
} }

View file

@ -177,8 +177,8 @@ final class WallPresenter extends OpenVKPresenter
$page = (int) ($_GET["p"] ?? 1); $page = (int) ($_GET["p"] ?? 1);
$pPage = min((int) ($_GET["posts"] ?? OPENVK_DEFAULT_PER_PAGE), 50); $pPage = min((int) ($_GET["posts"] ?? OPENVK_DEFAULT_PER_PAGE), 50);
$queryBase = "FROM `posts` JOIN `profiles` ON `profiles`.`id` = ABS(`posts`.`wall`) LEFT JOIN `groups` ON GREATEST(`posts`.`wall`, 0) = 0 AND `groups`.`id` = ABS(`posts`.`wall`)"; $queryBase = "FROM `posts` LEFT JOIN `groups` ON GREATEST(`posts`.`wall`, 0) = 0 AND `groups`.`id` = ABS(`posts`.`wall`) LEFT JOIN `profiles` ON LEAST(`posts`.`wall`, 0) = 0 AND `profiles`.`id` = ABS(`posts`.`wall`)";
$queryBase .= "WHERE (`profiles`.`profile_type` = 0 OR `profiles`.`first_name` IS NULL) AND (`groups`.`hide_from_global_feed` = 0 OR `groups`.`name` IS NULL) AND `posts`.`deleted` = 0"; $queryBase .= "WHERE (`groups`.`hide_from_global_feed` = 0 OR `groups`.`name` IS NULL) AND (`profiles`.`profile_type` = 0 OR `profiles`.`first_name` IS NULL) AND `posts`.`deleted` = 0";
if($this->user->identity->getNsfwTolerance() === User::NSFW_INTOLERANT) if($this->user->identity->getNsfwTolerance() === User::NSFW_INTOLERANT)
$queryBase .= " AND `nsfw` = 0"; $queryBase .= " AND `nsfw` = 0";