From 22dbe626b1bdc85ac75799ff1ed01d894cc77150 Mon Sep 17 00:00:00 2001 From: blankie Date: Sat, 2 Dec 2023 10:53:46 +1100 Subject: [PATCH] Fix viewing polls with no expiry https://cutie.city/@froggo@estrogen.network/109338577916060286 --- models.cpp | 6 +++++- models.h | 2 +- servehelper.cpp | 7 +++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/models.cpp b/models.cpp index bb90951..a656a18 100644 --- a/models.cpp +++ b/models.cpp @@ -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()); + if (!j.at("expires_at").is_null()) { + poll.expires_at = parse_rfc3339(j["expires_at"].get_ref()); + } 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); diff --git a/models.h b/models.h index 8c8a4d0..dac0510 100644 --- a/models.h +++ b/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; diff --git a/servehelper.cpp b/servehelper.cpp index df7569a..caaf5b9 100644 --- a/servehelper.cpp +++ b/servehelper.cpp @@ -495,11 +495,10 @@ static inline Element serialize_poll(const httplib::Request& req, const Poll& po ? std::vector({std::to_string(voters_count), " ", pick_form(voters_count, "voter", "voters")}) : std::vector({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));