Minor fixes (#34)

* Minor fixes

* Security fix

* Minor button fix
This commit is contained in:
Athozus 2023-03-31 18:08:51 +02:00 committed by GitHub
parent 0ea3777b51
commit 4d4fd90eee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 12 deletions

11
api.lua
View File

@ -63,8 +63,7 @@ function mail.send(m)
m.from, m.to, extra_log, m.subject, m.body
))
local id = mail.new_uuid()
local id
if m.id then
mail.delete_mail(m.from, m.id)
id = m.id
@ -72,7 +71,7 @@ function mail.send(m)
-- form the actual mail
local msg = {
id = id,
id = id or mail.new_uuid(),
from = m.from,
to = m.to,
cc = m.cc,
@ -125,12 +124,12 @@ function mail.save_draft(m)
m.subject = string.sub(m.subject,1,27) .. "..."
end
minetest.log("action", f("[mail] %q saves draft with subject %q and body %q",
minetest.log("verbose", f("[mail] %q saves draft with subject %q and body %q",
m.from, m.subject, m.body
))
-- remove it is an update
local id = mail.new_uuid()
local id
if m.id then
mail.delete_mail(m.from, m.id)
id = m.id
@ -139,7 +138,7 @@ function mail.save_draft(m)
-- add (again ie. update) in sender drafts
local entry = mail.get_storage_entry(m.from)
table.insert(entry.drafts, 1, {
id = id,
id = id or mail.new_uuid(),
from = m.from,
to = m.to,
cc = m.cc,

View File

@ -1,5 +1,5 @@
local FORMNAME = "mail:compose"
local msg_id = nil
local msg_id = {}
function mail.show_compose(name, to, subject, body, cc, bcc, id)
local formspec = [[
@ -25,7 +25,7 @@ function mail.show_compose(name, to, subject, body, cc, bcc, id)
minetest.formspec_escape(body) or "")
if id then
msg_id = id
msg_id[name] = id
end
minetest.show_formspec(name, FORMNAME, formspec)
@ -39,8 +39,8 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
local name = player:get_player_name()
if fields.send then
local id = mail.new_uuid()
if msg_id then
id = msg_id
if msg_id[name] then
id = msg_id[name]
end
local success, err = mail.send({
id = id,
@ -97,8 +97,8 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
elseif fields.draft then
local id = mail.new_uuid()
if msg_id then
id = msg_id
if msg_id[name] then
id = msg_id[name]
end
mail.save_draft({
id = id,

View File

@ -65,6 +65,18 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
mail.show_message(name, messagesSent[mail.selected_idxs.sent[name]].id)
end
elseif fields.edit then
if formname == "mail:drafts" and messagesDrafts[mail.selected_idxs.drafts[name]] then
mail.show_compose(name,
messagesDrafts[mail.selected_idxs.drafts[name]].to,
messagesDrafts[mail.selected_idxs.drafts[name]].subject,
messagesDrafts[mail.selected_idxs.drafts[name]].body,
messagesDrafts[mail.selected_idxs.drafts[name]].cc,
messagesDrafts[mail.selected_idxs.drafts[name]].bcc,
messagesDrafts[mail.selected_idxs.drafts[name]].id
)
end
elseif fields.delete then
if formname == "mail:inbox" and messagesInbox[mail.selected_idxs.inbox[name]] then -- inbox table
mail.delete_mail(name, messagesInbox[mail.selected_idxs.inbox[name]].id)