Debian Codegraph @

mtxclient/lib/structs/events/nheko_extensions/hidden_events.cpp

raw symbols SCIP
1 #include "mtx/events/nheko_extensions/hidden_events.hpp"
2
3 #include <nlohmann/json.hpp>
4
5 #include <mtx/log.hpp>
6
7 namespace mtx {
8 namespace events {
9 namespace account_data {
10 namespace nheko_extensions {
11
12 void
13 from_json(const nlohmann::json &obj, HiddenEvents &content)
14 {
15 if (obj.contains("hidden_event_types")) {
16 content.hidden_event_types = std::vector<EventType>{};
17 for (const auto &typeStr : obj.at("hidden_event_types")) {
18 auto type_ = typeStr.get<std::string>();
19 if (type_ == "") {
20 content.hidden_event_types->push_back(mtx::events::EventType::Unsupported);
21 } else {
22 try {
23 auto type = getEventType(type_);
24 content.hidden_event_types->push_back(type);
25 } catch (...) {
26 utils::log::log()->warn("Ignoring unknown event type to ignore: {}", type_);
27 }
28 }
29 }
30 }
31 }
32
33 void
34 to_json(nlohmann::json &obj, const HiddenEvents &content)
35 {
36 if (content.hidden_event_types) {
37 for (auto type : content.hidden_event_types.value()) {
38 obj["hidden_event_types"].push_back(to_string(type));
39 }
40 }
41 }
42 }
43 } // namespace account_data
44 } // namespace events
45 } // namespace mtx