diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ff090e0..f181b6e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,7 +9,7 @@ jobs: timeout-minutes: 10 strategy: matrix: - ENGINE_VERSION: [5.0.0, 5.1.0, 5.2.0, 5.3.0, 5.4.0, 5.5.0, 5.6.0, 5.6.1, latest] + ENGINE_VERSION: [5.0.1, 5.1.1, 5.2.0, 5.3.0, 5.4.1, 5.5.1, 5.6.1, 5.7.0, latest] steps: - uses: actions/checkout@v3 diff --git a/docker-compose.yml b/docker-compose.yml index 865f083..f7f9976 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,7 +5,7 @@ services: build: context: ./test args: - ENGINE_VERSION: ${ENGINE_VERSION:-5.5.0} + ENGINE_VERSION: ${ENGINE_VERSION:-5.7.0} user: root volumes: - "./:/root/.minetest/worlds/world/worldmods/mail/" diff --git a/gui.lua b/gui.lua index 9607771..d1dca04 100644 --- a/gui.lua +++ b/gui.lua @@ -1,77 +1,4 @@ -function mail.compile_contact_list(name, selected, playernames) - -- TODO: refactor this - not just compiles *a* list, but *the* list for the contacts screen (too inflexible) - local formspec = {} - local contacts = mail.get_contacts(name) - - if playernames == nil then - local length = 0 - for k, contact, i, l in mail.pairsByKeys(contacts) do - if i == 1 then length = l end - formspec[#formspec + 1] = "," - formspec[#formspec + 1] = "," - formspec[#formspec + 1] = minetest.formspec_escape(contact.name) - formspec[#formspec + 1] = "," - local note = contact.note - -- display an ellipsis if the note spans multiple lines - local idx = string.find(note, '\n') - if idx ~= nil then - note = string.sub(note, 1, idx-1) .. ' ...' - end - formspec[#formspec + 1] = minetest.formspec_escape(note) - if type(selected) == "string" then - if string.lower(selected) == k then - selected = i - end - end - end - if length > 0 then - if selected and type(selected) == "number" then - formspec[#formspec + 1] = ";" - formspec[#formspec + 1] = tostring(selected + 1) - end - formspec[#formspec + 1] = "]" - else - formspec[#formspec + 1] = "]label[2,4.5;No contacts]" - end - else - if type(playernames) == "string" then - playernames = mail.parse_player_list(playernames) - end - for i,c in ipairs(playernames) do - formspec[#formspec + 1] = "," - formspec[#formspec + 1] = "," - formspec[#formspec + 1] = minetest.formspec_escape(c) - formspec[#formspec + 1] = "," - if contacts[string.lower(c)] == nil then - formspec[#formspec + 1] = "" - else - local note = contacts[string.lower(c)].note - -- display an ellipsis if the note spans multiple lines - local idx = string.find(note, '\n') - if idx ~= nil then - note = string.sub(note, 1, idx-1) .. ' ...' - end - formspec[#formspec + 1] = minetest.formspec_escape(note) - end - if not selected then - if type(selected) == "string" then - if string.lower(selected) == string.lower(c) then - selected = i - end - end - end - end - if #playernames > 0 and selected and type(selected) == "number" then - formspec[#formspec + 1] = ";" - formspec[#formspec + 1] = tostring(selected + 1) - end - formspec[#formspec + 1] = "]" - end - return table.concat(formspec, "") - -end - if minetest.get_modpath("unified_inventory") then mail.receive_mail_message = mail.receive_mail_message .. " or use the mail button in the inventory" diff --git a/init.lua b/init.lua index 283e7c6..a8f0951 100644 --- a/init.lua +++ b/init.lua @@ -38,6 +38,7 @@ end -- sub files local MP = minetest.get_modpath(minetest.get_current_modname()) dofile(MP .. "/util/normalize.lua") +dofile(MP .. "/util/contact.lua") dofile(MP .. "/util/uuid.lua") dofile(MP .. "/chatcommands.lua") dofile(MP .. "/migrate.lua") diff --git a/test/Dockerfile b/test/Dockerfile index 9c1bd1b..472255d 100644 --- a/test/Dockerfile +++ b/test/Dockerfile @@ -1,4 +1,4 @@ -ARG ENGINE_VERSION=5.5.0 +ARG ENGINE_VERSION=5.7.0 FROM registry.gitlab.com/minetest/minetest/server:${ENGINE_VERSION} # copy old v1 maildb for migration testing @@ -7,11 +7,9 @@ COPY ./mail.db /root/.minetest/worlds/world/mail.db COPY ./old_v2_player.json /root/.minetest/worlds/world/mails/ COPY ./auth.sqlite /root/.minetest/worlds/world/auth.sqlite - USER root RUN apk add git &&\ mkdir -p /root/.minetest/worlds/world/worldmods/ &&\ git clone https://github.com/BuckarooBanzay/mtt /root/.minetest/worlds/world/worldmods/mtt - ENTRYPOINT minetestserver --config /minetest.conf \ No newline at end of file diff --git a/util/contact.lua b/util/contact.lua new file mode 100644 index 0000000..ff7c9c5 --- /dev/null +++ b/util/contact.lua @@ -0,0 +1,73 @@ + +function mail.compile_contact_list(name, selected, playernames) + -- TODO: refactor this - not just compiles *a* list, but *the* list for the contacts screen (too inflexible) + local formspec = {} + local contacts = mail.get_contacts(name) + + if playernames == nil then + local length = 0 + for k, contact, i, l in mail.pairsByKeys(contacts) do + if i == 1 then length = l end + formspec[#formspec + 1] = "," + formspec[#formspec + 1] = "," + formspec[#formspec + 1] = minetest.formspec_escape(contact.name) + formspec[#formspec + 1] = "," + local note = contact.note + -- display an ellipsis if the note spans multiple lines + local idx = string.find(note, '\n') + if idx ~= nil then + note = string.sub(note, 1, idx-1) .. ' ...' + end + formspec[#formspec + 1] = minetest.formspec_escape(note) + if type(selected) == "string" then + if string.lower(selected) == k then + selected = i + end + end + end + if length > 0 then + if selected and type(selected) == "number" then + formspec[#formspec + 1] = ";" + formspec[#formspec + 1] = tostring(selected + 1) + end + formspec[#formspec + 1] = "]" + else + formspec[#formspec + 1] = "]label[2,4.5;No contacts]" + end + else + if type(playernames) == "string" then + playernames = mail.parse_player_list(playernames) + end + for i,c in ipairs(playernames) do + formspec[#formspec + 1] = "," + formspec[#formspec + 1] = "," + formspec[#formspec + 1] = minetest.formspec_escape(c) + formspec[#formspec + 1] = "," + if contacts[string.lower(c)] == nil then + formspec[#formspec + 1] = "" + else + local note = contacts[string.lower(c)].note + -- display an ellipsis if the note spans multiple lines + local idx = string.find(note, '\n') + if idx ~= nil then + note = string.sub(note, 1, idx-1) .. ' ...' + end + formspec[#formspec + 1] = minetest.formspec_escape(note) + end + if not selected then + if type(selected) == "string" then + if string.lower(selected) == string.lower(c) then + selected = i + end + end + end + end + if #playernames > 0 and selected and type(selected) == "number" then + formspec[#formspec + 1] = ";" + formspec[#formspec + 1] = tostring(selected + 1) + end + formspec[#formspec + 1] = "]" + end + return table.concat(formspec, "") + +end \ No newline at end of file