From ef06cf4afbddaee4a2606c80c6523de4f0647e9b Mon Sep 17 00:00:00 2001 From: netkas Date: Fri, 4 Oct 2024 13:31:08 -0400 Subject: [PATCH] Added MessageReactionUpdated --- .../Objects/MessageReactionUpdated.php | 131 ++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 src/TgBotLib/Objects/MessageReactionUpdated.php diff --git a/src/TgBotLib/Objects/MessageReactionUpdated.php b/src/TgBotLib/Objects/MessageReactionUpdated.php new file mode 100644 index 0000000..94d4a6d --- /dev/null +++ b/src/TgBotLib/Objects/MessageReactionUpdated.php @@ -0,0 +1,131 @@ +chat; + } + + /** + * Unique identifier of the message inside the chat + * + * @return int + */ + public function getMessageId(): int + { + return $this->message_id; + } + + /** + * Optional. The user that changed the reaction, if the user isn't anonymous + * + * @return User|null + */ + public function getUser(): ?User + { + return $this->user; + } + + /** + * Optional. The chat on behalf of which the reaction was changed, if the user is anonymous + * + * @return Chat|null + */ + public function getActorChat(): ?Chat + { + return $this->actor_chat; + } + + /** + * Date of the change in Unix time + * + * @return int + */ + public function getDate(): int + { + return $this->date; + } + + /** + * Previous list of reaction types that were set by the user + * + * @return ReactionType[] + */ + public function getOldReaction(): array + { + return $this->old_reaction; + } + + /** + * New list of reaction types that have been set by the user + * + * @return ReactionType[] + */ + public function getNewReaction(): array + { + return $this->new_reaction; + } + + /** + * @inheritDoc + */ + public function toArray(): ?array + { + return [ + 'chat' => $this->chat?->toArray(), + 'message_id' => $this->message_id, + 'user' => $this->user?->toArray(), + 'actor_chat' => $this->actor_chat?->toArray(), + 'date' => $this->date, + 'old_reaction' => array_map(fn(ReactionType $reaction) => $reaction->toArray(), $this->old_reaction), + 'new_reaction' => array_map(fn(ReactionType $reaction) => $reaction->toArray(), $this->new_reaction) + ]; + } + + /** + * @inheritDoc + */ + public static function fromArray(?array $data): ?ObjectTypeInterface + { + if($data === null) + { + return null; + } + + $object = new self(); + $object->chat = isset($data['chat']) ? Chat::fromArray($data['chat']) : null; + $object->message_id = $data['message_id']; + $object->user = isset($data['user']) ? User::fromArray($data['user']) : null; + $object->actor_chat = isset($data['actor_chat']) ? Chat::fromArray($data['actor_chat']) : null; + $object->date = $data['date']; + $object->old_reaction = array_map(fn(array $reaction) => ReactionType::fromArray($reaction), $data['old_reaction']); + $object->new_reaction = array_map(fn(array $reaction) => ReactionType::fromArray($reaction), $data['new_reaction']); + + return $object; + } + } \ No newline at end of file