diff options
Diffstat (limited to 'src/Events')
-rw-r--r-- | src/Events/Event.php | 16 | ||||
-rw-r--r-- | src/Events/PresenceEvent.php | 40 | ||||
-rw-r--r-- | src/Events/RoomMemberEvent.php | 33 | ||||
-rw-r--r-- | src/Events/RoomNameEvent.php | 33 |
4 files changed, 122 insertions, 0 deletions
diff --git a/src/Events/Event.php b/src/Events/Event.php new file mode 100644 index 0000000..cab1b14 --- /dev/null +++ b/src/Events/Event.php @@ -0,0 +1,16 @@ +<?php + +namespace App\Events; + +use App\Types\EventType; + +abstract class Event +{ + public function __construct( + protected EventType $type, + ) + {} + + abstract public function fromJson(string $json): static; + abstract public function toJsonEncodeable(): array; +} diff --git a/src/Events/PresenceEvent.php b/src/Events/PresenceEvent.php new file mode 100644 index 0000000..e3a54b3 --- /dev/null +++ b/src/Events/PresenceEvent.php @@ -0,0 +1,40 @@ +<?php + +namespace App\Events; + +use App\Types\EventType; +use App\Types\PresenceState; + +class PresenceEvent extends Event +{ + public function __construct( + private string $sender, + private string $avatarUrl = "mxc://localhost/wefuiwegh8742w", + private int $lastActiveAgo = 1234, + private bool $currentlyActive = false, + private PresenceState $presence = PresenceState::ONLINE, + private string $statusMessage = "", + ) + { + parent::__construct(EventType::PRESENCE); + } + + public function fromJson(string $json): static + { + } + + public function toJsonEncodeable(): array + { + return [ + "type" => $this->type, + "sender" => $this->sender, + "content" => [ + "avatar_url" => $this->avatarUrl, + "currently_active" => $this->currentlyActive, + "last_active_ago" => $this->lastActiveAgo, + "presence" => $this->presence, + "status_msg" => $this->statusMessage, + ], + ]; + } +} diff --git a/src/Events/RoomMemberEvent.php b/src/Events/RoomMemberEvent.php new file mode 100644 index 0000000..02793ea --- /dev/null +++ b/src/Events/RoomMemberEvent.php @@ -0,0 +1,33 @@ +<?php + +namespace App\Events; + +use App\Types\EventType; + +class RoomMemberEvent extends Event +{ + public function __construct( + private string $sender, + private string $stateKey, + private string $membership, + ) + { + parent::__construct(EventType::ROOM_MEMBER); + } + + public function fromJson(string $json): static + { + } + + public function toJsonEncodeable(): array + { + return [ + "type" => $this->type, + "sender" => $this->sender, + "state_key" => $this->stateKey, + "content" => [ + "membership" => $this->membership, + ], + ]; + } +} diff --git a/src/Events/RoomNameEvent.php b/src/Events/RoomNameEvent.php new file mode 100644 index 0000000..59abbe2 --- /dev/null +++ b/src/Events/RoomNameEvent.php @@ -0,0 +1,33 @@ +<?php + +namespace App\Events; + +use App\Types\EventType; + +class RoomNameEvent extends Event +{ + public function __construct( + private string $sender, + private string $stateKey, + private string $name, + ) + { + parent::__construct(EventType::ROOM_NAME); + } + + public function fromJson(string $json): static + { + } + + public function toJsonEncodeable(): array + { + return [ + "type" => $this->type, + "sender" => $this->sender, + "state_key" => $this->stateKey, + "content" => [ + "name" => $this->name, + ], + ]; + } +} |