Skip to content

Commit

Permalink
satisfy luacheck
Browse files Browse the repository at this point in the history
  • Loading branch information
BuckarooBanzay committed Oct 13, 2020
1 parent 63521f5 commit 51e80c6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
29 changes: 17 additions & 12 deletions gui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function mail.show_edit_contact(name, contact_name, note, illegal_name_hint)
minetest.show_formspec(name, "mail:editcontact", formspec)
end

function mail.show_select_contact(name, to, cc, bcc)
function mail.show_select_contact(name, to, cc)
local formspec = mail.select_contact_formspec
local contacts = mail.compile_contact_list(name, selected_idxs.contacts[name])

Expand Down Expand Up @@ -183,7 +183,7 @@ function mail.compile_contact_list(name, selected, playernames)

if playernames == nil then
local length = 0
for k, contact, i, l in pairsByKeys(contacts) do
for k, contact, i, l in mail.pairsByKeys(contacts) do
if i == 1 then length = l end
formspec[#formspec + 1] = ","
formspec[#formspec + 1] = ","
Expand Down Expand Up @@ -534,7 +534,7 @@ function mail.handle_receivefields(player, formname, fields)
if fields[v.."add"] then
update = true
if selected_idxs.contacts[name] then
for k, contact, i in pairsByKeys(contacts) do
for k, contact, i in mail.pairsByKeys(contacts) do
if k == selected_idxs.contacts[name] or i == selected_idxs.contacts[name] then
local list = mail.parse_player_list(draft[v])
list[#list+1] = contact.name
Expand Down Expand Up @@ -565,10 +565,6 @@ function mail.handle_receivefields(player, formname, fields)
return true
end

if fields.back then
-- just do the default stuff below, as ESC will
end

-- delete old idxs
for _,v in ipairs({"contacts","to","cc","bcc"}) do
selected_idxs[v][name] = nil
Expand All @@ -582,27 +578,36 @@ function mail.handle_receivefields(player, formname, fields)

if fields.contacts then
local evt = minetest.explode_table_event(fields.contacts)
for k,c,i in pairsByKeys(contacts) do
for k, _, i in mail.pairsByKeys(contacts) do
if i == evt.row - 1 then
selected_idxs.contacts[name] = k
break
end
end
if evt.type == "DCL" and contacts[selected_idxs.contacts[name]] then
mail.show_edit_contact(name, contacts[selected_idxs.contacts[name]].name, contacts[selected_idxs.contacts[name]].note)
mail.show_edit_contact(
name,
contacts[selected_idxs.contacts[name]].name,
contacts[selected_idxs.contacts[name]].note
)
end
return true
elseif fields.new then
selected_idxs.contacts[name] = "#NEW#"
mail.show_edit_contact(name, "", "")
elseif fields.edit then
mail.show_edit_contact(name, contacts[selected_idxs.contacts[name]].name, contacts[selected_idxs.contacts[name]].note)
mail.show_edit_contact(
name,
contacts[selected_idxs.contacts[name]].name,
contacts[selected_idxs.contacts[name]].note
)
elseif fields.delete then
if contacts[selected_idxs.contacts[name]] then
-- delete the contact and set the selected to the next in the list, except if it was the last. Then determine the new last
-- delete the contact and set the selected to the next in the list,
-- except if it was the last. Then determine the new last
local found = false
local last = nil
for k,v,i in pairsByKeys(contacts) do
for k in mail.pairsByKeys(contacts) do
if found then
selected_idxs.contacts[name] = k
break
Expand Down
2 changes: 1 addition & 1 deletion migrate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ mail.migrate_contacts = function(playername)
local contacts = {}

if messages and not contacts then
for k,message in pairs(messages) do
for _, message in pairs(messages) do
mail.ensure_new_format(message)
if contacts[string.lower(message.from)] == nil then
contacts[string.lower(message.from)] = {
Expand Down
2 changes: 1 addition & 1 deletion storage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ mail.getContacts = function(playername)
return mail.read_json_file(mail.getContactsFile(playername))
end

function pairsByKeys(t, f)
function mail.pairsByKeys(t, f)
-- http://www.lua.org/pil/19.3.html
local a = {}
for n in pairs(t) do table.insert(a, n) end
Expand Down
4 changes: 2 additions & 2 deletions util/normalize.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ and add individual player names to recipient list
--]]
function mail.normalize_players_and_add_recipients(field, recipients)
local order = mail.parse_player_list(field)
for i,c in ipairs(order) do
for _, c in ipairs(order) do
if recipients[string.lower(c)] == nil then
recipients[string.lower(c)] = c
end
Expand Down Expand Up @@ -40,7 +40,7 @@ function mail.player_in_list(name, list)
if type(list) == "string" then
list = mail.parse_player_list(list)
end
for k,c in pairs(list) do
for _, c in pairs(list) do
if name == c then
return true
end
Expand Down

0 comments on commit 51e80c6

Please sign in to comment.