summaryrefslogtreecommitdiff
path: root/matrix-specification/Events/StateEvent.php
blob: 7fe7c83ce3b189c82185de50a96a7802529ef425 (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
<?php

namespace Matrix\Events;

use Matrix\Data\UnsignedData;
use Matrix\Enums\EventType;

class StateEvent extends ClientEvent
{
  public function __construct(
    array $content,
    string $eventId,
    int $originServerTimestamp,
    string $roomId,
    string $sender,
    protected string $stateKey,
    EventType $type,
    ?UnsignedData $unsigned = null,
  )
  {
    parent::__construct(
      $content,
      $eventId,
      $originServerTimestamp,
      $roomId,
      $sender,
      $type,
      $unsigned,
    );
  }

  public function jsonSerialize(): array
  {
    return [
      "content" => $this->content ?: new \stdClass,
      "event_id" => $this->eventId,
      "origin_server_ts" => $this->originServerTimestamp,
      "room_id" => $this->roomId,
      "sender" => $this->sender,
      "state_key" => $this->stateKey,
      "type" => $this->type,
      "unsigned" => $this->unsigned ?? new \stdClass,
    ];
  }

  public function getStateKey(): string
  {
    return $this->stateKey;
  }
}