2022-03-19 03:31:27 +03:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
namespace openvk\VKAPI\Handlers;
|
|
|
|
use Chandler\Database\DatabaseConnection;
|
|
|
|
use openvk\Web\Models\Repositories\Posts as PostsRepo;
|
|
|
|
use openvk\VKAPI\Handlers\Wall;
|
|
|
|
|
|
|
|
final class Newsfeed extends VKAPIRequestHandler
|
|
|
|
{
|
|
|
|
function get(string $fields = "", int $start_from = 0, int $offset = 0, int $count = 30, int $extended = 0)
|
|
|
|
{
|
|
|
|
$this->requireUser();
|
|
|
|
|
|
|
|
$id = $this->getUser()->getId();
|
|
|
|
$subs = DatabaseConnection::i()
|
|
|
|
->getContext()
|
|
|
|
->table("subscriptions")
|
|
|
|
->where("follower", $id);
|
|
|
|
$ids = array_map(function($rel) {
|
|
|
|
return $rel->target * ($rel->model === "openvk\Web\Models\Entities\User" ? 1 : -1);
|
|
|
|
}, iterator_to_array($subs));
|
|
|
|
$ids[] = $this->getUser()->getId();
|
|
|
|
|
|
|
|
$posts = DatabaseConnection::i()
|
2022-07-21 22:13:09 +03:00
|
|
|
->getContext()
|
|
|
|
->table("posts")
|
|
|
|
->select("id")
|
|
|
|
->where("wall IN (?)", $ids)
|
|
|
|
->where("deleted", 0)
|
2022-07-25 13:25:06 +03:00
|
|
|
->where("created < (?)", empty($start_from) ? time()+1 : $start_from)
|
2022-07-21 22:13:09 +03:00
|
|
|
->order("created DESC");
|
2022-03-19 03:31:27 +03:00
|
|
|
|
|
|
|
$rposts = [];
|
|
|
|
foreach($posts->page((int) ($offset + 1), $count) as $post)
|
|
|
|
$rposts[] = (new PostsRepo)->get($post->id)->getPrettyId();
|
|
|
|
|
2022-07-25 13:25:06 +03:00
|
|
|
$response = (new Wall)->getById(implode(',', $rposts), $extended, $fields, $this->getUser());
|
|
|
|
$response->next_from = end($response->items)->date;
|
|
|
|
return $response;
|
2022-03-19 03:31:27 +03:00
|
|
|
}
|
|
|
|
}
|