Fix viewing polls with no expiry
https://cutie.city/@froggo@estrogen.network/109338577916060286
This commit is contained in:
parent
2dd59b1e71
commit
22dbe626b1
|
@ -80,7 +80,11 @@ 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()) {
|
||||
j.at("voters_count").get_to(poll.voters_count);
|
||||
|
|
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