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