Fix duplicating of maillist while changing its name

This commit is contained in:
Athozus 2023-04-02 10:27:36 +02:00
parent 8f59abdd11
commit 7fb292556c
No known key found for this signature in database
GPG key ID: B50895022E8484BF
2 changed files with 9 additions and 11 deletions

View file

@ -148,21 +148,17 @@ function mail.get_maillist_by_name(playername, listname)
end
-- updates or creates a maillist
function mail.update_maillist(playername, list)
function mail.update_maillist(playername, list, old_list_name)
local entry = mail.get_storage_entry(playername)
local existing_updated = false
for i, existing_list in ipairs(entry.lists) do
if existing_list.name == list.name then
-- update
entry.lists[i] = list
existing_updated = true
if existing_list.name == old_list_name then
-- delete
table.remove(entry.lists, i)
break
end
end
if not existing_updated then
-- insert
table.insert(entry.lists, list)
end
-- insert
table.insert(entry.lists, list)
mail.set_storage_entry(playername, entry)
end