mirror of
https://notabug.org/scuti/pleroma-comments
synced 2025-01-03 16:41:45 +05:30
display polls
This commit is contained in:
parent
7cddab04b7
commit
940f549821
@ -130,6 +130,34 @@ function write_comments(pleroma_posts, instance, show_avatars)
|
||||
return table.concat(media_list, "\n")
|
||||
end
|
||||
|
||||
function get_poll(poll)
|
||||
if type(poll) ~= "table" then
|
||||
return ""
|
||||
end
|
||||
local bar_chart = {"<div class=\"chart\">"}
|
||||
local bar_template = "<div class=\"bar\" style=\"width: $pct$%;\">$label$</div>"
|
||||
local total_votes = math.floor(poll["votes_count"])
|
||||
for _, v in pairs(poll["options"]) do
|
||||
local width = math.floor(
|
||||
0.5 + (v["votes_count"]/total_votes) * 100)
|
||||
vars = {
|
||||
label = width .. "% " .. v["title"],
|
||||
pct = width
|
||||
}
|
||||
local bar = bar_template:gsub("%$(%w+)%$", vars)
|
||||
print(bar)
|
||||
table.insert(bar_chart, bar)
|
||||
end
|
||||
table.insert(bar_chart, "</div>")
|
||||
local summary = "<p>$x$ people have cast $y$ votes</p>"
|
||||
local foo = summary:gsub(
|
||||
"%$(%w+)%$",
|
||||
{x=math.floor(poll["voters_count"]), y=total_votes}
|
||||
)
|
||||
table.insert(bar_chart, foo)
|
||||
return table.concat(bar_chart,"\n")
|
||||
end
|
||||
|
||||
if #pleroma_posts == 0 then
|
||||
return ""
|
||||
end
|
||||
@ -157,9 +185,7 @@ function write_comments(pleroma_posts, instance, show_avatars)
|
||||
table.insert(
|
||||
attrs, get_media(post["media_attachments"])
|
||||
)
|
||||
if type(post["poll"]) == "table" then
|
||||
table.insert(attrs, "<p>(poll attached)</p>")
|
||||
end
|
||||
table.insert(attrs, get_poll(post["poll"]))
|
||||
|
||||
local interpolated = template:gsub("%$(%w+)%$", {
|
||||
i= #replies - i + 1,
|
||||
|
Loading…
Reference in New Issue
Block a user