| 1 | #include <nlohmann/json.hpp> |
| 2 | #include <string> |
| 3 | |
| 4 | #include "mtx/events/common.hpp" |
| 5 | #include "mtx/events/messages/location.hpp" |
| 6 | |
| 7 | using json = nlohmann::json; |
| 8 | |
| 9 | namespace mtx { |
| 10 | namespace events { |
| 11 | namespace msg { |
| 12 | |
| 13 | void |
| 14 | from_json(const json &obj, Location &content) |
| 15 | { |
| 16 | content.body = obj.at("body").get<std::string>(); |
| 17 | content.msgtype = obj.at("msgtype").get<std::string>(); |
| 18 | if (obj.find("geo_uri") != obj.end()) |
| 19 | content.geo_uri = obj.at("geo_uri").get<std::string>(); |
| 20 | |
| 21 | if (obj.find("info") != obj.end()) |
| 22 | content.info = obj.at("info").get<common::LocationInfo>(); |
| 23 | |
| 24 | content.relations = common::parse_relations(obj); |
| 25 | } |
| 26 | |
| 27 | void |
| 28 | to_json(json &obj, const Location &content) |
| 29 | { |
| 30 | obj["msgtype"] = "m.location"; |
| 31 | obj["body"] = content.body; |
| 32 | |
| 33 | obj["geo_uri"] = content.geo_uri; |
| 34 | obj["info"] = content.info; |
| 35 | common::apply_relations(obj, content.relations); |
| 36 | } |
| 37 | |
| 38 | } // namespace msg |
| 39 | } // namespace events |
| 40 | } // namespace mtx |