Skip to content

Commit 56b1643

Browse files
committed
add wall_post_new
1 parent 4b22095 commit 56b1643

File tree

9 files changed

+297
-47
lines changed

9 files changed

+297
-47
lines changed

src/DataFetcher.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
use Astaroth\DataFetcher\Events\MessageEvent;
1010
use Astaroth\DataFetcher\Events\MessageNew;
11+
use Astaroth\DataFetcher\Events\WallPostNew;
1112

1213
/**
1314
* Class DataFetcher
@@ -79,6 +80,11 @@ public function messageEvent(): MessageEvent
7980
return new MessageEvent($this->data->object);
8081
}
8182

83+
public function wallPostNew(): WallPostNew
84+
{
85+
return new WallPostNew($this->data->object);
86+
}
87+
8288
/**
8389
* @return object
8490
*/

src/Enums/Events.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ class Events
1313
{
1414
public const MESSAGE_NEW = "message_new";
1515
public const MESSAGE_EVENT = "message_event";
16+
public const WALL_POST_NEW = "wall_post_new";
1617
}

src/Traits/EventTrait.php renamed to src/Events/EventTrait.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
<?php
22

3-
declare(strict_types=1);
4-
5-
6-
namespace Astaroth\DataFetcher\Traits;
73

4+
namespace Astaroth\DataFetcher\Events;
85

96
/**
10-
* Trait FillObjectTrait
7+
* Trait EventTrait
118
* @package Astaroth\DataFetcher\Events
129
*/
1310
trait EventTrait
@@ -41,13 +38,4 @@ protected function getField(string $field): mixed
4138
{
4239
return $this->$field ?? null;
4340
}
44-
45-
/**
46-
* peer_id - 2e9 = chat_id
47-
* @return int|null
48-
*/
49-
public function getChatId(): ?int
50-
{
51-
return $this->getField("chat_id");
52-
}
5341
}

src/Events/MessageEvent.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
<?php
22

3+
/** @noinspection PhpPureAttributeCanBeAddedInspection */
4+
/** @noinspection PhpUnusedPrivateFieldInspection */
5+
6+
37
declare(strict_types=1);
48

59

610
namespace Astaroth\DataFetcher\Events;
711

8-
use Astaroth\DataFetcher\ICompatibleEvent;
9-
use Astaroth\DataFetcher\Traits\EventTrait;
10-
1112
/**
1213
* Class MessageEvent
1314
* @url https://vk.com/dev/groups_events
1415
* @package Astaroth\DataFetcher
1516
*/
16-
final class MessageEvent implements ICompatibleEvent
17+
final class MessageEvent
1718
{
1819
use EventTrait;
1920

@@ -48,9 +49,9 @@ public function getEventId(): string
4849
}
4950

5051
/**
51-
* @return object
52+
* @return object|null
5253
*/
53-
public function getPayload(): object
54+
public function getPayload(): ?object
5455
{
5556
return $this->getField("payload");
5657
}
@@ -63,8 +64,12 @@ public function getConversationMessageId(): int
6364
return $this->getField("conversation_message_id");
6465
}
6566

66-
public function getFromId(): ?int
67+
/**
68+
* peer_id - 2e9 = chat_id
69+
* @return int|null
70+
*/
71+
public function getChatId(): ?int
6772
{
68-
return $this->getUserId();
73+
return $this->getField("chat_id");
6974
}
7075
}

src/Events/MessageNew.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1-
<?php /** @noinspection PhpPropertyOnlyWrittenInspection */
1+
<?php
2+
3+
/** @noinspection PhpPureAttributeCanBeAddedInspection */
4+
/** @noinspection PhpUnusedPrivateFieldInspection */
25

36
declare(strict_types=1);
47

58

69
namespace Astaroth\DataFetcher\Events;
710

8-
use Astaroth\DataFetcher\ICompatibleEvent;
9-
use Astaroth\DataFetcher\Traits\EventTrait;
1011

1112
/**
1213
* Class MessageNew
1314
* vk api >= 5.80
1415
* @url https://vk.com/dev/objects/message
1516
* @package Astaroth\DataFetcher
1617
*/
17-
final class MessageNew implements ICompatibleEvent
18+
final class MessageNew
1819
{
1920
use EventTrait;
2021

@@ -134,7 +135,7 @@ public function getGeo(): ?object
134135
}
135136

