#include #include #include "mtx/events/common.hpp" #include "mtx/events/messages/emote.hpp" using json = nlohmann::json; namespace mtx { namespace events { namespace msg { void from_json(const json &obj, Emote &content) { content.body = obj.at("body").get(); content.msgtype = obj.at("msgtype").get(); if (obj.count("format") != 0) content.format = obj.at("format").get(); if (obj.count("formatted_body") != 0) content.formatted_body = obj.at("formatted_body").get(); content.relations = common::parse_relations(obj); content.mentions = common::parse_mentions(obj); } void to_json(json &obj, const Emote &content) { obj["msgtype"] = "m.emote"; obj["body"] = content.body; if (!content.formatted_body.empty()) { obj["format"] = mtx::common::FORMAT_MSG_TYPE; obj["formatted_body"] = content.formatted_body; } common::add_mentions(obj, content.mentions); common::apply_relations(obj, content.relations); } } // namespace msg } // namespace events } // namespace mtx