diff options
Diffstat (limited to 'matrix-specification/Data/Filters')
| -rw-r--r-- | matrix-specification/Data/Filters/EventFilter.php | 36 | ||||
| -rw-r--r-- | matrix-specification/Data/Filters/RoomEventFilter.php | 50 | ||||
| -rw-r--r-- | matrix-specification/Data/Filters/RoomFilter.php | 39 |
3 files changed, 125 insertions, 0 deletions
diff --git a/matrix-specification/Data/Filters/EventFilter.php b/matrix-specification/Data/Filters/EventFilter.php new file mode 100644 index 0000000..98788ad --- /dev/null +++ b/matrix-specification/Data/Filters/EventFilter.php @@ -0,0 +1,36 @@ +<?php + +namespace Matrix\Data\Filters; + +class EventFilter implements \JsonSerializable +{ + /** + * @param string[] $notSenders + * @param string[] $notTypes + * @param string[] $senders + * @param string[] $types + */ + public function __construct( + private ?int $limit = null, + private ?array $notSenders = null, + private ?array $notTypes = null, + private ?array $senders = null, + private ?array $types = null, + ) + { + if (! is_null($limit) && $limit <= 0) { + throw new \InvalidArgumentException("limit must be an integer greater than 0"); + } + } + + public function jsonSerialize(): array + { + return array_filter([ + "limit" => $this->limit, + "not_senders" => $this->notSenders, + "not_types" => $this->notTypes, + "senders" => $this->senders, + "types" => $this->types, + ], "is_null"); + } +} diff --git a/matrix-specification/Data/Filters/RoomEventFilter.php b/matrix-specification/Data/Filters/RoomEventFilter.php new file mode 100644 index 0000000..915c9a0 --- /dev/null +++ b/matrix-specification/Data/Filters/RoomEventFilter.php @@ -0,0 +1,50 @@ +<?php + +namespace Matrix\Data\Filters; + +class RoomEventFilter extends EventFilter +{ + /** + * @param string[] $notRooms + * @param string[] $notSenders + * @param string[] $notTypes + * @param string[] $rooms + * @param string[] $senders + * @param string[] $types + */ + public function __construct( + private ?bool $containsUrl = null, + private ?bool $includeRedundantMembers = null, + private ?bool $lazyLoadMembers = null, + ?int $limit = null, + private ?array $notRooms = null, + ?array $notSenders = null, + ?array $notTypes = null, + private ?array $rooms = null, + ?array $senders = null, + ?array $types = null, + private ?bool $unreadThreadNotifications = null, + ) + { + parent::__construct($limit, $notSenders, $notTypes, $senders, $types); + } + + public function setDefaults(): void + { + $this->includeRedundantMembers ??= false; + $this->lazyLoadMembers ??= false; + $this->unreadThreadNotifications ??= false; + } + + public function jsonSerialize(): array + { + return parent::jsonSerialize() + array_filter([ + "contains_url" => $this->containsUrl, + "include_redundant_members" => $this->includeRedundantMembers, + "lazy_load_members" => $this->lazyLoadMembers, + "not_rooms" => $this->notRooms, + "rooms" => $this->rooms, + "unread_thread_notifications" => $this->unreadThreadNotifications, + ], "is_null"); + } +} diff --git a/matrix-specification/Data/Filters/RoomFilter.php b/matrix-specification/Data/Filters/RoomFilter.php new file mode 100644 index 0000000..dd110bd --- /dev/null +++ b/matrix-specification/Data/Filters/RoomFilter.php @@ -0,0 +1,39 @@ +<?php + +namespace Matrix\Data\Filters; + +class RoomFilter +{ + /** + * @param string[] $notRooms + * @param string[] $rooms + */ + public function __construct( + private ?RoomEventFilter $accountData = null, + private ?RoomEventFilter $ephemeral = null, + private ?bool $includeLeave = null, + private ?array $notRooms = null, + private ?array $rooms = null, + private ?RoomEventFilter $state = null, + private ?RoomEventFilter $timeline = null, + ) + {} + + public function setDefaults(): void + { + $this->includeLeave ??= false; + } + + public function jsonSerialize(): array + { + return array_filter([ + "account_data" => $this->accountData, + "ephemeral" => $this->ephemeral, + "include_leave" => $this->includeLeave, + "not_rooms" => $this->notRooms, + "rooms" => $this->rooms, + "state" => $this->state, + "timeline" => $this->timeline, + ], "is_null"); + } +} |
