1#include <nlohmann/json.hpp>
2#include <string>
3
4#include "mtx/events/common.hpp"
5#include "mtx/events/messages/emote.hpp"
6
7using json = nlohmann::json;
8
9namespace mtx {
10namespace events {
11namespace msg {
12
13void
14from_json(const json &obj, Emote &content)
15{
16 content.body = obj.at(key: "body").get<std::string>();
17 content.msgtype = obj.at(key: "msgtype").get<std::string>();
18
19 if (obj.count(key: "format") != 0)
20 content.format = obj.at(key: "format").get<std::string>();
21
22 if (obj.count(key: "formatted_body") != 0)
23 content.formatted_body = obj.at(key: "formatted_body").get<std::string>();
24
25 content.relations = common::parse_relations(obj);
26}
27
28void
29to_json(json &obj, const Emote &content)
30{
31 obj["msgtype"] = "m.emote";
32 obj["body"] = content.body;
33
34 if (!content.formatted_body.empty()) {
35 obj["format"] = mtx::common::FORMAT_MSG_TYPE;
36 obj["formatted_body"] = content.formatted_body;
37 }
38
39 common::apply_relations(obj, relations: content.relations);
40}
41
42} // namespace msg
43} // namespace events
44} // namespace mtx
45