diff --git a/gui.lua b/gui.lua index 1666ad900f9bdf6f04cec236d7fa6f2a2d26d062..676e75efa185102c8f3ccb294068257775d7b979 100644 --- a/gui.lua +++ b/gui.lua @@ -28,8 +28,8 @@ mail.inbox_formspec = "size[8,9;]" .. theme .. [[ button[6,7.40;2,0.5;about;About] button_exit[6,8.45;2,0.5;quit;Close] - tablecolumns[color;text;text] - table[0,0;5.75,9;messages;#999,From,Subject]] + tablecolumns[color;text;text;text] + table[0,0;5.75,9;messages;#999,,From,Subject]] mail.contacts_formspec = "size[8,9;]" .. theme .. [[ button[6,0.10;2,0.5;new;New] @@ -75,6 +75,7 @@ end function mail.show_inbox(name) local formspec = { mail.inbox_formspec } local messages = mail.getMessages(name) + local now = os.time() message_drafts[name] = nil @@ -95,6 +96,8 @@ function mail.show_inbox(name) end end formspec[#formspec + 1] = "," + formspec[#formspec + 1] = minetest.formspec_escape(mail.pretty_duration(now - message.time)) + formspec[#formspec + 1] = "," formspec[#formspec + 1] = minetest.formspec_escape(message.sender) formspec[#formspec + 1] = "," if message.subject ~= "" then @@ -288,10 +291,11 @@ function mail.show_message(name, msgnumber) local formspec = [[ size[8,9] button[7.25,0;0.75,0.5;back;X] - label[0,0;From: %s] - label[0,0.4;To: %s] - label[0,0.8;CC: %s] - label[0,1.3;Subject: %s] + label[0,0;From: %s] + label[0,0.4;To: %s] + label[0,0.8;CC: %s] + label[3,0;Date: %s] + label[0,1.3;Subject: %s] textarea[0.25,1.8;8,7.8;body;;%s] button[0,8.5;2,1;reply;Reply] button[2,8.5;2,1;replyall;Reply All] @@ -302,9 +306,10 @@ function mail.show_message(name, msgnumber) local from = minetest.formspec_escape(message.sender) local to = minetest.formspec_escape(message.to) local cc = minetest.formspec_escape(message.cc) + local date = minetest.formspec_escape(mail.pretty_date(message.time, true)) local subject = minetest.formspec_escape(message.subject) local body = minetest.formspec_escape(message.body) - formspec = string.format(formspec, from, to, cc, subject, body) + formspec = string.format(formspec, from, to, cc, date, subject, body) if message.unread then message.unread = false diff --git a/util/misc.lua b/util/misc.lua index 8ad3428373839d50ffe4d6ba8dffb368a28d3202..6f70aca6ce0005051497864bd5880652705c4bde 100644 --- a/util/misc.lua +++ b/util/misc.lua @@ -60,6 +60,62 @@ function mail.calculate_frequent_contacts(name, only_show_contacts) return out end +function mail.pretty_date(timestamp, trim_if_recent) + -- convert timestamp to table in local time + local ts_tab = os.date("*t", timestamp) + + if trim_if_recent then + local ago = os.time() - timestamp + timestamp = os.time(ts_tab) -- make display local time for os.date() + + if ago >= 0 then + local now_tab = os.date("*t") + now_tab.sec = 0 + now_tab.min = 0 + now_tab.hour = 0 + if timestamp >= os.time(now_tab) then + return os.date("%H:%M", timestamp) + else + now_tab.day = 1 + now_tab.month = 1 + if timestamp >= os.time(now_tab) then + return os.date("%d.%m. %H:%M", timestamp) + end + end + end + end + + return os.date("%d.%m.%Y %H:%M:%S", timestamp) +end + +function mail.pretty_duration(seconds) + if seconds < 60 then + return seconds .. " sec" + elseif seconds < 60*60 then + return math.floor(0.5 + seconds/60) .. " min" + + elseif seconds < 60*60*2 then + return math.floor(0.5 + seconds/60/60) .. " hour" + elseif seconds < 60*60*24 then + return math.floor(0.5 + seconds/60/60) .. " hrs" + + elseif seconds < 60*60*24 * 2 then + return math.floor(0.5 + seconds/60/60/24) .. " day" + elseif seconds < 60*60*24 * 30 then + return math.floor(0.5 + seconds/60/60/24) .. " days" + + elseif seconds < 60*60*24 *30 *2 then + return math.floor(0.5 + seconds/60/60/24 /30) .. " month" + elseif seconds < 60*60*24 *30 *12 then + return math.floor(0.5 + seconds/60/60/24 /30) .. " months" + + elseif seconds < 60*60*24 *30 *12 *2 then + return math.floor(0.5 + seconds/60/60/24 /30 /12) .. " year" + else + return math.floor(0.5 + seconds/60/60/24 /30 /12) .. " yrs" + end +end + function pairsByKeys(t, f) -- http://www.lua.org/pil/19.3.html local a = {}