Compare commits
2 Commits
2dd59b1e71
...
d146ec3498
Author | SHA1 | Date |
---|---|---|
blankie | d146ec3498 | |
blankie | 22dbe626b1 |
|
@ -80,9 +80,13 @@ void from_json(const json& j, PollOption& option) {
|
|||
}
|
||||
|
||||
void from_json(const json& j, Poll& poll) {
|
||||
poll.expires_at = parse_rfc3339(j.at("expires_at").get_ref<const std::string&>());
|
||||
if (!j.at("expires_at").is_null()) {
|
||||
poll.expires_at = parse_rfc3339(j["expires_at"].get_ref<const std::string&>());
|
||||
} else {
|
||||
poll.expires_at = -1;
|
||||
}
|
||||
j.at("expired").get_to(poll.expired);
|
||||
if (!j.at("voters_count").is_null()) {
|
||||
if (j.contains("voters_count") && !j["voters_count"].is_null()) {
|
||||
j.at("voters_count").get_to(poll.voters_count);
|
||||
} else {
|
||||
poll.voters_count = -1;
|
||||
|
|
2
models.h
2
models.h
|
@ -64,7 +64,7 @@ struct PollOption {
|
|||
uint64_t votes_count;
|
||||
};
|
||||
struct Poll {
|
||||
time_t expires_at;
|
||||
time_t expires_at; // negative if none
|
||||
bool expired;
|
||||
int64_t voters_count; // negative if unknown
|
||||
uint64_t votes_count;
|
||||
|
|
|
@ -495,11 +495,10 @@ static inline Element serialize_poll(const httplib::Request& req, const Poll& po
|
|||
? std::vector<Node>({std::to_string(voters_count), " ", pick_form(voters_count, "voter", "voters")})
|
||||
: std::vector<Node>({std::to_string(poll.votes_count), " ", pick_form(poll.votes_count, "vote", "votes")})
|
||||
);
|
||||
p.nodes.push_back(" / ");
|
||||
if (poll.expired) {
|
||||
p.nodes.push_back("Expired");
|
||||
} else {
|
||||
p.nodes.push_back("Expires in ");
|
||||
p.nodes.push_back(" / Expired");
|
||||
} else if (poll.expires_at >= 0) {
|
||||
p.nodes.push_back(" / Expires in ");
|
||||
p.nodes.push_back(relative_time(current_time(), poll.expires_at));
|
||||
}
|
||||
div.nodes.push_back(std::move(p));
|
||||
|
|
Loading…
Reference in New Issue