Debian Codegraph @

mtxclient/lib/structs/events/guest_access.cpp

raw symbols SCIP
1 #include <nlohmann/json.hpp>
2 #include <string>
3
4 #include "mtx/events/guest_access.hpp"
5
6 using json = nlohmann::json;
7
8 namespace mtx {
9 namespace events {
10 namespace state {
11
12 std::string
13 accessStateToString(AccessState state)
14 {
15 if (state == AccessState::CanJoin)
16 return "can_join";
17
18 return "forbidden";
19 }
20
21 AccessState
22 stringToAccessState(const std::string &state)
23 {
24 if (state == "can_join")
25 return AccessState::CanJoin;
26
27 return AccessState::Forbidden;
28 }
29
30 void
31 from_json(const json &obj, GuestAccess &guest_access)
32 {
33 guest_access.guest_access = stringToAccessState(obj.value("guest_access", ""));
34 }
35
36 void
37 to_json(json &obj, const GuestAccess &guest_access)
38 {
39 obj["guest_access"] = accessStateToString(guest_access.guest_access);
40 }
41
42 } // namespace state
43 } // namespace events
44 } // namespace mtx