summaryrefslogtreecommitdiff
path: root/matrix-specification/Events/Room/PowerLevelsEvent.php
blob: 8b609f3dcbf4de189ee4fc67ea294a6bdf9b1eb1 (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
56
57
<?php

namespace Matrix\Events\Room;

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

class PowerLevelsEvent extends StateEvent
{
  /**
   * @param ?array<string, int> $events This is a mapping from event type to power level required.
   * @param ?array<string, int> $notifications This is a mapping from key to power level for that notifications key.
   * @param ?array<string, int> $events This is a mapping from user_id to power level for that user.
   */
  public function __construct(
    string $eventId,
    int $originServerTimestamp,
    string $roomId,
    string $sender,
    ?int $ban = 50,
    ?array $events = null,
    ?int $eventsDefault = 0,
    ?int $invite = 0,
    ?int $kick = 50,
    ?array $notifications = null, # TODO: https://spec.matrix.org/v1.17/client-server-api/#mroompower_levels_notifications
    ?int $redact = 50,
    ?int $stateDefault = 50,
    ?array $users = null,
    ?int $usersDefault = 0,
    string $stateKey = "",
    ?UnsignedData $unsigned = null,
  )
  {
    parent::__construct(
      array_filter([
        "ban" => $ban,
        "events" => $events,
        "events_default" => $eventsDefault,
        "invite" => $invite,
        "kick" => $kick,
        "notifications" => $notifications,
        "redact" => $redact,
        "state_default" => $stateDefault,
        "users" => $users,
        "users_default" => $usersDefault,
      ], fn ($value) => ! is_null($value)),
      $eventId,
      $originServerTimestamp,
      $roomId,
      $sender,
      $stateKey,
      EventType::ROOM_POWER_LEVELS,
      $unsigned,
    );
  }
}