Skip to content

Commit ec42cb1

Browse files
committed
Исправлено получение данных об отправителе для входящего сообщения
1 parent 113d077 commit ec42cb1

File tree

2 files changed

+26
-28
lines changed

2 files changed

+26
-28
lines changed

src/Foundation/Core/Entities/Messages/MessageFields.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Carbon\Carbon;
66
use Hopex\VkSdk\Exceptions\Api\ApiException;
7+
use Hopex\VkSdk\Facades\VkApi;
78
use Hopex\VkSdk\Foundation\Core\Entities\Users\UserProfileFields;
89
use Hopex\VkSdk\Foundation\Core\Entities\Users\UserRequestFields;
910
use Illuminate\Support\Collection;
@@ -52,21 +53,19 @@ public function getDate(): Carbon
5253

5354
/**
5455
* @param string $token
56+
* @param UserRequestFields $userRequestFields
5557
* @param array $userProfileFields
5658
* @return UserProfileFields
5759
* @throws ApiException
5860
* @throws Throwable
5961
*/
60-
public function getSender(string $token, UserRequestFields $userRequestFields): UserProfileFields
62+
public function getSender(string $token, UserRequestFields $userRequestFields, array $userProfileFields = []): UserProfileFields
6163
{
62-
return new UserProfileFields([]);
63-
// return new UserProfileFields(collect(VkApi::user($token)
64-
// ->get((new UserRequestFields())
65-
// ->setUserIds([
66-
// $this->getSenderId()
67-
// ])
68-
// ->setProfileFields($userRequestFields->)
69-
// )->first()));
64+
return new UserProfileFields(
65+
collect(VkApi::user($token)
66+
->get($userRequestFields->setProfileFields($userProfileFields))
67+
->first())
68+
);
7069
}
7170

7271
/**

src/Foundation/Core/Server/EventsHandler.php

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Hopex\VkSdk\Foundation\Core\Server;
44

55
use Hopex\VkSdk\Contracts\ServerEventsContract;
6+
use Hopex\VkSdk\Exceptions\Api\ApiException;
67
use Hopex\VkSdk\Exceptions\SourceQuery\AuthenticationSourceQueryException;
78
use Hopex\VkSdk\Exceptions\SourceQuery\InvalidArgumentSourceQueryException;
89
use Hopex\VkSdk\Exceptions\SourceQuery\InvalidPacketSourceQueryException;
@@ -46,7 +47,10 @@ public function __construct()
4647
}
4748

4849
/**
49-
* @inheritDoc
50+
* @param Message $message
51+
* @return void
52+
* @throws ApiException
53+
* @throws Throwable
5054
*/
5155
public function server_message_new(Message $message): void
5256
{
@@ -60,7 +64,10 @@ public function server_message_new(Message $message): void
6064
}
6165

6266
/**
63-
* @inheritDoc
67+
* @param Mute $mute
68+
* @return void
69+
* @throws ApiException
70+
* @throws Throwable
6471
*/
6572
public function server_mute_new(Mute $mute): void
6673
{
@@ -78,7 +85,10 @@ public function server_mute_new(Mute $mute): void
7885
}
7986

8087
/**
81-
* @inheritDoc
88+
* @param Ban $ban
89+
* @return void
90+
* @throws ApiException
91+
* @throws Throwable
8292
*/
8393
public function server_ban_new(Ban $ban): void
8494
{
@@ -140,26 +150,15 @@ public function requestStatistics(int $groupId): void
140150
public function messageSendToServer(int $groupId, int $peerId, string $name, string $text): void
141151
{
142152
$this->logger->info("ServerMessage \"$text\" from \"$name\" has been send to server by group $groupId");
143-
// $this->sourceQueryCall($groupId, 'sm_chat_say "' . $name . '" "' . $text . '"');
144153
$this->sourceQueryCall($groupId, "sm_chat_say \"$name\" \"$text\"");
145-
146-
VkApi::message(Session::get('group_token'))
147-
->send((new MessageRequestFields())
148-
->setPeerId($peerId)
149-
->setDisableMentions(true)
150-
->setDontParseLinks(true)
151-
->setMessage(str_replace([
152-
'%PLAYER%',
153-
'%MESSAGE%'
154-
], [
155-
$name,
156-
$text
157-
], Note::get('server.messages.to-server')))
158-
);
159154
}
160155

161156
/**
162-
* @inheritDoc
157+
* @param ServerEvent $event
158+
* @param string $message
159+
* @return void
160+
* @throws Throwable
161+
* @throws ApiException
163162
*/
164163
public function messageSendToVk(ServerEvent $event, string $message): void
165164
{

0 commit comments

Comments
 (0)