update testing harness / move contact-list function to util (#73)

* update testing harness / move contact-list function to util

* Use 5.x.1 versioning

---------

Co-authored-by: BuckarooBanzay <BuckarooBanzay@users.noreply.github.com>
Co-authored-by: Athozus <athozus@gmail.com>
This commit is contained in:
Buckaroo Banzai 2023-04-18 22:01:24 +02:00 committed by GitHub
parent 17d4c2e441
commit ed3c8b97a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 77 additions and 78 deletions

View File

@ -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

View File

@ -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/"

73
gui.lua
View File

@ -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"

View File

@ -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")

View File

@ -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

73
util/contact.lua Normal file
View File

@ -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