Skip to content

Commit

Permalink
add wall_post_new
Browse files Browse the repository at this point in the history
  • Loading branch information
labi-le committed Jun 30, 2021
1 parent 4b22095 commit 56b1643
Show file tree
Hide file tree
Showing 9 changed files with 297 additions and 47 deletions.
6 changes: 6 additions & 0 deletions src/DataFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

use Astaroth\DataFetcher\Events\MessageEvent;
use Astaroth\DataFetcher\Events\MessageNew;
use Astaroth\DataFetcher\Events\WallPostNew;

/**
* Class DataFetcher
Expand Down Expand Up @@ -79,6 +80,11 @@ public function messageEvent(): MessageEvent
return new MessageEvent($this->data->object);
}

public function wallPostNew(): WallPostNew
{
return new WallPostNew($this->data->object);
}

/**
* @return object
*/
Expand Down
1 change: 1 addition & 0 deletions src/Enums/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ class Events
{
public const MESSAGE_NEW = "message_new";
public const MESSAGE_EVENT = "message_event";
public const WALL_POST_NEW = "wall_post_new";
}
16 changes: 2 additions & 14 deletions src/Traits/EventTrait.php → src/Events/EventTrait.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
<?php

declare(strict_types=1);


namespace Astaroth\DataFetcher\Traits;

namespace Astaroth\DataFetcher\Events;

/**
* Trait FillObjectTrait
* Trait EventTrait
* @package Astaroth\DataFetcher\Events
*/
trait EventTrait
Expand Down Expand Up @@ -41,13 +38,4 @@ protected function getField(string $field): mixed
{
return $this->$field ?? null;
}

/**
* peer_id - 2e9 = chat_id
* @return int|null
*/
public function getChatId(): ?int
{
return $this->getField("chat_id");
}
}
21 changes: 13 additions & 8 deletions src/Events/MessageEvent.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
<?php

/** @noinspection PhpPureAttributeCanBeAddedInspection */
/** @noinspection PhpUnusedPrivateFieldInspection */


declare(strict_types=1);


namespace Astaroth\DataFetcher\Events;

use Astaroth\DataFetcher\ICompatibleEvent;
use Astaroth\DataFetcher\Traits\EventTrait;

/**
* Class MessageEvent
* @url https://vk.com/dev/groups_events
* @package Astaroth\DataFetcher
*/
final class MessageEvent implements ICompatibleEvent
final class MessageEvent
{
use EventTrait;

Expand Down Expand Up @@ -48,9 +49,9 @@ public function getEventId(): string
}

/**
* @return object
* @return object|null
*/
public function getPayload(): object
public function getPayload(): ?object
{
return $this->getField("payload");
}
Expand All @@ -63,8 +64,12 @@ public function getConversationMessageId(): int
return $this->getField("conversation_message_id");
}

public function getFromId(): ?int
/**
* peer_id - 2e9 = chat_id
* @return int|null
*/
public function getChatId(): ?int
{
return $this->getUserId();
return $this->getField("chat_id");
}
}
16 changes: 11 additions & 5 deletions src/Events/MessageNew.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
<?php /** @noinspection PhpPropertyOnlyWrittenInspection */
<?php

/** @noinspection PhpPureAttributeCanBeAddedInspection */
/** @noinspection PhpUnusedPrivateFieldInspection */

declare(strict_types=1);


namespace Astaroth\DataFetcher\Events;

use Astaroth\DataFetcher\ICompatibleEvent;
use Astaroth\DataFetcher\Traits\EventTrait;

/**
* Class MessageNew
* vk api >= 5.80
* @url https://vk.com/dev/objects/message
* @package Astaroth\DataFetcher
*/
final class MessageNew implements ICompatibleEvent
final class MessageNew
{
use EventTrait;

Expand Down Expand Up @@ -134,7 +135,7 @@ public function getGeo(): ?object
}

/**
* @return string|null
* @return object|null
*/
public function getPayload(): ?object
{
Expand Down Expand Up @@ -229,6 +230,11 @@ public function getMessageTag(): ?string
return $this->getField("message_tag");
}

public function getChatId(): ?int
{
return $this->getField("chat_id");
}

/**
* @return int
*/
Expand Down
144 changes: 144 additions & 0 deletions src/Events/WallPostNew.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<?php

/** @noinspection PhpPureAttributeCanBeAddedInspection */

/** @noinspection PhpUnusedPrivateFieldInspection */


namespace Astaroth\DataFetcher\Events;

/**
* Class WallPostNew
* @package Astaroth\DataFetcher\Events
*/
final class WallPostNew
{
use EventTrait;

private int $id;
private int $from_id;
private int $owner_id;
private int $date;
private int $marked_as_ads;
private string $post_type;
private string $text;
private int $can_edit;
private int $created_by;
private object $comments;
private bool $is_favorite;
private object $donut;
private int|float $short_text_rate;
private int $can_delete;

/**
* @return int
*/
public function getId(): int
{
return $this->getField("id");
}

/**
* @return int
*/
public function getFromId(): int
{
return $this->getField("from_id");
}

/**
* @return int
*/
public function getOwnerId(): int
{
return $this->getField("owner_id");
}

/**
* @return int
*/
public function getDate(): int
{
return $this->getField("date");
}

/**
* @return int
*/
public function getMarkedAsAds(): int
{
return $this->getField("marked_as_ads");
}

/**
* @return string
*/
public function getPostType(): string
{
return $this->getField("post_type");
}

/**
* @return string
*/
public function getText(): string
{
return $this->getField("text");
}

/**
* @return int
*/
public function getCanEdit(): int
{
return $this->getField("can_edit");
}

/**
* @return int
*/
public function getCreatedBy(): int
{
return $this->getField("created_by");
}

/**
* @return int
*/
public function getCanDelete(): int
{
return $this->getField("can_delete");
}

/**
* @return object
*/
public function getComments(): object
{
return $this->getField("comments");
}

/**
* @return bool
*/
public function isIsFavorite(): bool
{
return $this->getField("is_favorite");
}

/**
* @return object
*/
public function getDonut(): object
{
return $this->getField("donut");
}

/**
* @return float|int
*/
public function getShortTextRate(): float|int
{
return $this->getField("short_text_rate");
}
}
19 changes: 0 additions & 19 deletions src/ICompatibleEvent.php

This file was deleted.

8 changes: 7 additions & 1 deletion tests/MessageNewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class MessageNewTest extends TestCase
{
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"}';
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"}';
private MessageNew $m;

protected function setUp(): void
Expand Down Expand Up @@ -58,6 +58,12 @@ public function testGetPeerId(): void
self::assertIsInt($this->m->getPeerId());
}


public function testGetChatId(): void
{
self::assertIsInt($this->m->getChatId());
}

public function testGetAdminAuthorId(): void
{
self::assertIsInt($this->m->getAdminAuthorId());
Expand Down
Loading

0 comments on commit 56b1643

Please sign in to comment.