summaryrefslogtreecommitdiff
path: root/matrix-specification/Events/Room/CreateEvent.php
blob: eccda101238f5aaa119c19ced317a20645b8d4a9 (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php

namespace Matrix\Events\Room;

use Matrix\Data\Room\PreviousRoom;
use Matrix\Data\UnsignedData;
use Matrix\Enums\EventType;
use Matrix\Events\StateEvent;

class CreateEvent extends StateEvent
{
  /**
   * @param ?string[] $additionalCreators
   */
  public function __construct(
    string $eventId,
    int $originServerTimestamp,
    string $roomId,
    string $sender,
    string $roomVersion,
    ?array $additionalCreators = null,
    ?string $creator = null,
    bool $federate = true,
    ?PreviousRoom $predecessor = null,
    ?string $roomType = null,
    string $stateKey = "",
    ?UnsignedData $unsigned = null,
  )
  {
    if (intval($roomVersion) <= 10) {
      if (empty($creator)) {
        throw new \InvalidArgumentException("creator is required in room versions 1 - 10");
      }
    }

    parent::__construct(
      array_filter([
        "additional_creators" => $additionalCreators,
        "creator" => intval($roomVersion) <= 10 ? $creator : $sender,
        "m.federate" => $federate,
        "predecessor" => $predecessor,
        "room_version" => $roomVersion,
        "type" => $roomType,
      ], fn ($value) => ! is_null($value)),
      $eventId,
      $originServerTimestamp,
      $roomId,
      $sender,
      $stateKey,
      EventType::ROOM_CREATE,
      $unsigned,
    );
  }
}