mirror of
https://github.com/mt-mods/mail.git
synced 2025-07-04 21:50:28 -04:00
Add deleting contact
This commit is contained in:
parent
178a101618
commit
fd9b579c5f
2 changed files with 19 additions and 3 deletions
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
Add a link
Reference in a new issue