mirror of
https://notabug.org/scuti/pleroma-comments
synced 2025-05-31 11:21:40 +05:30
clean up main function
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
-- local https = "wget"
|
-- local https = "wget"
|
||||||
local json = require("cjson")
|
local json = require("cjson")
|
||||||
|
|
||||||
|
-- for testing
|
||||||
function printTable(t)
|
function printTable(t)
|
||||||
for key, value in pairs(t) do
|
for key, value in pairs(t) do
|
||||||
print(key, value)
|
print(key, value)
|
||||||
@@ -71,7 +72,7 @@ function write_comments(pleroma_posts, instance)
|
|||||||
local uid = post["account"]["id"]
|
local uid = post["account"]["id"]
|
||||||
local alias = post["account"]["display_name"]
|
local alias = post["account"]["display_name"]
|
||||||
local handle = post["account"]["acct"]
|
local handle = post["account"]["acct"]
|
||||||
local text = post["pleroma"]["content"]["text/plain"]
|
local text = post["content"]
|
||||||
local interpolated = template:gsub("%$(%w+)%$", {
|
local interpolated = template:gsub("%$(%w+)%$", {
|
||||||
i= #replies - i + 1,
|
i= #replies - i + 1,
|
||||||
host=instance,
|
host=instance,
|
||||||
@@ -99,32 +100,53 @@ function combine_tables(a,b)
|
|||||||
return a
|
return a
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function get_opening_post(host, post_id)
|
||||||
|
local url = "https://" .. host .. "/api/v1/statuses" .. post_id
|
||||||
|
print(url)
|
||||||
|
local received = get(url)
|
||||||
|
end
|
||||||
|
|
||||||
|
function get_url_from_pandoc_str(pandoc_str)
|
||||||
|
local str = pandoc.utils.stringify(pandoc_str)
|
||||||
|
-- 1 = protocol, 2 = host ...
|
||||||
|
-- https://host.tld/notice/12345
|
||||||
|
local tokens = tokenizeString(str, '/')
|
||||||
|
local id = tokens[#tokens]
|
||||||
|
|
||||||
|
local host = tokens[2]
|
||||||
|
local id = tokens[#tokens]
|
||||||
|
local link = str
|
||||||
|
|
||||||
|
return link, host, id
|
||||||
|
end
|
||||||
|
|
||||||
|
function get_replies(host, id)
|
||||||
|
local url = "https://" .. host .. "/api/v1/statuses/" .. id .. "/context"
|
||||||
|
print(url)
|
||||||
|
local got = get(url)
|
||||||
|
return got["descendants"]
|
||||||
|
end
|
||||||
|
|
||||||
function Meta(meta)
|
function Meta(meta)
|
||||||
local elem = meta["pleroma-urls"]
|
local pleroma_urls = meta["pleroma-urls"]
|
||||||
-- print(elem)
|
-- print(elem)
|
||||||
if elem == nil then
|
if pleroma_urls == nil then
|
||||||
return -- abort
|
return -- abort
|
||||||
end
|
end
|
||||||
local all_replies = {}
|
local all_replies = {}
|
||||||
local newelem = {}
|
local hrefs = {}
|
||||||
local host = ""
|
local host = ""
|
||||||
for _, v in pairs(elem) do
|
-- for each listed url in "pleroma-urls"
|
||||||
local str = pandoc.utils.stringify(v)
|
for _, v in pairs(pleroma_urls) do
|
||||||
print(str)
|
local link, host, id = get_url_from_pandoc_str(v)
|
||||||
-- 1 = protocol, 2 = host ...
|
table.insert(hrefs,
|
||||||
-- https://host.tld/notice/12345
|
{link = link, id = id}
|
||||||
local tokens = tokenizeString(str, '/')
|
|
||||||
local id = tokens[#tokens]
|
|
||||||
table.insert(newelem,
|
|
||||||
{link = str, id = id}
|
|
||||||
)
|
)
|
||||||
host = tokens[2]
|
local replies = get_replies(host, id)
|
||||||
local url = "https://" .. host .. "/api/v1/statuses/" .. id .. "/context"
|
|
||||||
local got = get(url)
|
|
||||||
if #all_replies == 0 then
|
if #all_replies == 0 then
|
||||||
all_replies = got["descendants"]
|
all_replies = replies
|
||||||
else
|
else
|
||||||
combine_tables(all_replies, got["descendants"])
|
combine_tables(all_replies, replies)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
table.sort(all_replies,
|
table.sort(all_replies,
|
||||||
@@ -138,7 +160,7 @@ function Meta(meta)
|
|||||||
meta["pleroma-comments"] = c
|
meta["pleroma-comments"] = c
|
||||||
meta["pleroma-comments-count"] = #c
|
meta["pleroma-comments-count"] = #c
|
||||||
meta["pleroma-has-comments"] = (#c > 0)
|
meta["pleroma-has-comments"] = (#c > 0)
|
||||||
meta["pleroma"] = newelem
|
meta["pleroma"] = hrefs
|
||||||
return meta
|
return meta
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user