VKAPI: Add support to start_from parameter

This commit is contained in:
veselcraft 2022-07-25 13:25:06 +03:00
parent 75030bfdc4
commit 174ed53d92
No known key found for this signature in database
GPG key ID: AED66BC1AC628A4E

View file

@ -10,9 +10,6 @@ final class Newsfeed extends VKAPIRequestHandler
{ {
$this->requireUser(); $this->requireUser();
if($offset != 0)
$start_from = $offset;
$id = $this->getUser()->getId(); $id = $this->getUser()->getId();
$subs = DatabaseConnection::i() $subs = DatabaseConnection::i()
->getContext() ->getContext()
@ -29,12 +26,15 @@ final class Newsfeed extends VKAPIRequestHandler
->select("id") ->select("id")
->where("wall IN (?)", $ids) ->where("wall IN (?)", $ids)
->where("deleted", 0) ->where("deleted", 0)
->where("created < (?)", empty($start_from) ? time()+1 : $start_from)
->order("created DESC"); ->order("created DESC");
$rposts = []; $rposts = [];
foreach($posts->page((int) ($offset + 1), $count) as $post) foreach($posts->page((int) ($offset + 1), $count) as $post)
$rposts[] = (new PostsRepo)->get($post->id)->getPrettyId(); $rposts[] = (new PostsRepo)->get($post->id)->getPrettyId();
return (new Wall)->getById(implode(',', $rposts), $extended, $fields, $this->getUser()); $response = (new Wall)->getById(implode(',', $rposts), $extended, $fields, $this->getUser());
$response->next_from = end($response->items)->date;
return $response;
} }
} }