136137
/**
137-
* @return string|null
138+
* @return object|null
138139
*/
139140
public function getPayload(): ?object
140141
{
@@ -229,6 +230,11 @@ public function getMessageTag(): ?string
229230
return $this->getField("message_tag");
230231
}
231232

233+
public function getChatId(): ?int
234+
{
235+
return $this->getField("chat_id");
236+
}
237+
232238
/**
233239
* @return int
234240
*/

src/Events/WallPostNew.php

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
<?php
2+
3+
/** @noinspection PhpPureAttributeCanBeAddedInspection */
4+
5+
/** @noinspection PhpUnusedPrivateFieldInspection */
6+
7+
8+
namespace Astaroth\DataFetcher\Events;
9+
10+
/**
11+
* Class WallPostNew
12+
* @package Astaroth\DataFetcher\Events
13+
*/
14+
final class WallPostNew
15+
{
16+
use EventTrait;
17+
18+
private int $id;
19+
private int $from_id;
20+
private int $owner_id;
21+
private int $date;
22+
private int $marked_as_ads;
23+
private string $post_type;
24+
private string $text;
25+
private int $can_edit;
26+
private int $created_by;
27+
private object $comments;
28+
private bool $is_favorite;
29+
private object $donut;
30+
private int|float $short_text_rate;
31+
private int $can_delete;
32+
33+
/**
34+
* @return int
35+
*/
36+
public function getId(): int
37+
{
38+
return $this->getField("id");
39+
}
40+
41+
/**
42+
* @return int
43+
*/
44+
public function getFromId(): int
45+
{
46+
return $this->getField("from_id");
47+
}
48+
49+
/**
50+
* @return int
51+
*/
52+
public function getOwnerId(): int
53+
{
54+
return $this->getField("owner_id");
55+
}
56+
57+
/**
58+
* @return int
59+
*/
60+
public function getDate(): int
61+
{
62+
return $this->getField("date");
63+
}
64+
65+
/**
66+
* @return int
67+
*/
68+
public function getMarkedAsAds(): int
69+
{
70+
return $this->getField("marked_as_ads");
71+
}
72+
73+
/**
74+
* @return string
75+
*/
76+
public function getPostType(): string
77+
{
78+
return $this->getField("post_type");
79+
}
80+
81+
/**
82+
* @return string
83+
*/
84+
public function getText(): string
85+
{
86+
return $this->getField("text");
87+
}
88+
89+
/**
90+
* @return int
91+
*/
92+
public function getCanEdit(): int
93+
{
94+
return $this->getField("can_edit");
95+
}
96+
97+
/**
98+
* @return int
99+
*/
100+
public function getCreatedBy(): int
101+
{
102+
return $this->getField("created_by");
103+
}
104+
105+
/**
106+
* @return int
107+
*/
108+
public function getCanDelete(): int
109+
{
110+
return $this->getField("can_delete");
111+
}
112+
113+
/**
114+
* @return object
115+
*/
116+
public function getComments(): object
117+
{
118+
return $this->getField("comments");
119+
}
120+
121+
/**
122+
* @return bool
123+
*/
124+
public function isIsFavorite(): bool
125+
{
126+
return $this->getField("is_favorite");
127+
}
128+
129+
/**
130+
* @return object
131+
*/
132+
public function getDonut(): object
133+
{
134+
return $this->getField("donut");
135+
}
136+
137+
/**
138+
* @return float|int
139+
*/
140+
public function getShortTextRate(): float|int
141+
{
142+
return $this->getField("short_text_rate");
143+
}
144+
}

src/ICompatibleEvent.php

Lines changed: 0 additions & 19 deletions
This file was deleted.

