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

namespace Matrix\Events;

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

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

  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,
      "type" => $this->type,
      "unsigned" => $this->unsigned ?? new \stdClass,
    ];
  }

  public function getId(): string
  {
    return $this->eventId;
  }

  public function getOriginServerTimestamp(): int
  {
    return $this->originServerTimestamp;
  }

  public function getRoomId(): string
  {
    return $this->roomId;
  }

  public function getUnsigned(): ?UnsignedData
  {
    return $this->unsigned;
  }
}