From 7449aaca526271bce157c0780a61671382d67072 Mon Sep 17 00:00:00 2001 From: Athozus Date: Wed, 26 Apr 2023 12:11:27 +0200 Subject: [PATCH] Message reply fixes (#78) * Fix reply buttons in message list * Give a default boxtab value (fix trivial issues) --- ui/events.lua | 12 ++++++------ ui/mail.lua | 3 +++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/ui/events.lua b/ui/events.lua index a9006ae..cab92c0 100644 --- a/ui/events.lua +++ b/ui/events.lua @@ -193,28 +193,28 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) mail.show_mail_menu(name, sortfieldindex, sortdirection, filter) elseif fields.reply then - if formname == "mail:inbox" and mail.selected_idxs.inbox[name] then + if formname == "mail:inbox" and mail.selected_idxs.inbox[name] and #mail.selected_idxs.inbox[name] > 0 then local message = mail.get_message(name, mail.selected_idxs.inbox[name][#mail.selected_idxs.inbox[name]]) mail.reply(name, message) - elseif formname == "mail:sent" and mail.selected_idxs.sent[name] then + elseif formname == "mail:sent" and mail.selected_idxs.sent[name] and #mail.selected_idxs.sent[name] > 0 then local message = mail.get_message(name, mail.selected_idxs.sent[name][#mail.selected_idxs.sent[name]]) mail.reply(name, message) end elseif fields.replyall then - if formname == "mail:inbox" and mail.selected_idxs.inbox[name] then + if formname == "mail:inbox" and mail.selected_idxs.inbox[name] and #mail.selected_idxs.inbox[name] > 0 then local message = mail.get_message(name, mail.selected_idxs.inbox[name][#mail.selected_idxs.inbox[name]]) mail.replyall(name, message) - elseif formname == "mail:sent" and mail.selected_idxs.sent[name] then + elseif formname == "mail:sent" and mail.selected_idxs.sent[name] and #mail.selected_idxs.sent[name] > 0 then local message = mail.get_message(name, mail.selected_idxs.sent[name][#mail.selected_idxs.sent[name]]) mail.replyall(name, message) end elseif fields.forward then - if formname == "mail:inbox" and mail.selected_idxs.inbox[name] then + if formname == "mail:inbox" and mail.selected_idxs.inbox[name] and #mail.selected_idxs.inbox[name] > 0 then local message = mail.get_message(name, mail.selected_idxs.inbox[name][#mail.selected_idxs.inbox[name]]) mail.forward(name, message) - elseif formname == "mail:sent" and mail.selected_idxs.sent[name] then + elseif formname == "mail:sent" and mail.selected_idxs.sent[name] and #mail.selected_idxs.sent[name] > 0 then local message = mail.get_message(name, mail.selected_idxs.sent[name][#mail.selected_idxs.sent[name]]) mail.forward(name, message) end diff --git a/ui/mail.lua b/ui/mail.lua index 3f685e9..d6fc408 100644 --- a/ui/mail.lua +++ b/ui/mail.lua @@ -2,6 +2,9 @@ function mail.show_mail_menu(playername, sortfield, sortdirection, filter) local index = mail.selected_idxs.boxtab[playername] or 1 + if not mail.selected_idxs.boxtab[playername] then + mail.selected_idxs.boxtab[playername] = 1 + end if index == 1 then mail.show_inbox(playername, sortfield, sortdirection, filter) elseif index == 2 then