mirror of
https://github.com/openvk/openvk
synced 2024-11-11 01:19:53 +03:00
VKAPI: Add support for Messages.getConversations
This commit is contained in:
parent
990bda4618
commit
61a2c44e22
2 changed files with 31 additions and 11 deletions
|
@ -4,6 +4,7 @@ use openvk\Web\Events\NewMessageEvent;
|
|||
use openvk\Web\Models\Entities\{Correspondence, Message};
|
||||
use openvk\Web\Models\Repositories\{Messages as MSGRepo, Users as USRRepo};
|
||||
use openvk\VKAPI\Structures\{Message as APIMsg, Conversation as APIConvo};
|
||||
use openvk\VKAPI\Handlers\Users as APIUsers;
|
||||
use Chandler\Signaling\SignalManager;
|
||||
|
||||
final class Messages extends VKAPIRequestHandler
|
||||
|
@ -145,12 +146,14 @@ final class Messages extends VKAPIRequestHandler
|
|||
return 1;
|
||||
}
|
||||
|
||||
function getConversations(int $offset = 0, int $count = 20, string $filter = "all", int $extended = 0): object
|
||||
function getConversations(int $offset = 0, int $count = 20, string $filter = "all", int $extended = 0, string $fields = ""): object
|
||||
{
|
||||
$this->requireUser();
|
||||
|
||||
$convos = (new MSGRepo)->getCorrespondencies($this->getUser(), -1, $count, $offset);
|
||||
$list = [];
|
||||
|
||||
$users = [];
|
||||
foreach($convos as $convo) {
|
||||
$correspondents = $convo->getCorrespondents();
|
||||
if($correspondents[0]->getId() === $this->getUser()->getId())
|
||||
|
@ -190,6 +193,11 @@ final class Messages extends VKAPIRequestHandler
|
|||
$lastMessagePreview->out = (int) ($lastMessage->getSender()->getId() === $this->getUser()->getId());
|
||||
$lastMessagePreview->body = $lastMessage->getText(false);
|
||||
$lastMessagePreview->emoji = true;
|
||||
|
||||
if($extended == 1) {
|
||||
$users[] = $lastMessage->getSender()->getId();
|
||||
$users[] = $author;
|
||||
}
|
||||
}
|
||||
|
||||
$list[] = [
|
||||
|
@ -198,10 +206,20 @@ final class Messages extends VKAPIRequestHandler
|
|||
];
|
||||
}
|
||||
|
||||
return (object) [
|
||||
"count" => sizeof($list),
|
||||
"items" => $list,
|
||||
];
|
||||
if($extended == 0){
|
||||
return (object) [
|
||||
"count" => sizeof($list),
|
||||
"items" => $list,
|
||||
];
|
||||
} else {
|
||||
$users = array_unique($users);
|
||||
|
||||
return (object) [
|
||||
"count" => sizeof($list),
|
||||
"items" => $list,
|
||||
"profiles" => (new APIUsers)->get(implode(',', $users), $fields, $offset, $count)
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
function getHistory(int $offset = 0, int $count = 20, int $user_id = -1, int $peer_id = -1, int $start_message_id = 0, int $rev = 0, int $extended = 0): object
|
||||
|
|
|
@ -5,13 +5,15 @@ use openvk\Web\Models\Repositories\Users as UsersRepo;
|
|||
|
||||
final class Users extends VKAPIRequestHandler
|
||||
{
|
||||
function get(string $user_ids = "0", string $fields = "", int $offset = 0, int $count = 100): array
|
||||
function get(string $user_ids = "0", string $fields = "", int $offset = 0, int $count = 100, User $authuser = null /* костыль(( */): array
|
||||
{
|
||||
$this->requireUser();
|
||||
// $this->requireUser();
|
||||
|
||||
if($authuser == null) $authuser = $this->getUser();
|
||||
|
||||
$users = new UsersRepo;
|
||||
if($user_ids == "0")
|
||||
$user_ids = (string) $this->getUser()->getId();
|
||||
$user_ids = (string) $authuser->getId();
|
||||
|
||||
$usrs = explode(',', $user_ids);
|
||||
$response;
|
||||
|
@ -51,7 +53,7 @@ final class Users extends VKAPIRequestHandler
|
|||
$response[$i]->verified = intval($usr->isVerified());
|
||||
break;
|
||||
case 'sex':
|
||||
$response[$i]->sex = $this->getUser()->isFemale() ? 1 : 2;
|
||||
$response[$i]->sex = $authuser->isFemale() ? 1 : 2;
|
||||
break;
|
||||
case 'has_photo':
|
||||
$response[$i]->has_photo = is_null($usr->getAvatarPhoto()) ? 0 : 1;
|
||||
|
@ -71,10 +73,10 @@ final class Users extends VKAPIRequestHandler
|
|||
$response[$i]->screen_name = $usr->getShortCode();
|
||||
break;
|
||||
case 'friend_status':
|
||||
switch($usr->getSubscriptionStatus($this->getUser())) {
|
||||
switch($usr->getSubscriptionStatus($authuser)) {
|
||||
case 3:
|
||||
case 0:
|
||||
$response[$i]->friend_status = $usr->getSubscriptionStatus($this->getUser());
|
||||
$response[$i]->friend_status = $usr->getSubscriptionStatus($authuser);
|
||||
break;
|
||||
case 1:
|
||||
$response[$i]->friend_status = 2;
|
||||
|
|
Loading…
Reference in a new issue