| 1 | #include "mtx/events/tag.hpp" |
| 2 | |
| 3 | #include <nlohmann/json.hpp> |
| 4 | |
| 5 | using json = nlohmann::json; |
| 6 | |
| 7 | namespace mtx { |
| 8 | namespace events { |
| 9 | namespace account_data { |
| 10 | |
| 11 | void |
| 12 | from_json(const json &obj, Tag &content) |
| 13 | { |
| 14 | // Workaround some Element clients sending order as strings... |
| 15 | if (auto o = obj.find("order"); o != obj.end() && o->is_number()) |
| 16 | content.order = o->get<double>(); |
| 17 | } |
| 18 | |
| 19 | void |
| 20 | to_json(json &obj, const Tag &content) |
| 21 | { |
| 22 | obj = nlohmann::json::object(); |
| 23 | if (content.order) |
| 24 | obj["order"] = content.order.value(); |
| 25 | } |
| 26 | |
| 27 | void |
| 28 | from_json(const json &obj, Tags &content) |
| 29 | { |
| 30 | content.tags = obj.at("tags").get<std::map<std::string, Tag>>(); |
| 31 | } |
| 32 | |
| 33 | void |
| 34 | to_json(json &obj, const Tags &content) |
| 35 | { |
| 36 | obj["tags"] = content.tags; |
| 37 | } |
| 38 | |
| 39 | } // namespace state |
| 40 | } // namespace events |
| 41 | } // namespace mtx |