generated from spatie/package-skeleton-laravel
-
-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #649 from andrey-helldar/patch/2024-09-20/12-13
Adding reaction processing when retrieving in webhooks
- Loading branch information
Showing
9 changed files
with
563 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DefStudio\Telegraph\DTO; | ||
|
||
use Carbon\CarbonInterface; | ||
use Illuminate\Contracts\Support\Arrayable; | ||
use Illuminate\Support\Carbon; | ||
|
||
/** | ||
* @implements Arrayable<string, string|int|bool|array<string, mixed>> | ||
*/ | ||
class Reaction implements Arrayable | ||
{ | ||
private int $id; | ||
|
||
private Chat $chat; | ||
private ?Chat $actorChat = null; | ||
|
||
private ?User $from = null; | ||
|
||
/** | ||
* @var array<array<string, string>> | ||
*/ | ||
private array $oldReaction = []; | ||
|
||
/** | ||
* @var array<array<string, string>> | ||
*/ | ||
private array $newReaction = []; | ||
|
||
private CarbonInterface $date; | ||
|
||
private function __construct() | ||
{ | ||
} | ||
|
||
/** | ||
* @param array{ | ||
* message_id: int, | ||
* chat: array<string, mixed>, | ||
* actor_chat?: array<string, mixed>, | ||
* user?: array<string, mixed>, | ||
* date: int, | ||
* old_reaction: array<int, array<string, string>>, | ||
* new_reaction: array<int, array<string, string>> | ||
* } $data | ||
*/ | ||
public static function fromArray(array $data): Reaction | ||
{ | ||
$reaction = new self(); | ||
|
||
$reaction->id = $data['message_id']; | ||
|
||
/* @phpstan-ignore-next-line */ | ||
$reaction->chat = Chat::fromArray($data['chat']); | ||
|
||
if (isset($data['actor_chat'])) { | ||
/* @phpstan-ignore-next-line */ | ||
$reaction->actorChat = Chat::fromArray($data['actor_chat']); | ||
} | ||
|
||
if (isset($data['user'])) { | ||
/* @phpstan-ignore-next-line */ | ||
$reaction->from = User::fromArray($data['user']); | ||
} | ||
|
||
$reaction->date = Carbon::createFromTimestamp($data['date']); | ||
|
||
$reaction->oldReaction = $data['old_reaction']; | ||
$reaction->newReaction = $data['new_reaction']; | ||
|
||
return $reaction; | ||
} | ||
|
||
public function id(): int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function chat(): Chat | ||
{ | ||
return $this->chat; | ||
} | ||
|
||
public function actorChat(): ?Chat | ||
{ | ||
return $this->actorChat; | ||
} | ||
|
||
public function from(): ?User | ||
{ | ||
return $this->from; | ||
} | ||
|
||
/** | ||
* @return array<array<string, string>> | ||
*/ | ||
public function oldReaction(): array | ||
{ | ||
return $this->oldReaction; | ||
} | ||
|
||
/** | ||
* @return array<array<string, string>> | ||
*/ | ||
public function newReaction(): array | ||
{ | ||
return $this->newReaction; | ||
} | ||
|
||
public function date(): CarbonInterface | ||
{ | ||
return $this->date; | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
return array_filter([ | ||
'id' => $this->id, | ||
'chat' => $this->chat->toArray(), | ||
'actor_chat' => $this->actorChat?->toArray(), | ||
'from' => $this->from?->toArray(), | ||
'old_reaction' => $this->oldReaction, | ||
'new_reaction' => $this->newReaction, | ||
'date' => $this->date->toISOString(), | ||
], fn ($value) => $value !== null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.