| 1 | #include <nlohmann/json.hpp> |
| 2 | #include <unordered_map> |
| 3 | |
| 4 | #include "mtx/events/account_data/ignored_users.hpp" |
| 5 | |
| 6 | namespace mtx { |
| 7 | namespace events { |
| 8 | namespace account_data { |
| 9 | |
| 10 | void |
| 11 | from_json(const nlohmann::json &obj, IgnoredUsers &content) |
| 12 | { |
| 13 | if (!obj.contains("ignored_users")) |
| 14 | return; |
| 15 | |
| 16 | for (const auto &[key, value] : obj.at("ignored_users").items()) { |
| 17 | IgnoredUser user; |
| 18 | user.id = key; |
| 19 | content.users.push_back(user); |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | void |
| 24 | to_json(nlohmann::json &obj, const IgnoredUsers &content) |
| 25 | { |
| 26 | std::unordered_map<std::string, nlohmann::json> map; |
| 27 | for (const IgnoredUser &user : content.users) { |
| 28 | map[user.id] = nlohmann::json::object(); // {} = null |
| 29 | } |
| 30 | obj["ignored_users"] = map; |
| 31 | } |
| 32 | |
| 33 | } // namespace account_data |
| 34 | } // namespace events |
| 35 | } // namespace mtx |