mirror of
https://github.com/mt-mods/mail.git
synced 2025-04-30 08:21:44 -04:00
Add deleting contact
This commit is contained in:
parent
178a101618
commit
fd9b579c5f
2 changed files with 19 additions and 3 deletions
4
gui.lua
4
gui.lua
|
@ -739,7 +739,7 @@ function mail.handle_receivefields(player, formname, fields)
|
|||
selected_idxs.contacts[name] = k
|
||||
break
|
||||
elseif k == selected_idxs.contacts[name] then
|
||||
contacts[selected_idxs.contacts[name]] = nil
|
||||
mail.deleteContact(name, contacts[selected_idxs.contacts[name]].name)
|
||||
selected_idxs.contacts[name] = nil
|
||||
found = true
|
||||
else
|
||||
|
@ -750,8 +750,6 @@ function mail.handle_receivefields(player, formname, fields)
|
|||
-- was the last in the list, so take the previous (new last)
|
||||
selected_idxs.contacts[name] = last
|
||||
end
|
||||
|
||||
mail.setContacts(name, contacts)
|
||||
end
|
||||
|
||||
mail.show_contacts(name)
|
||||
|
|
18
storage.lua
18
storage.lua
|
@ -226,6 +226,24 @@ function mail.setContact(playername, updated_contact)
|
|||
end
|
||||
end
|
||||
|
||||
function mail.deleteContact(owner, name)
|
||||
local contacts = mail.getContacts()
|
||||
local newContacts = {}
|
||||
for _, contact in ipairs(contacts) do
|
||||
if contact.owner == owner and contact.name == name then
|
||||
table.remove(contacts, _)
|
||||
else
|
||||
table.insert(newContacts, contact)
|
||||
end
|
||||
end
|
||||
if mail.write_json_file(mail.maildir .. "/mail.contacts.json", newContacts) then
|
||||
return true
|
||||
else
|
||||
minetest.log("error","[mail] Save failed - messages may be lost!")
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
function mail.read_json_file(path)
|
||||
local file = io.open(path, "r")
|
||||
local content = {}
|
||||
|
|
Loading…
Add table
Reference in a new issue