-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcompact_notice.cpp
More file actions
40 lines (33 loc) · 1.2 KB
/
Copy pathcompact_notice.cpp
File metadata and controls
40 lines (33 loc) · 1.2 KB
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
#include "compact_notice.hpp"
namespace acecode {
nlohmann::json make_compact_notice_metadata(const std::string& id,
const std::string& stage,
bool complete) {
return nlohmann::json{
{kCompactNoticeFlagKey, true},
{kCompactNoticeIdKey, id},
{kCompactNoticeStageKey, stage},
{kCompactNoticeCompleteKey, complete},
};
}
std::optional<CompactNotice> decode_compact_notice(
const nlohmann::json& metadata) {
if (!metadata.is_object() ||
!metadata.value(kCompactNoticeFlagKey, false)) {
return std::nullopt;
}
const std::string id = metadata.value(kCompactNoticeIdKey, std::string{});
const std::string stage = metadata.value(
kCompactNoticeStageKey, std::string{});
if (id.empty() || stage.empty()) return std::nullopt;
CompactNotice notice;
notice.id = id;
notice.stage = stage;
notice.complete = metadata.value(kCompactNoticeCompleteKey, false);
return notice;
}
std::optional<CompactNotice> decode_compact_notice(
const ChatMessage& message) {
return decode_compact_notice(message.metadata);
}
} // namespace acecode