libkazv
power-levels-desc.hpp
Go to the documentation of this file.
1 /*
2  * This file is part of libkazv.
3  * SPDX-FileCopyrightText: 2020-2023 tusooa <tusooa@kazv.moe>
4  * SPDX-License-Identifier: AGPL-3.0-or-later
5  */
6 
7 #pragma once
8 #include <libkazv-config.hpp>
9 
10 #include <memory>
11 #include <cstdint>
12 #include <optional>
13 
14 #include <copy-helper.hpp>
15 
16 namespace Kazv
17 {
18  class Event;
19 
20  using PowerLevel = std::int_fast64_t;
21 
26  {
27  public:
31  PowerLevelsDesc(const Event &e);
33 
35 
42  PowerLevel powerLevelOfUser(std::string userId) const;
43 
51  bool canSendMessage(std::string userId, std::string eventType) const;
52 
60  bool canSendState(std::string userId, std::string eventType) const;
61 
68  bool canInvite(std::string userId) const;
69 
76  bool canKick(std::string userId) const;
77 
84  bool canBan(std::string userId) const;
85 
92  bool canRedact(std::string userId) const;
93 
99  Event normalizedEvent() const;
100 
106  Event originalEvent() const;
107 
115  PowerLevelsDesc setBan(std::optional<PowerLevel> powerLevel) const;
116 
124  PowerLevelsDesc setInvite(std::optional<PowerLevel> powerLevel) const;
125 
133  PowerLevelsDesc setKick(std::optional<PowerLevel> powerLevel) const;
134 
143  PowerLevelsDesc setRedact(std::optional<PowerLevel> powerLevel) const;
144 
153  PowerLevelsDesc setEvent(std::string eventType, std::optional<PowerLevel> powerLevel) const;
154 
162  PowerLevelsDesc setEventsDefault(std::optional<PowerLevel> powerLevel) const;
163 
171  PowerLevelsDesc setStateDefault(std::optional<PowerLevel> powerLevel) const;
172 
180  PowerLevelsDesc setUser(std::string userId, std::optional<PowerLevel> powerLevel) const;
181 
188  PowerLevelsDesc setUsersDefault(std::optional<PowerLevel> powerLevel) const;
189 
190  private:
191  struct Private;
192  std::unique_ptr<Private> m_d;
193  };
194 }
Definition: event.hpp:21
Represent a m.power_levels event.
Definition: power-levels-desc.hpp:26
bool canInvite(std::string userId) const
Determine whether a user can invite someone else.
Definition: power-levels-desc.cpp:156
PowerLevelsDesc setInvite(std::optional< PowerLevel > powerLevel) const
Amend the power levels event to set the power level needed to invite someone.
Definition: power-levels-desc.cpp:212
PowerLevelsDesc setRedact(std::optional< PowerLevel > powerLevel) const
Amend the power levels event to set the power level needed to redact someone else's messages.
Definition: power-levels-desc.cpp:219
PowerLevelsDesc setBan(std::optional< PowerLevel > powerLevel) const
Amend the power levels event to set the power level needed to ban someone.
Definition: power-levels-desc.cpp:198
Event originalEvent() const
Get the original event provided when constructing this.
Definition: power-levels-desc.cpp:193
PowerLevelsDesc setUsersDefault(std::optional< PowerLevel > powerLevel) const
Amend the power levels event to set the default power level for users.
Definition: power-levels-desc.cpp:240
bool canSendMessage(std::string userId, std::string eventType) const
Determine whether a user can send a non-state event.
Definition: power-levels-desc.cpp:136
bool canRedact(std::string userId) const
Determine whether a user can redact someone else's events.
Definition: power-levels-desc.cpp:180
PowerLevelsDesc(const Event &e)
Construct a PowerLevelsDesc from an event.
Definition: power-levels-desc.cpp:118
PowerLevelsDesc setEvent(std::string eventType, std::optional< PowerLevel > powerLevel) const
Amend the power levels event to set the power level needed to send an event of a particular type.
Definition: power-levels-desc.cpp:257
PowerLevel powerLevelOfUser(std::string userId) const
Get the power level of a user in the room.
Definition: power-levels-desc.cpp:126
Event normalizedEvent() const
Get the normalized event of this.
Definition: power-levels-desc.cpp:188
bool canBan(std::string userId) const
Determine whether a user can ban someone else.
Definition: power-levels-desc.cpp:172
PowerLevelsDesc setUser(std::string userId, std::optional< PowerLevel > powerLevel) const
Amend the power levels event to set the power level of some user.
Definition: power-levels-desc.cpp:247
PowerLevelsDesc setStateDefault(std::optional< PowerLevel > powerLevel) const
Amend the power levels event to set the power level needed to send a state event whose type is not in...
Definition: power-levels-desc.cpp:233
bool canKick(std::string userId) const
Determine whether a user can kick someone else.
Definition: power-levels-desc.cpp:164
KAZV_DECLARE_COPYABLE(PowerLevelsDesc)
PowerLevelsDesc setKick(std::optional< PowerLevel > powerLevel) const
Amend the power levels event to set the power level needed to kick someone.
Definition: power-levels-desc.cpp:205
bool canSendState(std::string userId, std::string eventType) const
Determine whether a user can send a state event.
Definition: power-levels-desc.cpp:146
PowerLevelsDesc setEventsDefault(std::optional< PowerLevel > powerLevel) const
Amend the power levels event to set the power level needed to send a non-state event whose type is no...
Definition: power-levels-desc.cpp:226
Definition: location.hpp:10
std::int_fast64_t PowerLevel
Definition: power-levels-desc.hpp:20
Definition: power-levels-desc.cpp:68