mirror of
https://github.com/openvk/openvk
synced 2024-11-11 01:19:53 +03:00
VKAPI: Wall.get impovements
Added a "extended" value, added a "offset" to the Repositories/Posts->getPostsFromUsersWall function and little bit of refactoring
This commit is contained in:
parent
012bd072b4
commit
a3d65a402e
3 changed files with 74 additions and 25 deletions
|
@ -16,20 +16,25 @@ final class Wall extends VKAPIRequestHandler
|
|||
$posts = new PostsRepo;
|
||||
|
||||
$items = [];
|
||||
$profiles = [];
|
||||
$groups = [];
|
||||
$count = $posts->getPostCountOnUserWall((int) $owner_id);
|
||||
|
||||
foreach ($posts->getPostsFromUsersWall((int)$owner_id) as $post) {
|
||||
foreach ($posts->getPostsFromUsersWall((int)$owner_id, 1, $count, $offset) as $post) {
|
||||
$from_id = get_class($post->getOwner()) == "openvk\Web\Models\Entities\Club" ? $post->getOwner()->getId() * (-1) : $post->getOwner()->getId();
|
||||
$items[] = (object)[
|
||||
"id" => $post->getVirtualId(),
|
||||
"from_id" => $post->getOwner()->getId(),
|
||||
"from_id" => $from_id,
|
||||
"owner_id" => $post->getTargetWall(),
|
||||
"date" => $post->getPublicationTime()->timestamp(),
|
||||
"post_type" => "post",
|
||||
"text" => $post->getText(),
|
||||
"can_edit" => 0, // TODO
|
||||
"can_delete" => $post->canBeDeletedBy($this->getUser()),
|
||||
"can_pin" => 0, // TODO
|
||||
"can_pin" => $post->canBePinnedBy($this->getUser()),
|
||||
"can_archive" => false, // TODO MAYBE
|
||||
"is_archived" => false,
|
||||
"is_pinned" => $post->isPinned(),
|
||||
"post_source" => (object)["type" => "vk"],
|
||||
"comments" => (object)[
|
||||
"count" => $post->getCommentsCount(),
|
||||
|
@ -46,21 +51,61 @@ final class Wall extends VKAPIRequestHandler
|
|||
"user_reposted" => 0
|
||||
]
|
||||
];
|
||||
|
||||
if ($from_id > 0)
|
||||
$profiles[] = $from_id;
|
||||
else
|
||||
$groups[] = $from_id * -1;
|
||||
}
|
||||
|
||||
$profiles = [];
|
||||
$groups = [];
|
||||
|
||||
$groups[0] = 'lol';
|
||||
$groups[2] = 'cec';
|
||||
|
||||
if($extended == 1)
|
||||
return (object)[
|
||||
"items" => (array)$items,
|
||||
"cock" => (array)$groups
|
||||
{
|
||||
$profiles = array_unique($profiles);
|
||||
$groups = array_unique($groups);
|
||||
|
||||
$profilesFormatted = [];
|
||||
$groupsFormatted = [];
|
||||
|
||||
foreach ($profiles as $prof) {
|
||||
$user = (new UsersRepo)->get($prof);
|
||||
$profilesFormatted[] = (object)[
|
||||
"first_name" => $user->getFirstName(),
|
||||
"id" => $user->getId(),
|
||||
"last_name" => $user->getLastName(),
|
||||
"can_access_closed" => false,
|
||||
"is_closed" => false,
|
||||
"sex" => $user->isFemale() ? 1 : 2,
|
||||
"screen_name" => $user->getShortCode(),
|
||||
"photo_50" => $user->getAvatarUrl(),
|
||||
"photo_100" => $user->getAvatarUrl(),
|
||||
"online" => $user->isOnline()
|
||||
];
|
||||
}
|
||||
|
||||
foreach($groups as $g) {
|
||||
$group = (new ClubsRepo)->get($g);
|
||||
$groupsFormatted[] = (object)[
|
||||
"id" => $group->getId(),
|
||||
"name" => $group->getName(),
|
||||
"screen_name" => $group->getShortCode(),
|
||||
"is_closed" => 0,
|
||||
"type" => "group",
|
||||
"photo_50" => $group->getAvatarUrl(),
|
||||
"photo_100" => $group->getAvatarUrl(),
|
||||
"photo_200" => $group->getAvatarUrl(),
|
||||
];
|
||||
}
|
||||
|
||||
return (object)[
|
||||
"count" => $count,
|
||||
"items" => (array)$items,
|
||||
"profiles" => (array)$profilesFormatted,
|
||||
"groups" => (array)$groupsFormatted
|
||||
];
|
||||
}
|
||||
else
|
||||
return (object)[
|
||||
"count" => $count,
|
||||
"items" => (array)$items
|
||||
];
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ class Post extends Postable
|
|||
*/
|
||||
function getOwner(bool $honourFlags = true, bool $real = false): RowModel
|
||||
{
|
||||
if($honourFlags && ( ($this->getRecord()->flags & 0b10000000) > 0 )) {
|
||||
if($honourFlags && $this->isPostedOnBehalfOfGroup()) {
|
||||
if($this->getRecord()->wall < 0)
|
||||
return (new Clubs)->get(abs($this->getRecord()->wall));
|
||||
}
|
||||
|
|
|
@ -37,12 +37,13 @@ class Posts
|
|||
return $this->toPost($post);
|
||||
}
|
||||
|
||||
function getPostsFromUsersWall(int $user, int $page = 1, ?int $perPage = NULL): \Traversable
|
||||
function getPostsFromUsersWall(int $user, int $page = 1, ?int $perPage = NULL, ?int $offset = NULL): \Traversable
|
||||
{
|
||||
$perPage ??= OPENVK_DEFAULT_PER_PAGE;
|
||||
$offset = $perPage * ($page - 1);
|
||||
$offset ??= $perPage * ($page - 1);
|
||||
|
||||
$pinPost = $this->getPinnedPost($user);
|
||||
if(is_null($offset) || $offset == 0) {
|
||||
if(!is_null($pinPost)) {
|
||||
if($page === 1) {
|
||||
$perPage--;
|
||||
|
@ -52,6 +53,9 @@ class Posts
|
|||
$offset--;
|
||||
}
|
||||
}
|
||||
} else if(!is_null($offset)) {
|
||||
$offset--;
|
||||
}
|
||||
|
||||
$sel = $this->posts->where([
|
||||
"wall" => $user,
|
||||
|
|
Loading…
Reference in a new issue