summaryrefslogtreecommitdiff
path: root/matrix-specification/Data/Filters/RoomFilter.php
blob: fe741c58afab462f757de5e050763d396480e24b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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,
    ], fn ($value) => ! is_null($value));
  }
}