mirror of
https://notabug.org/scuti/pleroma-comments
synced 2025-01-05 17:43:48 +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")
|
return table.concat(media_list, "\n")
|
||||||
end
|
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
|
if #pleroma_posts == 0 then
|
||||||
return ""
|
return ""
|
||||||
end
|
end
|
||||||
@ -157,9 +185,7 @@ function write_comments(pleroma_posts, instance, show_avatars)
|
|||||||
table.insert(
|
table.insert(
|
||||||
attrs, get_media(post["media_attachments"])
|
attrs, get_media(post["media_attachments"])
|
||||||
)
|
)
|
||||||
if type(post["poll"]) == "table" then
|
table.insert(attrs, get_poll(post["poll"]))
|
||||||
table.insert(attrs, "<p>(poll attached)</p>")
|
|
||||||
end
|
|
||||||
|
|
||||||
local interpolated = template:gsub("%$(%w+)%$", {
|
local interpolated = template:gsub("%$(%w+)%$", {
|
||||||
i= #replies - i + 1,
|
i= #replies - i + 1,
|
||||||
|
Loading…
Reference in New Issue
Block a user