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(key: "body").get<std::string>(); |
19 | content.msgtype = obj.at(key: "msgtype").get<std::string>(); |
20 | |
21 | if (obj.find(key: "url") != obj.end()) |
22 | content.url = obj.at(key: "url").get<std::string>(); |
23 | |
24 | if (obj.find(key: "info") != obj.end()) |
25 | content.info = obj.at(key: "info").get<common::VideoInfo>(); |
26 | |
27 | if (obj.find(key: "file") != obj.end()) |
28 | content.file = obj.at(key: "file").get<crypto::EncryptedFile>(); |
29 | |
30 | content.relations = common::parse_relations(obj); |
31 | } |
32 | |
33 | void |
34 | to_json(json &obj, const Video &content) |
35 | { |
36 | obj["msgtype"] = "m.video"; |
37 | obj["body"] = content.body; |
38 | obj["info"] = content.info; |
39 | |
40 | if (content.file) |
41 | obj["file"] = content.file.value(); |
42 | else |
43 | obj["url"] = content.url; |
44 | |
45 | common::apply_relations(obj, relations: content.relations); |
46 | } |
47 | |
48 | } // namespace msg |
49 | } // namespace events |
50 | } // namespace mtx |
51 |