mirror of
https://github.com/mt-mods/mail.git
synced 2025-07-26 09:04:49 -04:00
Message filters/sorters (#56)
* Add sorters for inbox/outbox * Add ascending/descending, fix selection issue * Add filters * Update translations * Fix UI * Fix luacheck * Fix fields disappearing after clicking on tabs/buttons * Fix luacheck (2) * Fix first message not sorted correctly
This commit is contained in:
parent
def93bdd0f
commit
da05b5d108
10 changed files with 265 additions and 116 deletions
|
@ -8,10 +8,34 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||
-- split inbox and sent msgs for different tests
|
||||
local entry = mail.get_storage_entry(name)
|
||||
|
||||
local messagesInbox = entry.inbox
|
||||
local messagesSent = entry.outbox
|
||||
local messagesInboxUnAnalyzed = entry.inbox
|
||||
local messagesOutBoxUnAnalyzed = entry.outbox
|
||||
local messagesDrafts = entry.drafts
|
||||
|
||||
-- filter inbox/outbox messages
|
||||
|
||||
local filter = fields.filter
|
||||
if not filter then
|
||||
filter = ""
|
||||
end
|
||||
|
||||
local messagesInboxFiltered = mail.filter_messages(messagesInboxUnAnalyzed, filter)
|
||||
local messagesOutboxFiltered = mail.filter_messages(messagesOutBoxUnAnalyzed, filter)
|
||||
|
||||
-- then sort them
|
||||
|
||||
local sortfield = tostring(fields.sortfield)
|
||||
local sortdirection = tostring(fields.sortdirection)
|
||||
if not sortfield or sortfield == "" or sortfield == "0" then
|
||||
sortfield = "3"
|
||||
end
|
||||
if not sortdirection or sortdirection == "" or sortdirection == "0" then
|
||||
sortdirection = "1"
|
||||
end
|
||||
|
||||
local messagesInbox = mail.sort_messages(messagesInboxFiltered, sortfield, sortdirection, filter)
|
||||
local messagesSent = mail.sort_messages(messagesOutboxFiltered, sortfield, sortdirection, filter)
|
||||
|
||||
if fields.inbox then -- inbox table
|
||||
local evt = minetest.explode_table_event(fields.inbox)
|
||||
mail.selected_idxs.inbox[name] = evt.row - 1
|
||||
|
@ -48,11 +72,11 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||
|
||||
if fields.boxtab == "1" then
|
||||
mail.selected_idxs.boxtab[name] = 1
|
||||
mail.show_inbox(name)
|
||||
mail.show_inbox(name, sortfield, sortdirection, filter)
|
||||
|
||||
elseif fields.boxtab == "2" then
|
||||
mail.selected_idxs.boxtab[name] = 2
|
||||
mail.show_sent(name)
|
||||
mail.show_sent(name, sortfield, sortdirection, filter)
|
||||
|
||||
elseif fields.boxtab == "3" then
|
||||
mail.selected_idxs.boxtab[name] = 3
|
||||
|
@ -86,7 +110,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||
mail.delete_mail(name, messagesDrafts[mail.selected_idxs.drafts[name]].id)
|
||||
end
|
||||
|
||||
mail.show_mail_menu(name)
|
||||
mail.show_mail_menu(name, sortfield, sortdirection, filter)
|
||||
|
||||
elseif fields.reply then
|
||||
if formname == "mail:inbox" and messagesInbox[mail.selected_idxs.inbox[name]] then
|
||||
|
@ -122,7 +146,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||
mail.mark_read(name, messagesSent[mail.selected_idxs.sent[name]].id)
|
||||
end
|
||||
|
||||
mail.show_mail_menu(name)
|
||||
mail.show_mail_menu(name, sortfield, sortdirection, filter)
|
||||
|
||||
elseif fields.markunread then
|
||||
if formname == "mail:inbox" and messagesInbox[mail.selected_idxs.inbox[name]] then
|
||||
|
@ -131,7 +155,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||
mail.mark_unread(name, messagesSent[mail.selected_idxs.sent[name]].id)
|
||||
end
|
||||
|
||||
mail.show_mail_menu(name)
|
||||
mail.show_mail_menu(name, sortfield, sortdirection, filter)
|
||||
|
||||
elseif fields.new then
|
||||
mail.show_compose(name)
|
||||
|
@ -145,6 +169,8 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||
elseif fields.about then
|
||||
mail.show_about(name)
|
||||
|
||||
elseif fields.sortfield or fields.sortdirection or fields.filter then
|
||||
mail.show_mail_menu(name, sortfield, sortdirection, filter)
|
||||
end
|
||||
|
||||
return true
|
||||
|
|
56
ui/inbox.lua
56
ui/inbox.lua
|
@ -1,30 +1,50 @@
|
|||
-- translation
|
||||
local S = minetest.get_translator("mail")
|
||||
|
||||
local inbox_formspec = "size[8.5,10;]" .. mail.theme .. [[
|
||||
tabheader[0.3,1;boxtab;]] .. S("Inbox") .. "," .. S("Sent messages").. "," .. S("Drafts") .. [[;1;false;false]
|
||||
|
||||
button[6,0.10;2.5,0.5;new;]] .. S("New") .. [[]
|
||||
button[6,0.95;2.5,0.5;read;]] .. S("Read") .. [[]
|
||||
button[6,1.70;2.5,0.5;reply;]] .. S("Reply") .. [[]
|
||||
button[6,2.45;2.5,0.5;replyall;]] .. S("Reply all") .. [[]
|
||||
button[6,3.20;2.5,0.5;forward;]] .. S("Forward") .. [[]
|
||||
button[6,3.95;2.5,0.5;delete;]] .. S("Delete") .. [[]
|
||||
button[6,4.82;2.5,0.5;markread;]] .. S("Mark Read") .. [[]
|
||||
button[6,5.55;2.5,0.5;markunread;]] .. S("Mark Unread") .. [[]
|
||||
button[6,6.8;2.5,0.5;contacts;]] .. S("Contacts") .. [[]
|
||||
button[6,7.6;2.5,0.5;maillists;]] .. S("Mail lists") .. [[]
|
||||
button[6,8.7;2.5,0.5;about;]] .. S("About") .. [[]
|
||||
button_exit[6,9.5;2.5,0.5;quit;]] .. S("Close") .. [[]
|
||||
function mail.show_inbox(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
|
||||
|
||||
tablecolumns[color;text;text]
|
||||
table[0,0.7;5.75,9.35;inbox;#999,]] .. S("From") .. "," .. S("Subject")
|
||||
sortfield = tostring(sortfield)
|
||||
sortdirection = tostring(sortdirection)
|
||||
|
||||
if not filter then
|
||||
filter = ""
|
||||
end
|
||||
|
||||
function mail.show_inbox(name)
|
||||
local inbox_formspec = "size[8.5,10;]" .. mail.theme .. [[
|
||||
tabheader[0.3,1;boxtab;]] .. S("Inbox") .. "," .. S("Sent messages").. "," .. S("Drafts") .. [[;1;false;false]
|
||||
|
||||
button[6,0.10;2.5,0.5;new;]] .. S("New") .. [[]
|
||||
button[6,0.95;2.5,0.5;read;]] .. S("Read") .. [[]
|
||||
button[6,1.70;2.5,0.5;reply;]] .. S("Reply") .. [[]
|
||||
button[6,2.45;2.5,0.5;replyall;]] .. S("Reply all") .. [[]
|
||||
button[6,3.20;2.5,0.5;forward;]] .. S("Forward") .. [[]
|
||||
button[6,3.95;2.5,0.5;delete;]] .. S("Delete") .. [[]
|
||||
button[6,4.82;2.5,0.5;markread;]] .. S("Mark Read") .. [[]
|
||||
button[6,5.55;2.5,0.5;markunread;]] .. S("Mark Unread") .. [[]
|
||||
button[6,6.8;2.5,0.5;contacts;]] .. S("Contacts") .. [[]
|
||||
button[6,7.6;2.5,0.5;maillists;]] .. S("Mail lists") .. [[]
|
||||
button[6,8.7;2.5,0.5;about;]] .. S("About") .. [[]
|
||||
button_exit[6,9.5;2.5,0.5;quit;]] .. S("Close") .. [[]
|
||||
|
||||
dropdown[0,9.4;2,0.5;sortfield;]] ..
|
||||
S("From") .. "," .. S("Subject") .. "," .. S("Date") .. [[;]] .. tostring(sortfield) .. [[;1]
|
||||
dropdown[2.0,9.4;2,0.5;sortdirection;]] ..
|
||||
S("Ascending") .. "," .. S("Descending") .. [[;]] .. tostring(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]
|
||||
|
||||
tablecolumns[color;text;text]
|
||||
table[0,0.7;5.75,8.35;inbox;#999,]] .. S("From") .. "," .. S("Subject")
|
||||
local formspec = { inbox_formspec }
|
||||
local entry = mail.get_storage_entry(name)
|
||||
local messages = entry.inbox
|
||||
local messages = mail.sort_messages(mail.filter_messages(entry.inbox, filter), sortfield, sortdirection)
|
||||
|
||||
mail.message_drafts[name] = nil
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
-- helper function for tabbed overview
|
||||
|
||||
function mail.show_mail_menu(playername)
|
||||
function mail.show_mail_menu(playername, sortfield, sortdirection, filter)
|
||||
local index = mail.selected_idxs.boxtab[playername] or 1
|
||||
if index == 1 then
|
||||
mail.show_inbox(playername)
|
||||
mail.show_inbox(playername, sortfield, sortdirection, filter)
|
||||
elseif index == 2 then
|
||||
mail.show_sent(playername)
|
||||
mail.show_sent(playername, sortfield, sortdirection, filter)
|
||||
elseif index == 3 then
|
||||
mail.show_drafts(playername)
|
||||
end
|
||||
|
|
|
@ -1,28 +1,48 @@
|
|||
-- translation
|
||||
local S = minetest.get_translator("mail")
|
||||
|
||||
local sent_formspec = "size[8.5,10;]" .. mail.theme .. [[
|
||||
tabheader[0.3,1;boxtab;]] .. S("Inbox") .. "," .. S("Sent messages").. "," .. S("Drafts") .. [[;2;false;false]
|
||||
|
||||
button[6,0.10;2.5,0.5;new;]] .. S("New") .. [[]
|
||||
button[6,0.95;2.5,0.5;read;]] .. S("Read") .. [[]
|
||||
button[6,1.70;2.5,0.5;reply;]] .. S("Reply") .. [[]
|
||||
button[6,2.45;2.5,0.5;replyall;]] .. S("Reply all") .. [[]
|
||||
button[6,3.20;2.5,0.5;forward;]] .. S("Forward") .. [[]
|
||||
button[6,3.95;2.5,0.5;delete;]] .. S("Delete") .. [[]
|
||||
button[6,6.8;2.5,0.5;contacts;]] .. S("Contacts") .. [[]
|
||||
button[6,7.6;2.5,0.5;maillists;]] .. S("Mail lists") .. [[]
|
||||
button[6,8.7;2.5,0.5;about;]] .. S("About") .. [[]
|
||||
button_exit[6,9.5;2.5,0.5;quit;]] .. S("Close") .. [[]
|
||||
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
|
||||
|
||||
tablecolumns[color;text;text]
|
||||
table[0,0.7;5.75,9.35;sent;#999,]] .. S("To") .. "," .. S("Subject")
|
||||
sortfield = tostring(sortfield)
|
||||
sortdirection = tostring(sortdirection)
|
||||
|
||||
if not filter then
|
||||
filter = ""
|
||||
end
|
||||
|
||||
function mail.show_sent(name)
|
||||
local sent_formspec = "size[8.5,10;]" .. mail.theme .. [[
|
||||
tabheader[0.3,1;boxtab;]] .. S("Inbox") .. "," .. S("Sent messages").. "," .. S("Drafts") .. [[;2;false;false]
|
||||
|
||||
button[6,0.10;2.5,0.5;new;]] .. S("New") .. [[]
|
||||
button[6,0.95;2.5,0.5;read;]] .. S("Read") .. [[]
|
||||
button[6,1.70;2.5,0.5;reply;]] .. S("Reply") .. [[]
|
||||
button[6,2.45;2.5,0.5;replyall;]] .. S("Reply all") .. [[]
|
||||
button[6,3.20;2.5,0.5;forward;]] .. S("Forward") .. [[]
|
||||
button[6,3.95;2.5,0.5;delete;]] .. S("Delete") .. [[]
|
||||
button[6,6.8;2.5,0.5;contacts;]] .. S("Contacts") .. [[]
|
||||
button[6,7.6;2.5,0.5;maillists;]] .. S("Mail lists") .. [[]
|
||||
button[6,8.7;2.5,0.5;about;]] .. S("About") .. [[]
|
||||
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]
|
||||
dropdown[2.0,9.4;2,0.5;sortdirection;]]
|
||||
.. S("Ascending") .. "," .. S("Descending") .. [[;]] .. tostring(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]
|
||||
|
||||
tablecolumns[color;text;text]
|
||||
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 = entry.outbox
|
||||
local messages = mail.sort_messages(mail.filter_messages(entry.outbox, filter), sortfield, sortdirection)
|
||||
|
||||
mail.message_drafts[name] = nil
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue