From 38d67e0601ca2310429ea7175bf9ce156fc8680f Mon Sep 17 00:00:00 2001 From: scuti Date: Wed, 27 Nov 2024 21:56:32 -0800 Subject: [PATCH] display extra attributes e.g images attached --- pleroma-comments.lua | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/pleroma-comments.lua b/pleroma-comments.lua index c7fa0ff..ce1fbeb 100644 --- a/pleroma-comments.lua +++ b/pleroma-comments.lua @@ -108,6 +108,29 @@ function write_comments(pleroma_posts, instance, show_avatars) return card_template:gsub("%$(%w+)%$", vars) end + function get_media(attachments) + if type(attachments) ~= "table" then + return "" + end + if #attachments < 1 then + return "" + end + local media_list = {"

images attached:

    "} + local item = "
  1. $mime$
  2. " + for _, v in pairs(attachments) do + local vars = { + link = v["preview_url"], + mime = v["pleroma"]["mime_type"] + } + local foo = item:gsub("%$(%w+)%$", vars) + print(foo) + table.insert(media_list, foo) + end + table.insert(media_list, "
") + printTable(media_list) + return table.concat(media_list, "\n") + end + if #pleroma_posts == 0 then return "" end @@ -121,6 +144,7 @@ function write_comments(pleroma_posts, instance, show_avatars) $text$ $card$ + $attributes$ ]] local comments = {} @@ -128,8 +152,16 @@ function write_comments(pleroma_posts, instance, show_avatars) for i, post in ipairs(replies) do local pid = post["id"] local datetime = get_short_date(post["created_at"]) - local text = post["content"] + + local attrs = {} + table.insert( + attrs, get_media(post["media_attachments"]) + ) + if type(post["poll"]) == "table" then + table.insert(attrs, "

(poll attached)

") + end + local interpolated = template:gsub("%$(%w+)%$", { i= #replies - i + 1, host=instance, @@ -137,7 +169,8 @@ function write_comments(pleroma_posts, instance, show_avatars) datetime=datetime, user=get_user(post["account"], instance, true), text = text, - card = get_card(post["card"], instance) + card = get_card(post["card"], instance), + attributes = table.concat(attrs) }) -- print(interpolated) table.insert(