diff options
Diffstat (limited to 'matrix-specification/Data')
| -rw-r--r-- | matrix-specification/Data/DeviceLists.php | 4 | ||||
| -rw-r--r-- | matrix-specification/Data/Room/AllowCondition.php | 24 | ||||
| -rw-r--r-- | matrix-specification/Data/Room/AvatarInfo.php | 28 | ||||
| -rw-r--r-- | matrix-specification/Data/Room/JoinedRoom.php | 4 | ||||
| -rw-r--r-- | matrix-specification/Data/Room/PreviousRoom.php | 20 | ||||
| -rw-r--r-- | matrix-specification/Data/Room/Rooms.php | 10 | ||||
| -rw-r--r-- | matrix-specification/Data/Room/TextualRepresentation.php | 20 | ||||
| -rw-r--r-- | matrix-specification/Data/Room/ThumbnailInfo.php | 24 | ||||
| -rw-r--r-- | matrix-specification/Data/Room/TopicContentBlock.php | 21 | ||||
| -rw-r--r-- | matrix-specification/Data/UnsignedData.php | 32 |
10 files changed, 178 insertions, 9 deletions
diff --git a/matrix-specification/Data/DeviceLists.php b/matrix-specification/Data/DeviceLists.php index 33d9459..eef2df4 100644 --- a/matrix-specification/Data/DeviceLists.php +++ b/matrix-specification/Data/DeviceLists.php @@ -17,8 +17,8 @@ class DeviceLists implements \JsonSerializable public function jsonSerialize(): array { return [ - "changed" => $this->events, - "left" => $this->events, + "changed" => $this->changed, + "left" => $this->left, ]; } } diff --git a/matrix-specification/Data/Room/AllowCondition.php b/matrix-specification/Data/Room/AllowCondition.php new file mode 100644 index 0000000..600c618 --- /dev/null +++ b/matrix-specification/Data/Room/AllowCondition.php @@ -0,0 +1,24 @@ +<?php + +namespace Matrix\Data\Room; + +class AllowCondition implements \JsonSerializable +{ + public function __construct( + private string $type, + private ?string $roomId = null, + ) + { + if ($type == "m.room.membership" && empty($roomId)) { + throw new \InvalidArgumentException("room id is required"); + } + } + + public function jsonSerialize(): array + { + return array_filter([ + "room_id" => $this->roomId, + "type" => $this->type, + ], fn ($value) => ! is_null($value)); + } +} diff --git a/matrix-specification/Data/Room/AvatarInfo.php b/matrix-specification/Data/Room/AvatarInfo.php new file mode 100644 index 0000000..473beb9 --- /dev/null +++ b/matrix-specification/Data/Room/AvatarInfo.php @@ -0,0 +1,28 @@ +<?php + +namespace Matrix\Data\Room; + +class AvatarInfo implements \JsonSerializable +{ + public function __construct( + private int $height, + private string $mimeType, + private int $fileSize, + private ThumbnailInfo $thumbnailInfo, + private string $thumbnailUrl, + private int $width, + ) + {} + + public function jsonSerialize(): array + { + return [ + "h" => $this->height, + "mimetype" => $this->mimeType, + "size" => $this->fileSize, + "thumbnail_info" => $this->thumbnailInfo, + "thumbnail_url" => $this->thumbnailUrl, + "w" => $this->width, + ]; + } +} diff --git a/matrix-specification/Data/Room/JoinedRoom.php b/matrix-specification/Data/Room/JoinedRoom.php index 0057071..f78eaea 100644 --- a/matrix-specification/Data/Room/JoinedRoom.php +++ b/matrix-specification/Data/Room/JoinedRoom.php @@ -24,14 +24,14 @@ class JoinedRoom implements \JsonSerializable public function jsonSerialize(): array { return array_filter([ - "account_data" => $this->inviteState, + "account_data" => $this->accountData, "ephemeral" => $this->ephemeral, "state" => $this->state, "state_after" => $this->stateAfter, "summary" => $this->summary, "timeline" => $this->timeline, "unread_notifications" => $this->unreadNotifications, - "unreadThreadNotifications" => $this->unreadThreadNotifications, + "unreadThreadNotifications" => empty($this->unreadThreadNotifications) ? new \stdClass() : $this->unreadNotifications, ], fn ($value) => ! is_null($value)); } } diff --git a/matrix-specification/Data/Room/PreviousRoom.php b/matrix-specification/Data/Room/PreviousRoom.php new file mode 100644 index 0000000..ced4172 --- /dev/null +++ b/matrix-specification/Data/Room/PreviousRoom.php @@ -0,0 +1,20 @@ +<?php + +namespace Matrix\Data\Room; + +class PreviousRoom implements \JsonSerializable +{ + public function __construct( + private string $roomId, + private ?string $eventId = null, + ) + {} + + public function jsonSerialize(): array + { + return array_filter([ + "event_id" => $this->eventId, + "room_id" => $this->roomId, + ], fn ($value) => ! is_null($value)); + } +} diff --git a/matrix-specification/Data/Room/Rooms.php b/matrix-specification/Data/Room/Rooms.php index 1a84608..4d2cdf6 100644 --- a/matrix-specification/Data/Room/Rooms.php +++ b/matrix-specification/Data/Room/Rooms.php @@ -21,17 +21,17 @@ class Rooms implements \JsonSerializable public function jsonSerialize(): array { return [ - "invite" => $this->invite ?? new \stdClass(), - "join" => $this->join ?? new \stdClass(), - "knock" => $this->knock ?? new \stdClass(), - "leave" => $this->leave ?? new \stdClass(), + "invite" => empty($this->invite) ? new \stdClass() : $this->invite, + "join" => empty($this->join) ? new \stdClass() : $this->join, + "knock" => empty($this->knock) ? new \stdClass() : $this->knock, + "leave" => empty($this->leave) ? new \stdClass() : $this->leave, ]; } /** * @return InvitedRoom[] */ - public function getInvite(): ?array + public function getInvited(): ?array { return $this->invite; } diff --git a/matrix-specification/Data/Room/TextualRepresentation.php b/matrix-specification/Data/Room/TextualRepresentation.php new file mode 100644 index 0000000..9b66f48 --- /dev/null +++ b/matrix-specification/Data/Room/TextualRepresentation.php @@ -0,0 +1,20 @@ +<?php + +namespace Matrix\Data\Room; + +class TextualRepresentation implements \JsonSerializable +{ + public function __construct( + private string $body, + private ?string $mimeType = "text/plain", + ) + {} + + public function jsonSerialize(): array + { + return array_filter([ + "body" => $this->body, + "mimetype" => $this->mimeType, + ], fn ($value) => ! is_null($value)); + } +} diff --git a/matrix-specification/Data/Room/ThumbnailInfo.php b/matrix-specification/Data/Room/ThumbnailInfo.php new file mode 100644 index 0000000..31a264b --- /dev/null +++ b/matrix-specification/Data/Room/ThumbnailInfo.php @@ -0,0 +1,24 @@ +<?php + +namespace Matrix\Data\Room; + +class ThumbnailInfo implements \JsonSerializable +{ + public function __construct( + private int $height, + private string $mimeType, + private int $fileSize, + private int $width, + ) + {} + + public function jsonSerialize(): array + { + return [ + "h" => $this->height, + "mimetype" => $this->mimeType, + "size" => $this->fileSize, + "w" => $this->width, + ]; + } +} diff --git a/matrix-specification/Data/Room/TopicContentBlock.php b/matrix-specification/Data/Room/TopicContentBlock.php new file mode 100644 index 0000000..96341d0 --- /dev/null +++ b/matrix-specification/Data/Room/TopicContentBlock.php @@ -0,0 +1,21 @@ +<?php + +namespace Matrix\Data\Room; + +class TopicContentBlock implements \JsonSerializable +{ + /** + * @param TextualRepresentation[] $text + */ + public function __construct( + private array $text, + ) + {} + + public function jsonSerialize(): array + { + return [ + "m.text" => $this->text, + ]; + } +} diff --git a/matrix-specification/Data/UnsignedData.php b/matrix-specification/Data/UnsignedData.php new file mode 100644 index 0000000..a1748cf --- /dev/null +++ b/matrix-specification/Data/UnsignedData.php @@ -0,0 +1,32 @@ +<?php + +namespace Matrix\Data; + +use Matrix\Enums\MembershipState; +use Matrix\Events\ClientEvent; + +/** + * @see https://spec.matrix.org/v1.16/client-server-api/#definition-clientevent_unsigneddata + */ +class UnsignedData implements \JsonSerializable +{ + public function __construct( + private ?int $age = null, + private ?MembershipState $membership = null, + private ?array $previousContent = null, + private ?ClientEvent $redactedBecause = null, + private ?string $transactionId = null, + ) + {} + + public function jsonSerialize(): array + { + return array_filter([ + "age" => $this->age, + "membership" => $this->membership, + "prev_content" => $this->previousContent, + "redacted_because" => $this->redactedBecause, + "transaction_id" => $this->transactionId, + ], fn ($value) => ! is_null($value)); + } +} |
