| 1 | #include <nlohmann/json.hpp> |
|---|---|
| 2 | #include <string> |
| 3 | |
| 4 | #include "mtx/events/common.hpp" |
| 5 | #include "mtx/events/messages/emote.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, Emote &content) |
| 15 | { |
| 16 | content.body = obj.at(key: "body").get<std::string>(); |
| 17 | content.msgtype = obj.at(key: "msgtype").get<std::string>(); |
| 18 | |
| 19 | if (obj.count(key: "format") != 0) |
| 20 | content.format = obj.at(key: "format").get<std::string>(); |
| 21 | |
| 22 | if (obj.count(key: "formatted_body") != 0) |
| 23 | content.formatted_body = obj.at(key: "formatted_body").get<std::string>(); |
| 24 | |
| 25 | content.relations = common::parse_relations(obj); |
| 26 | } |
| 27 | |
| 28 | void |
| 29 | to_json(json &obj, const Emote &content) |
| 30 | { |
| 31 | obj["msgtype"] = "m.emote"; |
| 32 | obj["body"] = content.body; |
| 33 | |
| 34 | if (!content.formatted_body.empty()) { |
| 35 | obj["format"] = mtx::common::FORMAT_MSG_TYPE; |
| 36 | obj["formatted_body"] = content.formatted_body; |
| 37 | } |
| 38 | |
| 39 | common::apply_relations(obj, relations: content.relations); |
| 40 | } |
| 41 | |
| 42 | } // namespace msg |
| 43 | } // namespace events |
| 44 | } // namespace mtx |
| 45 |