diff --git a/init.lua b/init.lua index 9c9e3ed..27f01cd 100644 --- a/init.lua +++ b/init.lua @@ -20,6 +20,7 @@ mail = { outbox = {}, drafts = {}, trash = {}, + message = {}, contacts = {}, maillists = {}, to = {}, diff --git a/ui/compose.lua b/ui/compose.lua index 9187d10..dff83bd 100644 --- a/ui/compose.lua +++ b/ui/compose.lua @@ -2,7 +2,6 @@ local S = minetest.get_translator("mail") local FORMNAME = "mail:compose" -local msg_id = {} function mail.show_compose(name, to, subject, body, cc, bcc, id) local formspec = [[ @@ -28,9 +27,7 @@ function mail.show_compose(name, to, subject, body, cc, bcc, id) minetest.formspec_escape(body) or "") if id then - msg_id[name] = id - else - msg_id[name] = nil + mail.selected_idxs.message[name] = id end minetest.show_formspec(name, FORMNAME, formspec) @@ -44,8 +41,8 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) local name = player:get_player_name() if fields.send then local id = mail.new_uuid() - if msg_id[name] then - id = msg_id[name] + if mail.selected_idxs.message[name] then + id = mail.selected_idxs.message[name] end if (fields.to == "" and fields.cc == "" and fields.bcc == "") or fields.body == "" then -- if mail is invalid then store it as a draft @@ -117,8 +114,8 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) elseif fields.draft then local id = mail.new_uuid() - if msg_id[name] then - id = msg_id[name] + if mail.selected_idxs.message[name] then + id = mail.selected_idxs.message[name] end mail.save_draft({ id = id, diff --git a/ui/events.lua b/ui/events.lua index b241910..6de9c93 100644 --- a/ui/events.lua +++ b/ui/events.lua @@ -89,11 +89,14 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) end if selected_id == 0 then table.insert(mail.selected_idxs.inbox[name], inbox.id) + mail.selected_idxs.message[name] = inbox.id end else mail.selected_idxs.inbox[name] = { inbox.id } + mail.selected_idxs.message[name] = inbox.id end if evt.type == "DCL" then + mail.selected_idxs.message[name] = inbox.id mail.show_message(name, inbox.id) else mail.show_mail_menu(name) @@ -132,11 +135,14 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) end if selected_id == 0 then table.insert(mail.selected_idxs.outbox[name], outbox.id) + mail.selected_idxs.message[name] = outbox.id end else mail.selected_idxs.outbox[name] = { outbox.id } + mail.selected_idxs.message[name] = outbox.id end if evt.type == "DCL" then + mail.selected_idxs.message[name] = outbox.id mail.show_message(name, outbox.id) else mail.show_mail_menu(name) @@ -156,6 +162,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) end mail.selected_idxs.drafts[name] = evt.row - 1 if evt.type == "DCL" and messagesDrafts[mail.selected_idxs.drafts[name]] then + mail.selected_idxs.message[name] = messagesDrafts[mail.selected_idxs.drafts[name]].id mail.show_compose(name, messagesDrafts[mail.selected_idxs.drafts[name]].to, messagesDrafts[mail.selected_idxs.drafts[name]].subject, @@ -180,6 +187,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) end mail.selected_idxs.trash[name] = evt.row - 1 if evt.type == "DCL" and messagesTrash[mail.selected_idxs.trash[name]] then + mail.selected_idxs.message[name] = messagesTrash[mail.selected_idxs.trash[name]].id mail.show_message(name, messagesTrash[mail.selected_idxs.trash[name]].id) end return true @@ -203,12 +211,13 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) elseif fields.read then if formname == "mail:inbox" and nonempty(mail.selected_idxs.inbox[name]) then -- inbox table - mail.show_message(name, mail.selected_idxs.inbox[name][#mail.selected_idxs.inbox[name]]) + mail.selected_idxs.message[name] = mail.selected_idxs.inbox[name][#mail.selected_idxs.inbox[name]] elseif formname == "mail:outbox" and nonempty(mail.selected_idxs.outbox[name]) then -- outbox table - mail.show_message(name, mail.selected_idxs.outbox[name][#mail.selected_idxs.outbox[name]]) + mail.selected_idxs.message[name] = mail.selected_idxs.outbox[name][#mail.selected_idxs.outbox[name]] elseif formname == "mail:trash" and messagesTrash[mail.selected_idxs.trash[name]] then - mail.show_message(name, messagesTrash[mail.selected_idxs.trash[name]].id) + mail.selected_idxs.message[name] = messagesTrash[mail.selected_idxs.trash[name]].id end + mail.show_message(name, mail.selected_idxs.message[name]) elseif fields.edit then if formname == "mail:drafts" and messagesDrafts[mail.selected_idxs.drafts[name]] then diff --git a/ui/message.lua b/ui/message.lua index 0bb3fcf..644f4b3 100644 --- a/ui/message.lua +++ b/ui/message.lua @@ -5,6 +5,7 @@ local FORMNAME = "mail:message" function mail.show_message(name, id) local message = mail.get_message(name, id) + mail.selected_idxs.message[name] = id local formspec = [[ size[8,9] @@ -111,16 +112,8 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) end local name = player:get_player_name() - local entry = mail.get_storage_entry(name) - - local message = "" - if mail.selected_idxs.inbox[name] and mail.selected_idxs.boxtab[name] == 1 then - message = mail.get_message(name, mail.selected_idxs.inbox[name][#mail.selected_idxs.inbox[name]]) - elseif mail.selected_idxs.outbox[name] and mail.selected_idxs.boxtab[name] == 2 then - message = mail.get_message(name, mail.selected_idxs.outbox[name][#mail.selected_idxs.outbox[name]]) - elseif mail.selected_idxs.trash[name] and mail.selected_idxs.boxtab[name] == 4 then - message = mail.get_message(name, entry.trash[mail.selected_idxs.trash[name]].id) - end + + local message = mail.get_message(name, mail.selected_idxs.message[name]) if fields.back then mail.show_mail_menu(name) diff --git a/ui/receivers.lua b/ui/receivers.lua index cb953be..14799a5 100644 --- a/ui/receivers.lua +++ b/ui/receivers.lua @@ -43,16 +43,8 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) end local name = player:get_player_name() - local entry = mail.get_storage_entry(name) - - local message_id = "" - if mail.selected_idxs.inbox[name] and mail.selected_idxs.boxtab[name] == 1 then - message_id = mail.selected_idxs.inbox[name][#mail.selected_idxs.inbox[name]] - elseif mail.selected_idxs.outbox[name] and mail.selected_idxs.boxtab[name] == 2 then - message_id = mail.selected_idxs.outbox[name][#mail.selected_idxs.outbox[name]] - elseif mail.selected_idxs.trash[name] and mail.selected_idxs.boxtab[name] == 4 then - message_id = entry.trash[mail.selected_idxs.trash[name]].id - end + + local message_id = mail.selected_idxs.message[name] if fields.back then mail.show_message(name, message_id)