From e32cc6fa6b861e43e8c063a66dd58506b781c6ca Mon Sep 17 00:00:00 2001 From: Athozus Date: Thu, 7 Dec 2023 22:01:05 +0100 Subject: [PATCH] Generate interleaved style when replying/forwarding a message (#120) --- ui/message.lua | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/ui/message.lua b/ui/message.lua index 888e680..237a87c 100644 --- a/ui/message.lua +++ b/ui/message.lua @@ -3,6 +3,16 @@ local S = minetest.get_translator("mail") local FORMNAME = "mail:message" +local function interleaveMsg(body) + local lines = (body or ""):split("\n", true) + local il_lines = {} + for _,l in ipairs(lines) do + il_lines[#il_lines+1] = "> " .. l + end + return table.concat(il_lines, "\n") +end + + function mail.show_message(name, id) local message = mail.get_message(name, id) if not message then @@ -65,8 +75,7 @@ function mail.reply(name, message) minetest.log("error", "[mail] current mail-context: " .. dump(mail.selected_idxs)) return end - local replyfooter = "Type your reply here.\n\n--Original message follows--\n" ..message.body - mail.show_compose(name, message.from, "Re: "..message.subject, replyfooter) + mail.show_compose(name, message.from, "Re: "..message.subject, interleaveMsg(message.body)) end function mail.replyall(name, message) @@ -77,8 +86,6 @@ function mail.replyall(name, message) return end - local replyfooter = "Type your reply here.\n\n--Original message follows--\n" ..message.body - -- new recipients are the sender plus the original recipients, minus ourselves local recipients = message.to or "" if message.from ~= nil then @@ -103,12 +110,11 @@ function mail.replyall(name, message) end cc = mail.concat_player_list(cc) - mail.show_compose(name, recipients, "Re: "..message.subject, replyfooter, cc) + mail.show_compose(name, recipients, "Re: "..message.subject, interleaveMsg(message.body), cc) end function mail.forward(name, message) - local fwfooter = "Type your message here.\n\n--Original message follows--\n" .. (message.body or "") - mail.show_compose(name, "", "Fw: " .. (message.subject or ""), fwfooter) + mail.show_compose(name, "", "Fw: " .. (message.subject or ""), interleaveMsg(message.body)) end minetest.register_on_player_receive_fields(function(player, formname, fields)