mirror of
https://github.com/mt-mods/mail.git
synced 2025-07-18 12:16:41 -04:00
status refactoring
This commit is contained in:
parent
706b870b7d
commit
b414ace620
9 changed files with 91 additions and 176 deletions
23
migrate.lua
23
migrate.lua
|
@ -13,12 +13,12 @@ end
|
|||
function mail.migrate_v2_to_v3()
|
||||
minetest.mkdir(mail.maildir) -- if necessary (eg. first login)
|
||||
print("[mail] Migration from v2 to v3 database")
|
||||
local already_processed = {} -- store messages that are already process to avoid duplicates
|
||||
|
||||
minetest.after(0,function()
|
||||
for playername, _ in minetest.get_auth_handler().iterate() do
|
||||
local player_contacts = mail.read_json_file(mail.maildir .. "/contacts/" .. playername .. ".json")
|
||||
local entry = mail.get_storage_entry(playername)
|
||||
|
||||
local player_contacts = mail.read_json_file(mail.maildir .. "/contacts/" .. playername .. ".json")
|
||||
for _, c in pairs(player_contacts) do
|
||||
table.insert(entry.contacts, { name = c.name, note = c.note })
|
||||
end
|
||||
|
@ -26,27 +26,16 @@ function mail.migrate_v2_to_v3()
|
|||
local saneplayername = string.gsub(playername, "[.|/]", "")
|
||||
local player_inbox = mail.read_json_file(mail.maildir .. "/" .. saneplayername .. ".json")
|
||||
for _, msg in ipairs(player_inbox) do
|
||||
-- id like "123456789.0singleplayer" -- it presumes that a same sender cannot send two mails within a second
|
||||
local msg_id = tostring(msg.time) .. msg.sender
|
||||
local new_msg = true -- check if that mail was already processed with another player
|
||||
for _, cur_id in ipairs(already_processed) do
|
||||
if cur_id == msg_id then
|
||||
new_msg = false
|
||||
break
|
||||
end
|
||||
end
|
||||
-- add if valid and "to" field populated (missing in ancient storage formats)
|
||||
if new_msg and msg.to then
|
||||
local msg_table = {
|
||||
if msg.to then
|
||||
table.insert(entry.inbox, {
|
||||
id = mail.new_uuid(),
|
||||
sender = msg.sender,
|
||||
to = msg.to,
|
||||
cc = msg.cc,
|
||||
subject = msg.subject,
|
||||
body = msg.body,
|
||||
time = msg.time,
|
||||
}
|
||||
mail.addMessage(msg_table)
|
||||
table.insert(already_processed, msg_id)
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue