| 1 | #include "mtx/events/nheko_extensions/event_expiry.hpp" |
| 2 | |
| 3 | #include <nlohmann/json.hpp> |
| 4 | |
| 5 | namespace mtx { |
| 6 | namespace events { |
| 7 | namespace account_data { |
| 8 | namespace nheko_extensions { |
| 9 | |
| 10 | void |
| 11 | from_json(const nlohmann::json &obj, EventExpiry &content) |
| 12 | { |
| 13 | content.exclude_state_events = obj.value("exclude_state_events", false); |
| 14 | content.expire_after_ms = obj.value("expire_after_ms", std::uint64_t{0}); |
| 15 | content.protect_latest = obj.value("protect_latest", std::uint64_t{0}); |
| 16 | content.keep_only_latest = obj.value("keep_only_latest", std::uint64_t{0}); |
| 17 | } |
| 18 | |
| 19 | void |
| 20 | to_json(nlohmann::json &obj, const EventExpiry &content) |
| 21 | { |
| 22 | if (content.exclude_state_events) |
| 23 | obj["exclude_state_events"] = true; |
| 24 | if (content.expire_after_ms) |
| 25 | obj["expire_after_ms"] = content.expire_after_ms; |
| 26 | if (content.protect_latest) |
| 27 | obj["protect_latest"] = content.protect_latest; |
| 28 | if (content.keep_only_latest) |
| 29 | obj["keep_only_latest"] = content.keep_only_latest; |
| 30 | } |
| 31 | } |
| 32 | } // namespace account_data |
| 33 | } // namespace events |
| 34 | } // namespace mtx |