mirror of
https://github.com/mt-mods/mail.git
synced 2025-07-10 00:20:34 -04:00
maillist refactoring
This commit is contained in:
parent
a690fc721d
commit
8ce3dc2ecf
5 changed files with 77 additions and 199 deletions
16
migrate.lua
16
migrate.lua
|
@ -1,6 +1,18 @@
|
|||
|
||||
local STORAGE_VERSION_KEY = "@@version"
|
||||
|
||||
local function read_json_file(path)
|
||||
local file = io.open(path, "r")
|
||||
local content = {}
|
||||
if file then
|
||||
local json = file:read("*a")
|
||||
content = minetest.parse_json(json or "[]") or {}
|
||||
file:close()
|
||||
end
|
||||
return content
|
||||
end
|
||||
|
||||
|
||||
function mail.migrate()
|
||||
local version = mail.storage:get_int(STORAGE_VERSION_KEY)
|
||||
if version < 3 then
|
||||
|
@ -18,13 +30,13 @@ function mail.migrate_v2_to_v3()
|
|||
for playername, _ in minetest.get_auth_handler().iterate() do
|
||||
local entry = mail.get_storage_entry(playername)
|
||||
|
||||
local player_contacts = mail.read_json_file(mail.maildir .. "/contacts/" .. playername .. ".json")
|
||||
local player_contacts = 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
|
||||
|
||||
local saneplayername = string.gsub(playername, "[.|/]", "")
|
||||
local player_inbox = mail.read_json_file(mail.maildir .. "/" .. saneplayername .. ".json")
|
||||
local player_inbox = read_json_file(mail.maildir .. "/" .. saneplayername .. ".json")
|
||||
for _, msg in ipairs(player_inbox) do
|
||||
if msg.to then
|
||||
table.insert(entry.inbox, {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue