| 1 | #include <nlohmann/json.hpp> |
| 2 | #include <string> |
| 3 | |
| 4 | #include "mtx/events/common.hpp" |
| 5 | #include "mtx/events/messages/video.hpp" |
| 6 | |
| 7 | using json = nlohmann::json; |
| 8 | |
| 9 | namespace common = mtx::common; |
| 10 | |
| 11 | namespace mtx { |
| 12 | namespace events { |
| 13 | namespace msg { |
| 14 | |
| 15 | void |
| 16 | from_json(const json &obj, Video &content) |
| 17 | { |
| 18 | content.body = obj.at("body").get<std::string>(); |
| 19 | content.msgtype = obj.at("msgtype").get<std::string>(); |
| 20 | |
| 21 | if (obj.find("url") != obj.end()) |
| 22 | content.url = obj.at("url").get<std::string>(); |
| 23 | |
| 24 | if (obj.find("info") != obj.end()) |
| 25 | content.info = obj.at("info").get<common::VideoInfo>(); |
| 26 | |
| 27 | if (obj.find("file") != obj.end()) |
| 28 | content.file = obj.at("file").get<crypto::EncryptedFile>(); |
| 29 | |
| 30 | content.relations = common::parse_relations(obj); |
| 31 | content.mentions = common::parse_mentions(obj); |
| 32 | } |
| 33 | |
| 34 | void |
| 35 | to_json(json &obj, const Video &content) |
| 36 | { |
| 37 | obj["msgtype"] = "m.video"; |
| 38 | obj["body"] = content.body; |
| 39 | obj["info"] = content.info; |
| 40 | |
| 41 | if (content.file) |
| 42 | obj["file"] = content.file.value(); |
| 43 | else |
| 44 | obj["url"] = content.url; |
| 45 | |
| 46 | common::add_mentions(obj, content.mentions); |
| 47 | common::apply_relations(obj, content.relations); |
| 48 | } |
| 49 | |
| 50 | } // namespace msg |
| 51 | } // namespace events |
| 52 | } // namespace mtx |