VKAPI: Make getConversations output a real count of dialogs; Fix bug with extended param, when offset causes profile array to be dead xd

This commit is contained in:
veselcraft 2022-08-27 01:32:53 +03:00
parent 2fa36e123d
commit 4891030ed0
No known key found for this signature in database
GPG key ID: AED66BC1AC628A4E

View file

@ -152,6 +152,7 @@ final class Messages extends VKAPIRequestHandler
$this->requireUser(); $this->requireUser();
$convos = (new MSGRepo)->getCorrespondencies($this->getUser(), -1, $count, $offset); $convos = (new MSGRepo)->getCorrespondencies($this->getUser(), -1, $count, $offset);
$convosCount = (new MSGRepo)->getCorrespondenciesCount($this->getUser());
$list = []; $list = [];
$users = []; $users = [];
@ -197,7 +198,6 @@ final class Messages extends VKAPIRequestHandler
$lastMessagePreview->emoji = true; $lastMessagePreview->emoji = true;
if($extended == 1) { if($extended == 1) {
$users[] = $lastMessage->getSender()->getId();
$users[] = $author; $users[] = $author;
} }
} }
@ -210,16 +210,17 @@ final class Messages extends VKAPIRequestHandler
if($extended == 0){ if($extended == 0){
return (object) [ return (object) [
"count" => sizeof($list), "count" => $convosCount,
"items" => $list, "items" => $list,
]; ];
} else { } else {
$users[] = $this->getUser()->getId();
$users = array_unique($users); $users = array_unique($users);
return (object) [ return (object) [
"count" => sizeof($list), "count" => $convosCount,
"items" => $list, "items" => $list,
"profiles" => (!empty($users) ? (new APIUsers)->get(implode(',', $users), $fields, $offset, $count) : []) "profiles" => (!empty($users) ? (new APIUsers)->get(implode(',', $users), $fields, 0, $count+1) : [])
]; ];
} }
} }