| 1 | #include "mtx/responses/device.hpp" |
|---|---|
| 2 | |
| 3 | #include <nlohmann/json.hpp> |
| 4 | |
| 5 | namespace mtx { |
| 6 | namespace responses { |
| 7 | |
| 8 | void |
| 9 | from_json(const nlohmann::json &obj, Device &res) |
| 10 | { |
| 11 | res.device_id = obj.at(key: "device_id").get<std::string>(); |
| 12 | |
| 13 | // This is needed because synapse sometimes sends null instead -_- |
| 14 | if (obj.contains(key: "display_name") && obj[ "display_name"].is_string()) { |
| 15 | res.display_name = obj.value(key: "display_name", default_value: std::string{}); |
| 16 | } |
| 17 | |
| 18 | // This is needed because synapse sometimes sends null instead -_- |
| 19 | if (obj.contains(key: "last_seen_ip") && obj[ "last_seen_ip"].is_string()) { |
| 20 | res.last_seen_ip = obj.value(key: "last_seen_ip", default_value: std::string{}); |
| 21 | } |
| 22 | |
| 23 | // This is needed because synapse sometimes sends null instead -_- |
| 24 | if (obj.contains(key: "last_seen_ts") && obj[ "last_seen_ts"].is_number()) { |
| 25 | res.last_seen_ts = obj.value(key: "last_seen_ts", default_value: size_t{}); |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | void |
| 30 | from_json(const nlohmann::json &obj, QueryDevices &response) |
| 31 | { |
| 32 | response.devices = obj.at(key: "devices").get<std::vector<Device>>(); |
| 33 | } |
| 34 | } |
| 35 | } |
| 36 |