mirror of
https://github.com/mt-mods/mail.git
synced 2025-07-05 14:10:31 -04:00
Simplify sorting and make it more readable (#58)
* Simplify sorting and make it more readable * Make sorter local * Fix sorters dropdowns go back to default * Fix luacheck * Move sorting dropdown values to selected_idxs * Show previous sorters when going back from message/contacts/... * Use shallow copy instead of original table * Open mail interface with previous tab/dropdowns * Rework mail.sort_messages * Combine filter and sort, make filtering safe * Remove checks and logging from sorters --------- Co-authored-by: Athozus <athozus@gmail.com>
This commit is contained in:
parent
0435a0fd21
commit
67bda9a788
6 changed files with 108 additions and 168 deletions
|
@ -2,20 +2,10 @@
|
|||
local S = minetest.get_translator("mail")
|
||||
|
||||
|
||||
function mail.show_sent(name, sortfield, sortdirection, filter)
|
||||
if not sortfield or sortfield == "" or sortfield == "0" then
|
||||
sortfield = 3
|
||||
end
|
||||
if not sortdirection or sortdirection == "" or sortdirection == "0" then
|
||||
sortdirection = 1
|
||||
end
|
||||
|
||||
sortfield = tostring(sortfield)
|
||||
sortdirection = tostring(sortdirection)
|
||||
|
||||
if not filter then
|
||||
filter = ""
|
||||
end
|
||||
function mail.show_sent(name, sortfieldindex, sortdirection, filter)
|
||||
sortfieldindex = tonumber(sortfieldindex or mail.selected_idxs.sortfield[name]) or 3
|
||||
sortdirection = sortdirection or mail.selected_idxs.sortdirection[name] or "1"
|
||||
filter = filter or ""
|
||||
|
||||
local sent_formspec = "size[8.5,10;]" .. mail.theme .. [[
|
||||
tabheader[0.3,1;boxtab;]] .. S("Inbox") .. "," .. S("Sent messages").. "," .. S("Drafts") .. [[;2;false;false]
|
||||
|
@ -32,9 +22,9 @@ function mail.show_sent(name, sortfield, sortdirection, filter)
|
|||
button_exit[6,9.5;2.5,0.5;quit;]] .. S("Close") .. [[]
|
||||
|
||||
dropdown[0,9.4;2,0.5;sortfield;]]
|
||||
.. S("To") .. "," .. S("Subject") .. "," .. S("Date") .. [[;]] .. tostring(sortfield) .. [[;1]
|
||||
.. S("To") .. "," .. S("Subject") .. "," .. S("Date") .. [[;]] .. sortfieldindex .. [[;1]
|
||||
dropdown[2.0,9.4;2,0.5;sortdirection;]]
|
||||
.. S("Ascending") .. "," .. S("Descending") .. [[;]] .. tostring(sortdirection) .. [[;1]
|
||||
.. S("Ascending") .. "," .. S("Descending") .. [[;]] .. sortdirection .. [[;1]
|
||||
field[4.25,9.85;1.4,0.5;filter;]].. S("Filter") .. [[:;]] .. filter .. [[]
|
||||
button[5.14,9.52;0.85,0.5;search;Q]
|
||||
|
||||
|
@ -42,11 +32,12 @@ function mail.show_sent(name, sortfield, sortdirection, filter)
|
|||
table[0,0.7;5.75,8.35;sent;#999,]] .. S("To") .. "," .. S("Subject")
|
||||
local formspec = { sent_formspec }
|
||||
local entry = mail.get_storage_entry(name)
|
||||
local messages = mail.sort_messages(mail.filter_messages(entry.outbox, filter), sortfield, sortdirection)
|
||||
local sortfield = ({"to","subject","time"})[sortfieldindex]
|
||||
local messages = mail.sort_messages(entry.outbox, sortfield, sortdirection == "2", filter)
|
||||
|
||||
mail.message_drafts[name] = nil
|
||||
|
||||
if messages[1] then
|
||||
if #messages > 0 then
|
||||
for _, message in ipairs(messages) do
|
||||
formspec[#formspec + 1] = ","
|
||||
formspec[#formspec + 1] = ","
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue