Debian Codegraph @

mtxclient/lib/structs/responses/device.cpp

raw symbols SCIP
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("device_id").get<std::string>();
12
13 // This is needed because synapse sometimes sends null instead -_-
14 if (obj.contains("display_name") && obj["display_name"].is_string()) {
15 res.display_name = obj.value("display_name", std::string{});
16 }
17
18 // This is needed because synapse sometimes sends null instead -_-
19 if (obj.contains("last_seen_ip") && obj["last_seen_ip"].is_string()) {
20 res.last_seen_ip = obj.value("last_seen_ip", std::string{});
21 }
22
23 // This is needed because synapse sometimes sends null instead -_-
24 if (obj.contains("last_seen_ts") && obj["last_seen_ts"].is_number()) {
25 res.last_seen_ts = obj.value("last_seen_ts", size_t{});
26 }
27 }
28
29 void
30 from_json(const nlohmann::json &obj, QueryDevices &response)
31 {
32 response.devices = obj.at("devices").get<std::vector<Device>>();
33 }
34 }
35 }