Skip to content

Commit

Permalink
Added new_chat_members to Message object
Browse files Browse the repository at this point in the history
  • Loading branch information
unreal4u committed May 18, 2017
1 parent c12b995 commit f89d869
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/Telegram/Types/Custom/UserArray.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types = 1);

namespace unreal4u\TelegramAPI\Telegram\Types\Custom;

use unreal4u\TelegramAPI\Abstracts\CustomType;
use unreal4u\TelegramAPI\Telegram\Types\User;
use unreal4u\TelegramAPI\Interfaces\CustomArrayType;
use Psr\Log\LoggerInterface;

/**
* Mockup class to generate a real telegram update representation
*/
class UserArray extends CustomType implements CustomArrayType
{
public function __construct(array $data = null, LoggerInterface $logger = null)
{
if (count($data) !== 0) {
foreach ($data as $id => $chatMember) {
$this->data[$id] = new User($chatMember, $logger);
}
}
}

/**
* Traverses through our $data, yielding the result set
*
* @return ChatMember[]
*/
public function traverseObject()
{
foreach ($this->data as $user) {
yield $user;
}
}
}
10 changes: 10 additions & 0 deletions src/Telegram/Types/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use unreal4u\TelegramAPI\Abstracts\TelegramTypes;
use unreal4u\TelegramAPI\Telegram\Types\Custom\PhotoSizeArray;
use unreal4u\TelegramAPI\Telegram\Types\Custom\MessageEntityArray;
use unreal4u\TelegramAPI\Telegram\Types\Custom\UserArray;

/**
* This object represents a message.
Expand Down Expand Up @@ -139,6 +140,13 @@ class Message extends TelegramTypes
*/
public $video_note;

/**
* Optional. New members that were added to the group or supergroup and information about them (the bot itself may
* be one of these members)
* @var User[]
*/
public $new_chat_members;

/**
* Optional. Caption for the photo or video
* @var string
Expand Down Expand Up @@ -266,6 +274,8 @@ protected function mapSubObjects(string $key, array $data): TelegramTypes
case 'new_chat_member':
case 'left_chat_member':
return new User($data, $this->logger);
case 'new_chat_members':
return new UserArray($data, $this->logger);
case 'photo':
case 'new_chat_photo':
return new PhotoSizeArray($data, $this->logger);
Expand Down

0 comments on commit f89d869

Please sign in to comment.