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