Update selection list after an action (fix #80, #81, #83)

This commit is contained in:
Athozus 2023-05-02 10:38:08 +02:00
parent ec92aaba05
commit c670d48622
No known key found for this signature in database
GPG Key ID: B50895022E8484BF
3 changed files with 35 additions and 0 deletions

View File

@ -188,10 +188,13 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
elseif fields.delete then
if formname == "mail:inbox" and mail.selected_idxs.inbox[name] then -- inbox table
mail.delete_mail(name, mail.selected_idxs.inbox[name])
mail.selected_idxs.inbox[name] = {}
elseif formname == "mail:sent" and mail.selected_idxs.sent[name] then -- sent table
mail.delete_mail(name, mail.selected_idxs.sent[name])
mail.selected_idxs.sent[name] = {}
elseif formname == "mail:drafts" and messagesDrafts[mail.selected_idxs.drafts[name]] then -- drafts table
mail.delete_mail(name, messagesDrafts[mail.selected_idxs.drafts[name]].id)
mail.selected_idxs.drafts[name] = nil
end
mail.show_mail_menu(name, sortfieldindex, sortdirection, filter)

View File

@ -104,5 +104,21 @@ function mail.show_inbox(name, sortfieldindex, sortdirection, filter)
else
formspec[#formspec + 1] = "]label[2.25,4.5;" .. S("No mail") .. "]"
end
if mail.selected_idxs.inbox[name] and #mail.selected_idxs.inbox[name] > 0 then
for i, selected_msg in ipairs(mail.selected_idxs.inbox[name]) do
local is_present = false
for _, msg in ipairs(messages) do
if msg.id == selected_msg then
is_present = true
break
end
end
if not is_present then
table.remove(mail.selected_idxs.inbox[name], i)
end
end
end
minetest.show_formspec(name, "mail:inbox", table.concat(formspec, ""))
end

View File

@ -83,5 +83,21 @@ function mail.show_sent(name, sortfieldindex, sortdirection, filter)
else
formspec[#formspec + 1] = "]label[2.25,4.5;" .. S("No mail") .. "]"
end
if mail.selected_idxs.sent[name] and #mail.selected_idxs.sent[name] > 0 then
for i, selected_msg in ipairs(mail.selected_idxs.sent[name]) do
local is_present = false
for _, msg in ipairs(messages) do
if msg.id == selected_msg then
is_present = true
break
end
end
if not is_present then
table.remove(mail.selected_idxs.sent[name], i)
end
end
end
minetest.show_formspec(name, "mail:sent", table.concat(formspec, ""))
end