mirror of
https://github.com/mt-mods/mail.git
synced 2025-04-30 16:31:43 -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
|
selected_idxs.contacts[name] = k
|
||||||
break
|
break
|
||||||
elseif k == selected_idxs.contacts[name] then
|
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
|
selected_idxs.contacts[name] = nil
|
||||||
found = true
|
found = true
|
||||||
else
|
else
|
||||||
|
@ -750,8 +750,6 @@ function mail.handle_receivefields(player, formname, fields)
|
||||||
-- was the last in the list, so take the previous (new last)
|
-- was the last in the list, so take the previous (new last)
|
||||||
selected_idxs.contacts[name] = last
|
selected_idxs.contacts[name] = last
|
||||||
end
|
end
|
||||||
|
|
||||||
mail.setContacts(name, contacts)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
mail.show_contacts(name)
|
mail.show_contacts(name)
|
||||||
|
|
18
storage.lua
18
storage.lua
|
@ -226,6 +226,24 @@ function mail.setContact(playername, updated_contact)
|
||||||
end
|
end
|
||||||
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)
|
function mail.read_json_file(path)
|
||||||
local file = io.open(path, "r")
|
local file = io.open(path, "r")
|
||||||
local content = {}
|
local content = {}
|
||||||
|
|
Loading…
Add table
Reference in a new issue