tests/MessageNewTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
class MessageNewTest extends TestCase
1111
{
12-
private const RAW_INPUT_DATA_MESSAGE_NEW = '{"type": "message_new","object": {"message": {"date": 1622990967,"from_id": 418618,"id": 0, "action": {"type": "chat_kick_user","member_id": 418618}, "reply_message":[], "was_listened":false, "ref": "ref", "message_tag": "tag", "ref_source":"ref", "members_count":7,"admin_author_id":88,"pinned_at":72817288,"update_time":3283832, "out": 0,"peer_id": 2000000003,"text": "astaroth","conversation_message_id": 1377,"fwd_messages": [],"important": false,"random_id": 0,"payload": {"settings": "test_key"},"attachments": [{"type": "photo","photo": {"album_id": -3,"date": 1622993751,"id": 457242921,"owner_id": 418618,"has_tags": false,"access_key": "163e1a080d1691860e","sizes": [{ "height": 75, "url": "https://sun9-9.userapi.com/impg/_OcZbwysQ198r2aib3TPk8gNSFJo56hEKqTAuA/IH8MFsKRReI.jpg?size=42x75&quality=96&sign=4ee2d5efc7e36954ac4c06ffb7f8cada&c_uniq_tag=xdhjNELMVyOZwOslB_rlnjZdaOzn6KJk1qcgsorsXb0&type=album", "type": "s", "width": 42},{ "height": 130, "url": "https://sun9-9.userapi.com/impg/_OcZbwysQ198r2aib3TPk8gNSFJo56hEKqTAuA/IH8MFsKRReI.jpg?size=73x130&quality=96&sign=21ade76f738e9b0172d06099f334e55b&c_uniq_tag=TpgCFiU8I_huIzB6efqRgkaSm7sGb12aSdcw3nI2fF4&type=album", "type": "m", "width": 73},{ "height": 604, "url": "https://sun9-9.userapi.com/impg/_OcZbwysQ198r2aib3TPk8gNSFJo56hEKqTAuA/IH8MFsKRReI.jpg?size=340x604&quality=96&sign=062bf7ae6a014397c3d6a73bd0b45a6c&c_uniq_tag=jg4hMK3Br7efHLW-ktVegrTEOL2vvFzsMTP9SXRturg&type=album", "type": "x", "width": 340},{ "height": 807, "url": "https://sun9-9.userapi.com/impg/_OcZbwysQ198r2aib3TPk8gNSFJo56hEKqTAuA/IH8MFsKRReI.jpg?size=454x807&quality=96&sign=30bb4b5a3033610c63bc00c7bdf86c21&c_uniq_tag=RZjGH-zjMMDwOOdfavmDYB1gWImajsoOzCsXcmoF91Y&type=album", "type": "y", "width": 454},{ "height": 1080, "url": "https://sun9-9.userapi.com/impg/_OcZbwysQ198r2aib3TPk8gNSFJo56hEKqTAuA/IH8MFsKRReI.jpg?size=607x1080&quality=96&sign=52b27953fe92136a9aa64790eb46a28a&c_uniq_tag=UfKIP14ejN3ordaQJT7gDAikYoW0N7sXBbsE4XpD3TA&type=album", "type": "z", "width": 607},{ "height": 1600, "url": "https://sun9-9.userapi.com/impg/_OcZbwysQ198r2aib3TPk8gNSFJo56hEKqTAuA/IH8MFsKRReI.jpg?size=900x1600&quality=96&sign=42a9239e9a9af0a362d874974a3a5888&c_uniq_tag=D7jeBbJQYvnVeNZoaZUg7kPknLg0cG232zH3ggk9jAI&type=album", "type": "w", "width": 900},{ "height": 231, "url": "https://sun9-9.userapi.com/impg/_OcZbwysQ198r2aib3TPk8gNSFJo56hEKqTAuA/IH8MFsKRReI.jpg?size=130x231&quality=96&sign=2c75f5e29a764ec3a50d175515caf5eb&c_uniq_tag=WCBYn6ZOm_JCtUG_8AZ6ASZVVSpuBDdH0KqBoWyqw3g&type=album", "type": "o", "width": 130},{ "height": 355, "url": "https://sun9-9.userapi.com/impg/_OcZbwysQ198r2aib3TPk8gNSFJo56hEKqTAuA/IH8MFsKRReI.jpg?size=200x356&quality=96&sign=27311875cf52205dc4fd74386340d5ab&c_uniq_tag=vJR0YOqjFmeNGrMXLYYXGKGZpRKK3YK1nVakGDxBivI&type=album", "type": "p", "width": 200},{ "height": 569, "url": "https://sun9-9.userapi.com/impg/_OcZbwysQ198r2aib3TPk8gNSFJo56hEKqTAuA/IH8MFsKRReI.jpg?size=320x569&quality=96&sign=a5ac3cc36ee28ed9df3c17de160ae89c&c_uniq_tag=z9WIl9S-C8ChWis-tcqbrUAWA3kY9TwK_6kKWSyNMew&type=album", "type": "q", "width": 320},{"height": 900,"url": "https://sun9-9.userapi.com/impg/_OcZbwysQ198r2aib3TPk8gNSFJo56hEKqTAuA/IH8MFsKRReI.jpg?size=510x900&quality=96&crop=0,0,900,1588&sign=89c690ebe88d84c414982bb726352718&c_uniq_tag=-pOxAeKeQ9Lk6MIjkG31vAOW1W6jijzGFWVvbxB3kEw&type=album","type": "r","width": 510}],"text": ""}}],"geo": {"type": "point","coordinates": {"latitude": 57.918701,"longitude": 60.141824},"place": {"country": "Россия","city": "Нижний Тагил","title": "Нижний Тагил, Россия"}},"is_hidden": false,"is_cropped": true},"client_info": {"button_actions": ["text","vkpay","open_app","location","open_link","callback","intent_subscribe","intent_unsubscribe"],"keyboard": true,"inline_keyboard": true,"carousel": true,"lang_id": 0}},"group_id": 196756261,"event_id": "4ed07b8f5c5f56080ccd643aba529ec78e448eb1"}';
12+
private const RAW_INPUT_DATA_MESSAGE_NEW = '{"type": "message_new","object": {"message": {"date": 1622990967,"from_id": 418618,"id": 0, "action": {"type": "chat_kick_user","member_id": 418618}, "reply_message":{}, "was_listened":false, "ref": "ref", "message_tag": "tag", "ref_source":"ref", "members_count":7,"admin_author_id":88,"pinned_at":72817288,"update_time":3283832, "out": 0,"peer_id": 2000000003,"text": "astaroth","conversation_message_id": 1377,"fwd_messages": [],"important": false,"random_id": 0,"payload": {"settings": "test_key"},"attachments": [{"type": "photo","photo": {"album_id": -3,"date": 1622993751,"id": 457242921,"owner_id": 418618,"has_tags": false,"access_key": "163e1a080d1691860e","sizes": [{ "height": 75, "url": "https://sun9-9.userapi.com/impg/_OcZbwysQ198r2aib3TPk8gNSFJo56hEKqTAuA/IH8MFsKRReI.jpg?size=42x75&quality=96&sign=4ee2d5efc7e36954ac4c06ffb7f8cada&c_uniq_tag=xdhjNELMVyOZwOslB_rlnjZdaOzn6KJk1qcgsorsXb0&type=album", "type": "s", "width": 42},{ "height": 130, "url": "https://sun9-9.userapi.com/impg/_OcZbwysQ198r2aib3TPk8gNSFJo56hEKqTAuA/IH8MFsKRReI.jpg?size=73x130&quality=96&sign=21ade76f738e9b0172d06099f334e55b&c_uniq_tag=TpgCFiU8I_huIzB6efqRgkaSm7sGb12aSdcw3nI2fF4&type=album", "type": "m", "width": 73},{ "height": 604, "url": "https://sun9-9.userapi.com/impg/_OcZbwysQ198r2aib3TPk8gNSFJo56hEKqTAuA/IH8MFsKRReI.jpg?size=340x604&quality=96&sign=062bf7ae6a014397c3d6a73bd0b45a6c&c_uniq_tag=jg4hMK3Br7efHLW-ktVegrTEOL2vvFzsMTP9SXRturg&type=album", "type": "x", "width": 340},{ "height": 807, "url": "https://sun9-9.userapi.com/impg/_OcZbwysQ198r2aib3TPk8gNSFJo56hEKqTAuA/IH8MFsKRReI.jpg?size=454x807&quality=96&sign=30bb4b5a3033610c63bc00c7bdf86c21&c_uniq_tag=RZjGH-zjMMDwOOdfavmDYB1gWImajsoOzCsXcmoF91Y&type=album", "type": "y", "width": 454},{ "height": 1080, "url": "https://sun9-9.userapi.com/impg/_OcZbwysQ198r2aib3TPk8gNSFJo56hEKqTAuA/IH8MFsKRReI.jpg?size=607x1080&quality=96&sign=52b27953fe92136a9aa64790eb46a28a&c_uniq_tag=UfKIP14ejN3ordaQJT7gDAikYoW0N7sXBbsE4XpD3TA&type=album", "type": "z", "width": 607},{ "height": 1600, "url": "https://sun9-9.userapi.com/impg/_OcZbwysQ198r2aib3TPk8gNSFJo56hEKqTAuA/IH8MFsKRReI.jpg?size=900x1600&quality=96&sign=42a9239e9a9af0a362d874974a3a5888&c_uniq_tag=D7jeBbJQYvnVeNZoaZUg7kPknLg0cG232zH3ggk9jAI&type=album", "type": "w", "width": 900},{ "height": 231, "url": "https://sun9-9.userapi.com/impg/_OcZbwysQ198r2aib3TPk8gNSFJo56hEKqTAuA/IH8MFsKRReI.jpg?size=130x231&quality=96&sign=2c75f5e29a764ec3a50d175515caf5eb&c_uniq_tag=WCBYn6ZOm_JCtUG_8AZ6ASZVVSpuBDdH0KqBoWyqw3g&type=album", "type": "o", "width": 130},{ "height": 355, "url": "https://sun9-9.userapi.com/impg/_OcZbwysQ198r2aib3TPk8gNSFJo56hEKqTAuA/IH8MFsKRReI.jpg?size=200x356&quality=96&sign=27311875cf52205dc4fd74386340d5ab&c_uniq_tag=vJR0YOqjFmeNGrMXLYYXGKGZpRKK3YK1nVakGDxBivI&type=album", "type": "p", "width": 200},{ "height": 569, "url": "https://sun9-9.userapi.com/impg/_OcZbwysQ198r2aib3TPk8gNSFJo56hEKqTAuA/IH8MFsKRReI.jpg?size=320x569&quality=96&sign=a5ac3cc36ee28ed9df3c17de160ae89c&c_uniq_tag=z9WIl9S-C8ChWis-tcqbrUAWA3kY9TwK_6kKWSyNMew&type=album", "type": "q", "width": 320},{"height": 900,"url": "https://sun9-9.userapi.com/impg/_OcZbwysQ198r2aib3TPk8gNSFJo56hEKqTAuA/IH8MFsKRReI.jpg?size=510x900&quality=96&crop=0,0,900,1588&sign=89c690ebe88d84c414982bb726352718&c_uniq_tag=-pOxAeKeQ9Lk6MIjkG31vAOW1W6jijzGFWVvbxB3kEw&type=album","type": "r","width": 510}],"text": ""}}],"geo": {"type": "point","coordinates": {"latitude": 57.918701,"longitude": 60.141824},"place": {"country": "Россия","city": "Нижний Тагил","title": "Нижний Тагил, Россия"}},"is_hidden": false,"is_cropped": true},"client_info": {"button_actions": ["text","vkpay","open_app","location","open_link","callback","intent_subscribe","intent_unsubscribe"],"keyboard": true,"inline_keyboard": true,"carousel": true,"lang_id": 0}},"group_id": 196756261,"event_id": "4ed07b8f5c5f56080ccd643aba529ec78e448eb1"}';
1313
private MessageNew $m;
1414

1515
protected function setUp(): void
@@ -58,6 +58,12 @@ public function testGetPeerId(): void
5858
self::assertIsInt($this->m->getPeerId());
5959
}
6060

61+
62+
public function testGetChatId(): void
63+
{
64+
self::assertIsInt($this->m->getChatId());
65+
}
66+
6167
public function testGetAdminAuthorId(): void
6268
{
6369
self::assertIsInt($this->m->getAdminAuthorId());

0 commit comments

Comments
 (0)