Add multiple selection (#60)

* Add multiple selection

* Fix wrong messages issues

* Update translations

* Mix colors for unread/cc in inbox with selected green

* Fix duplicates when clicking on select all with already one selected, and add the number of selected items

* Fixes

* Remove old translations files

* Fix filter priority
This commit is contained in:
Athozus 2023-04-12 17:08:34 +02:00 committed by GitHub
parent 67bda9a788
commit 191e511a05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 293 additions and 148 deletions

View File

@ -23,7 +23,9 @@ mail = {
bcc = {},
boxtab = {},
sortfield = {},
sortdirection = {}
sortdirection = {},
filter = {},
multipleselection = {}
},
message_drafts = {}

View File

@ -3,33 +3,39 @@ BCC=BCC
Cancel=Abbrechen
Save draft=Entwurf Speichern
Send=Senden
CC=CC
Edit=Bearbeiten
Note=Notiz
Delete=Löschen
New=Neu
Name=Name
No drafts=Keine Entwürfe
Edit=Bearbeiten
Subject=Betreff
Player name=Spielername
your contacts.=ihre Kontakte.
The contact=Der Kontakt
Maillist name=Verteilerlistenname
Desc=Beschreibung
Players=Spieler
your maillists.=ihre Verteilerlisten.
The maillist=Die Verteilerliste
Back=Zurück
Save=Speichern
That name=Der Name
is already in=ist bereits in
name cannot=Name kann nicht
be empty.=leer sein.
Back=Zurück
Note=Notiz
Maillist name=Verteilerlistenname
Desc=Beschreibung
Players=Spieler
your maillists.=ihre Verteilerlisten.
The maillist=Die Verteilerliste
Mark Read=Als gelesen makieren
Mark Unread=Als ungelesen makieren
From=Von
(No description)=(Keine Beschreibung)
No maillist=Keine Verteilerliste
CC=CC
Read=Lesen
Ascending=
Descending=
Filter=
Allow multiple selection=
selected=
(Un)select all=
No mail=Keine Nachrichten
Inbox=Posteingang
Sent messages=Nachrichten senden
@ -43,10 +49,7 @@ Date=Datum
Reply=Antworten
Reply all=Allen antworten
Forward=Weiter
(No description)=(Keine Beschreibung)
No maillist=Keine Verteilerliste
Subject=Betreff
To=An
Delete=Löschen
Add=Hinzufügen
Remove=Entfernen
Name=Name
To=An

View File

@ -3,33 +3,39 @@ BCC=Cci
Cancel=Annuler
Save draft=Enregistrer le brouillon
Send=Envoyer
CC=Cc
Edit=Modifier
Note=Note
Delete=Supprimer
New=Nouveau
Name=Nom
No drafts=Pas de brouillons
Edit=Modifier
Subject=Objet
Player name=Nom du joueur
your contacts.=vos contacts.
The contact=Ce contact
Maillist name=Nom de la liste de diffusion
Desc=Desc
Players=Joueurs
your maillists.=vos listes de diffusion.
The maillist=Cette liste de diffusion
Back=Retour
Save=Sauvegarder
That name=Ce nom
is already in=existe déjà
name cannot=nom ne peut pas
be empty.=être vide.
Back=Retour
Note=Note
Maillist name=Nom de la liste de diffusion
Desc=Desc
Players=Joueurs
your maillists.=vos listes de diffusion.
The maillist=Cette liste de diffusion
Mark Read=Marquer comme lu
Mark Unread=Marquer non lu
From=De
(No description)=Sans description
No maillist=Aucune liste de diffusion
CC=Cc
Read=Lire
Ascending=Croissant
Descending=Décroissant
Filter=Filtre
Allow multiple selection=Autoriser la sélection multiple
selected=sélectionnés
(Un)select all=Tout (dé)selectionner
No mail=Aucun mail
Inbox=Boîte de réception
Sent messages=Messages envoyés
@ -43,10 +49,7 @@ Date=Date
Reply=Répondre
Reply all=Répondre à tous
Forward=Transférer
(No description)=Sans description
No maillist=Aucune liste de diffusion
Subject=Objet
To=À
Delete=Supprimer
Add=Ajouter
Remove=Enlever
Name=Nom
To=À

View File

@ -3,33 +3,39 @@ BCC=密件副本
Cancel=取消
Save draft=儲存草稿
Send=發送
CC=副本
Edit=編輯
Note=備註
Delete=刪除
New=新建
Name=名稱
No drafts=沒有草稿
Edit=編輯
Subject=主旨
Player name=玩家名稱
your contacts.=
The contact=
Maillist name=郵件列表名稱
Desc=描述
Players=玩家
your maillists.=
The maillist=
Back=返回
Save=儲存
That name=
is already in=
name cannot=
be empty.=
Back=返回
Note=備註
Maillist name=郵件列表名稱
Desc=描述
Players=玩家
your maillists.=
The maillist=
Mark Read=標記已讀
Mark Unread=標記未讀
From=寄件者
(No description)=(沒有描述)
No maillist=沒有郵件列表
CC=副本
Read=閱讀
Ascending=
Descending=
Filter=
Allow multiple selection=
selected=
(Un)select all=
No mail=沒有郵件
Inbox=收件箱
Sent messages=寄件備份
@ -43,10 +49,7 @@ Date=日期
Reply=回覆
Reply all=回覆所有人
Forward=轉寄
(No description)=(沒有描述)
No maillist=沒有郵件列表
Subject=主旨
To=收件人
Delete=刪除
Add=加入
Remove=移除
Name=名稱
To=收件人

View File

@ -3,33 +3,39 @@ BCC=
Cancel=
Save draft=
Send=
CC=
Edit=
Note=
Delete=
New=
Name=
No drafts=
Edit=
Subject=
Player name=
your contacts.=
The contact=
Maillist name=
Desc=
Players=
your maillists.=
The maillist=
Back=
Save=
That name=
is already in=
name cannot=
be empty.=
Back=
Note=
Maillist name=
Desc=
Players=
your maillists.=
The maillist=
Mark Read=
Mark Unread=
From=
(No description)=
No maillist=
CC=
Read=
Ascending=
Descending=
Filter=
Allow multiple selection=
selected=
(Un)select all=
No mail=
Inbox=
Sent messages=
@ -43,10 +49,7 @@ Date=
Reply=
Reply all=
Forward=
(No description)=
No maillist=
Subject=
To=
Delete=
Add=
Remove=
Name=
To=

View File

@ -40,9 +40,9 @@ function mail.show_drafts(name)
formspec[#formspec + 1] = S("(No subject)")
end
end
if mail.selected_idxs.sent[name] then
if mail.selected_idxs.drafts[name] then
formspec[#formspec + 1] = ";"
formspec[#formspec + 1] = tostring(mail.selected_idxs.sent[name] + 1)
formspec[#formspec + 1] = tostring(mail.selected_idxs.drafts[name] + 1)
end
formspec[#formspec + 1] = "]"
else

View File

@ -17,15 +17,29 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
-- Get player name and handle / convert common input fields
local name = player:get_player_name()
local filter = fields.filter or ""
local filter = fields.filter or mail.selected_idxs.filter[name] or ""
local sortfieldindex = tonumber(fields.sortfield or mail.selected_idxs.sortfield[name]) or 3
local sortdirection = fields.sortdirection or mail.selected_idxs.sortdirection[name] or "1"
local inboxsortfield = ({"from","subject","time"})[sortfieldindex]
local outboxsortfield = ({"to","subject","time"})[sortfieldindex]
-- Be sure that inbox/outbox selected idxs aren't nil
mail.selected_idxs.inbox[name] = mail.selected_idxs.inbox[name] or {}
mail.selected_idxs.sent[name] = mail.selected_idxs.sent[name] or {}
-- Store common player configuration for reuse
mail.selected_idxs.sortfield[name] = sortfieldindex
mail.selected_idxs.sortdirection[name] = sortdirection
mail.selected_idxs.filter[name] = filter
if fields.multipleselection then
mail.selected_idxs.multipleselection[name] = fields.multipleselection == "true"
end
-- Avoid several selected after disabling the multiple selection
if not mail.selected_idxs.multipleselection[name] then
mail.selected_idxs.inbox[name] = { mail.selected_idxs.inbox[name][#mail.selected_idxs.inbox[name]] }
mail.selected_idxs.sent[name] = { mail.selected_idxs.sent[name][#mail.selected_idxs.sent[name]] }
end
-- split inbox and sent msgs for different tests
local entry = mail.get_storage_entry(name)
@ -36,18 +50,60 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
-- Hanmdle formspec event
if fields.inbox then -- inbox table
local evt = minetest.explode_table_event(fields.inbox)
mail.selected_idxs.inbox[name] = evt.row - 1
if evt.type == "DCL" and getInbox()[mail.selected_idxs.inbox[name]] then
mail.show_message(name, getInbox()[mail.selected_idxs.inbox[name]].id)
if mail.selected_idxs.multipleselection[name] then
if not mail.selected_idxs.inbox[name] then
mail.selected_idxs.inbox[name] = {}
end
local selected_id = 0
if mail.selected_idxs.inbox[name] and #mail.selected_idxs.inbox[name] > 0 then
for i, selected_msg in ipairs(mail.selected_idxs.inbox[name]) do
if getInbox()[evt.row-1].id == selected_msg then
selected_id = i
table.remove(mail.selected_idxs.inbox[name], i)
break
end
end
end
if selected_id == 0 then
table.insert(mail.selected_idxs.inbox[name], getInbox()[evt.row-1].id)
end
else
mail.selected_idxs.inbox[name] = { getInbox()[evt.row-1].id }
end
if evt.type == "DCL" and getInbox()[evt.row-1] then
mail.show_message(name, getInbox()[evt.row-1].id)
else
mail.show_mail_menu(name)
end
return true
end
if fields.sent then -- sent table
local evt = minetest.explode_table_event(fields.sent)
mail.selected_idxs.sent[name] = evt.row - 1
if evt.type == "DCL" and getOutbox()[mail.selected_idxs.sent[name]] then
mail.show_message(name, getOutbox()[mail.selected_idxs.sent[name]].id)
if mail.selected_idxs.multipleselection[name] then
if not mail.selected_idxs.sent[name] then
mail.selected_idxs.sent[name] = {}
end
local selected_id = 0
if mail.selected_idxs.sent[name] and #mail.selected_idxs.sent[name] > 0 then
for i, selected_msg in ipairs(mail.selected_idxs.sent[name]) do
if getOutbox()[evt.row-1].id == selected_msg then
selected_id = i
table.remove(mail.selected_idxs.sent[name], i)
break
end
end
end
if selected_id == 0 then
table.insert(mail.selected_idxs.sent[name], getOutbox()[evt.row-1].id)
end
else
mail.selected_idxs.sent[name] = { getOutbox()[evt.row-1].id }
end
if evt.type == "DCL" and getOutbox()[evt.row-1] then
mail.show_message(name, getOutbox()[evt.row-1].id)
else
mail.show_mail_menu(name)
end
return true
end
@ -81,10 +137,10 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
mail.show_drafts(name)
elseif fields.read then
if formname == "mail:inbox" and getInbox()[mail.selected_idxs.inbox[name]] then -- inbox table
mail.show_message(name, getInbox()[mail.selected_idxs.inbox[name]].id)
elseif formname == "mail:sent" and getOutbox()[mail.selected_idxs.sent[name]] then -- sent table
mail.show_message(name, getOutbox()[mail.selected_idxs.sent[name]].id)
if formname == "mail:inbox" and mail.selected_idxs.inbox[name] then -- inbox table
mail.show_message(name, mail.selected_idxs.inbox[name][#mail.selected_idxs.inbox[name]])
elseif formname == "mail:sent" and mail.selected_idxs.sent[name] then -- sent table
mail.show_message(name, mail.selected_idxs.inbox[name][#mail.selected_idxs.inbox[name]])
end
elseif fields.edit then
@ -100,10 +156,14 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end
elseif fields.delete then
if formname == "mail:inbox" and getInbox()[mail.selected_idxs.inbox[name]] then -- inbox table
mail.delete_mail(name, getInbox()[mail.selected_idxs.inbox[name]].id)
elseif formname == "mail:sent" and getOutbox()[mail.selected_idxs.sent[name]] then -- sent table
mail.delete_mail(name, getOutbox()[mail.selected_idxs.sent[name]].id)
if formname == "mail:inbox" and mail.selected_idxs.inbox[name] then -- inbox table
for _, msg_id in ipairs(mail.selected_idxs.inbox[name]) do
mail.delete_mail(name, msg_id)
end
elseif formname == "mail:sent" and mail.selected_idxs.sent[name] then -- sent table
for _, msg_id in ipairs(mail.selected_idxs.sent[name]) do
mail.delete_mail(name, msg_id)
end
elseif formname == "mail:drafts" and messagesDrafts[mail.selected_idxs.drafts[name]] then -- drafts table
mail.delete_mail(name, messagesDrafts[mail.selected_idxs.drafts[name]].id)
end
@ -111,46 +171,46 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
mail.show_mail_menu(name, sortfieldindex, sortdirection, filter)
elseif fields.reply then
if formname == "mail:inbox" and getInbox()[mail.selected_idxs.inbox[name]] then
local message = getInbox()[mail.selected_idxs.inbox[name]]
if formname == "mail:inbox" and mail.selected_idxs.inbox[name] then
local message = mail.get_message(name, mail.selected_idxs.inbox[name][#mail.selected_idxs.inbox[name]])
mail.reply(name, message)
elseif formname == "mail:sent" and getOutbox()[mail.selected_idxs.sent[name]] then
local message = getOutbox()[mail.selected_idxs.sent[name]]
elseif formname == "mail:sent" and mail.selected_idxs.sent[name] then
local message = mail.get_message(name, mail.selected_idxs.sent[name][#mail.selected_idxs.sent[name]])
mail.reply(name, message)
end
elseif fields.replyall then
if formname == "mail:inbox" and getInbox()[mail.selected_idxs.inbox[name]] then
local message = getInbox()[mail.selected_idxs.inbox[name]]
if formname == "mail:inbox" and mail.selected_idxs.inbox[name] then
local message = mail.get_message(name, mail.selected_idxs.inbox[name][#mail.selected_idxs.inbox[name]])
mail.replyall(name, message)
elseif formname == "mail:sent" and getOutbox()[mail.selected_idxs.sent[name]] then
local message = getOutbox()[mail.selected_idxs.sent[name]]
elseif formname == "mail:sent" and mail.selected_idxs.sent[name] then
local message = mail.get_message(name, mail.selected_idxs.sent[name][#mail.selected_idxs.sent[name]])
mail.replyall(name, message)
end
elseif fields.forward then
if formname == "mail:inbox" and getInbox()[mail.selected_idxs.inbox[name]] then
local message = getInbox()[mail.selected_idxs.inbox[name]]
if formname == "mail:inbox" and mail.selected_idxs.inbox[name] then
local message = mail.get_message(name, mail.selected_idxs.inbox[name][#mail.selected_idxs.inbox[name]])
mail.forward(name, message)
elseif formname == "mail:sent" and getOutbox()[mail.selected_idxs.sent[name]] then
local message = getOutbox()[mail.selected_idxs.sent[name]]
elseif formname == "mail:sent" and mail.selected_idxs.sent[name] then
local message = mail.get_message(name, mail.selected_idxs.sent[name][#mail.selected_idxs.sent[name]])
mail.forward(name, message)
end
elseif fields.markread then
if formname == "mail:inbox" and getInbox()[mail.selected_idxs.inbox[name]] then
mail.mark_read(name, getInbox()[mail.selected_idxs.inbox[name]].id)
elseif formname == "mail:sent" and getOutbox()[mail.selected_idxs.sent[name]] then
mail.mark_read(name, getOutbox()[mail.selected_idxs.sent[name]].id)
if formname == "mail:inbox" and mail.selected_idxs.inbox[name] then
for _, msg_id in ipairs(mail.selected_idxs.inbox[name]) do
mail.mark_read(name, msg_id)
end
end
mail.show_mail_menu(name, sortfieldindex, sortdirection, filter)
elseif fields.markunread then
if formname == "mail:inbox" and getInbox()[mail.selected_idxs.inbox[name]] then
mail.mark_unread(name, getInbox()[mail.selected_idxs.inbox[name]].id)
elseif formname == "mail:sent" and getOutbox()[mail.selected_idxs.sent[name]] then
mail.mark_unread(name, getOutbox()[mail.selected_idxs.sent[name]].id)
if formname == "mail:inbox" and mail.selected_idxs.inbox[name] then
for _, msg_id in ipairs(mail.selected_idxs.inbox[name]) do
mail.mark_unread(name, msg_id)
end
end
mail.show_mail_menu(name, sortfieldindex, sortdirection, filter)
@ -167,6 +227,37 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
elseif fields.about then
mail.show_about(name)
elseif fields.selectall then
if formname == "mail:inbox" then
if not mail.selected_idxs.inbox[name] then
mail.selected_idxs.inbox[name] = {}
end
if #mail.selected_idxs.inbox[name] >= #getInbox() then -- if selection is full
mail.selected_idxs.inbox[name] = {}
else
mail.selected_idxs.inbox[name] = {} -- reset to avoid duplicates
mail.selected_idxs.multipleselection[name] = true
for _, msg in ipairs(getInbox()) do
table.insert(mail.selected_idxs.inbox[name], msg.id)
end
end
elseif formname == "mail:sent" then
if not mail.selected_idxs.sent[name] then
mail.selected_idxs.sent[name] = {}
end
if #mail.selected_idxs.sent[name] >= #getOutbox() then -- if selection is full
mail.selected_idxs.sent[name] = {}
else
mail.selected_idxs.inbox[name] = {} -- reset to avoid duplicates
mail.selected_idxs.multipleselection[name] = true
for _, msg in ipairs(getOutbox()) do
table.insert(mail.selected_idxs.sent[name], msg.id)
end
end
end
mail.show_mail_menu(name)
elseif fields.sortfield or fields.sortdirection or fields.filter then
mail.show_mail_menu(name, sortfieldindex, sortdirection, filter)
end

View File

@ -5,7 +5,8 @@ local S = minetest.get_translator("mail")
function mail.show_inbox(name, sortfieldindex, sortdirection, filter)
sortfieldindex = tonumber(sortfieldindex or mail.selected_idxs.sortfield[name]) or 3
sortdirection = sortdirection or mail.selected_idxs.sortdirection[name] or "1"
filter = filter or ""
filter = filter or mail.selected_idxs.filter[name] or ""
mail.selected_idxs.inbox[name] = mail.selected_idxs.inbox[name] or {}
local inbox_formspec = "size[8.5,10;]" .. mail.theme .. [[
tabheader[0.3,1;boxtab;]] .. S("Inbox") .. "," .. S("Sent messages").. "," .. S("Drafts") .. [[;1;false;false]
@ -23,15 +24,20 @@ function mail.show_inbox(name, sortfieldindex, sortdirection, filter)
button[6,8.7;2.5,0.5;about;]] .. S("About") .. [[]
button_exit[6,9.5;2.5,0.5;quit;]] .. S("Close") .. [[]
dropdown[0,9.4;2,0.5;sortfield;]] ..
dropdown[0,8.4;2,0.5;sortfield;]] ..
S("From") .. "," .. S("Subject") .. "," .. S("Date") .. [[;]] .. sortfieldindex .. [[;true]
dropdown[2.0,9.4;2,0.5;sortdirection;]] ..
dropdown[2.0,8.4;2,0.5;sortdirection;]] ..
S("Ascending") .. "," .. S("Descending") .. [[;]] .. sortdirection .. [[;true]
field[4.25,9.85;1.4,0.5;filter;]] .. S("Filter") .. [[:;]] .. filter .. [[]
button[5.14,9.52;0.85,0.5;search;Q]
field[4.25,8.85;1.4,0.5;filter;]] .. S("Filter") .. [[:;]] .. filter .. [[]
button[5.14,8.52;0.85,0.5;search;Q]
checkbox[0,9.1;multipleselection;]] .. S("Allow multiple selection") .. [[;]] ..
tostring(mail.selected_idxs.multipleselection[name]) .. [[]
label[0,9.65;]] .. tostring(#mail.selected_idxs.inbox[name]) .. " " .. S("selected") .. [[]
button[3.5,9.5;2.5,0.5;selectall;]] .. S("(Un)select all") .. [[]
tablecolumns[color;text;text]
table[0,0.7;5.75,8.35;inbox;#999,]] .. S("From") .. "," .. S("Subject")
table[0,0.7;5.75,7.35;inbox;#999,]] .. S("From") .. "," .. S("Subject")
local formspec = { inbox_formspec }
local entry = mail.get_storage_entry(name)
local sortfield = ({"from","subject","time"})[sortfieldindex]
@ -41,6 +47,31 @@ function mail.show_inbox(name, sortfieldindex, sortdirection, filter)
if #messages > 0 then
for _, message in ipairs(messages) do
local selected_id = 0
-- check if message is in selection list and return its id
if mail.selected_idxs.inbox[name] and #mail.selected_idxs.inbox[name] > 0 then
for i, selected_msg in ipairs(mail.selected_idxs.inbox[name]) do
if message.id == selected_msg then
selected_id = i
break
end
end
end
if selected_id > 0 then
if not message.read then
if not mail.player_in_list(name, message.to) then
formspec[#formspec + 1] = ",#A39E5D"
else
formspec[#formspec + 1] = ",#A39E19"
end
else
if not mail.player_in_list(name, message.to) then
formspec[#formspec + 1] = ",#899888"
else
formspec[#formspec + 1] = ",#466432"
end
end
else
if not message.read then
if not mail.player_in_list(name, message.to) then
formspec[#formspec + 1] = ",#FFD788"
@ -54,6 +85,7 @@ function mail.show_inbox(name, sortfieldindex, sortdirection, filter)
formspec[#formspec + 1] = ","
end
end
end
formspec[#formspec + 1] = ","
formspec[#formspec + 1] = minetest.formspec_escape(message.from)
formspec[#formspec + 1] = ","
@ -68,10 +100,6 @@ function mail.show_inbox(name, sortfieldindex, sortdirection, filter)
formspec[#formspec + 1] = S("(No subject)")
end
end
if mail.selected_idxs.inbox[name] then
formspec[#formspec + 1] = ";"
formspec[#formspec + 1] = tostring(mail.selected_idxs.inbox[name] + 1)
end
formspec[#formspec + 1] = "]"
else
formspec[#formspec + 1] = "]label[2.25,4.5;" .. S("No mail") .. "]"

View File

@ -90,10 +90,6 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end
local name = player:get_player_name()
local entry = mail.get_storage_entry(name)
local messagesInbox = entry.inbox
local messagesSent = entry.outbox
if fields.back then
mail.show_mail_menu(name)
@ -101,36 +97,36 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
elseif fields.reply then
local message = ""
if messagesInbox[mail.selected_idxs.inbox[name]] then
message = messagesInbox[mail.selected_idxs.inbox[name]]
elseif messagesSent[mail.selected_idxs.sent[name]] then
message = messagesSent[mail.selected_idxs.sent[name]]
if mail.selected_idxs.inbox[name] then
message = mail.get_message(name, mail.selected_idxs.inbox[name][#mail.selected_idxs.inbox[name]])
elseif mail.selected_idxs.sent[name] then
message = mail.get_message(name, mail.selected_idxs.sent[name][#mail.selected_idxs.sent[name]])
end
mail.reply(name, message)
elseif fields.replyall then
local message = ""
if messagesInbox[mail.selected_idxs.inbox[name]] then
message = messagesInbox[mail.selected_idxs.inbox[name]]
elseif messagesSent[mail.selected_idxs.sent[name]] then
message = messagesSent[mail.selected_idxs.sent[name]]
if mail.selected_idxs.inbox[name] then
message = mail.get_message(name, mail.selected_idxs.inbox[name][#mail.selected_idxs.inbox[name]])
elseif mail.selected_idxs.sent[name] then
message = mail.get_message(name, mail.selected_idxs.sent[name][#mail.selected_idxs.sent[name]])
end
mail.replyall(name, message)
elseif fields.forward then
local message = ""
if messagesInbox[mail.selected_idxs.inbox[name]] then
message = messagesInbox[mail.selected_idxs.inbox[name]]
elseif messagesSent[mail.selected_idxs.sent[name]] then
message = messagesSent[mail.selected_idxs.sent[name]]
if mail.selected_idxs.inbox[name] then
message = mail.get_message(name, mail.selected_idxs.inbox[name][#mail.selected_idxs.inbox[name]])
elseif mail.selected_idxs.sent[name] then
message = mail.get_message(name, mail.selected_idxs.sent[name][#mail.selected_idxs.sent[name]])
end
mail.forward(name, message)
elseif fields.delete then
if messagesInbox[mail.selected_idxs.inbox[name]] then
mail.delete_mail(name, messagesInbox[mail.selected_idxs.inbox[name]].id)
elseif messagesSent[mail.selected_idxs.sent[name]] then
mail.delete_mail(name, messagesSent[mail.selected_idxs.sent[name]].id)
if mail.selected_idxs.inbox[name] then
mail.delete_mail(name, mail.selected_idxs.inbox[name][#mail.selected_idxs.inbox[name]])
elseif mail.selected_idxs.sent[name] then
mail.delete_mail(name, mail.selected_idxs.sent[name][#mail.selected_idxs.sent[name]])
end
mail.show_mail_menu(name)
end

View File

@ -5,7 +5,8 @@ local S = minetest.get_translator("mail")
function mail.show_sent(name, sortfieldindex, sortdirection, filter)
sortfieldindex = tonumber(sortfieldindex or mail.selected_idxs.sortfield[name]) or 3
sortdirection = sortdirection or mail.selected_idxs.sortdirection[name] or "1"
filter = filter or ""
filter = filter or mail.selected_idxs.filter[name] or ""
mail.selected_idxs.sent[name] = mail.selected_idxs.sent[name] or {}
local sent_formspec = "size[8.5,10;]" .. mail.theme .. [[
tabheader[0.3,1;boxtab;]] .. S("Inbox") .. "," .. S("Sent messages").. "," .. S("Drafts") .. [[;2;false;false]
@ -21,15 +22,20 @@ function mail.show_sent(name, sortfieldindex, sortdirection, filter)
button[6,8.7;2.5,0.5;about;]] .. S("About") .. [[]
button_exit[6,9.5;2.5,0.5;quit;]] .. S("Close") .. [[]
dropdown[0,9.4;2,0.5;sortfield;]]
.. S("To") .. "," .. S("Subject") .. "," .. S("Date") .. [[;]] .. sortfieldindex .. [[;1]
dropdown[2.0,9.4;2,0.5;sortdirection;]]
.. S("Ascending") .. "," .. S("Descending") .. [[;]] .. sortdirection .. [[;1]
field[4.25,9.85;1.4,0.5;filter;]].. S("Filter") .. [[:;]] .. filter .. [[]
button[5.14,9.52;0.85,0.5;search;Q]
dropdown[0,8.4;2,0.5;sortfield;]] ..
S("To") .. "," .. S("Subject") .. "," .. S("Date") .. [[;]] .. sortfieldindex .. [[;true]
dropdown[2.0,8.4;2,0.5;sortdirection;]] ..
S("Ascending") .. "," .. S("Descending") .. [[;]] .. sortdirection .. [[;true]
field[4.25,8.85;1.4,0.5;filter;]] .. S("Filter") .. [[:;]] .. filter .. [[]
button[5.14,8.52;0.85,0.5;search;Q]
checkbox[0,9.1;multipleselection;]] .. S("Allow multiple selection") .. [[;]] ..
tostring(mail.selected_idxs.multipleselection[name]) .. [[]
label[0,9.65;]] .. tostring(#mail.selected_idxs.sent[name]) .. " " .. S("selected") .. [[]
button[3.5,9.5;2.5,0.5;selectall;]] .. S("(Un)select all") .. [[]
tablecolumns[color;text;text]
table[0,0.7;5.75,8.35;sent;#999,]] .. S("To") .. "," .. S("Subject")
table[0,0.7;5.75,7.35;sent;#999,]] .. S("To") .. "," .. S("Subject")
local formspec = { sent_formspec }
local entry = mail.get_storage_entry(name)
local sortfield = ({"to","subject","time"})[sortfieldindex]
@ -39,7 +45,21 @@ function mail.show_sent(name, sortfieldindex, sortdirection, filter)
if #messages > 0 then
for _, message in ipairs(messages) do
local selected_id = 0
-- check if message is in selection list and return its id
if mail.selected_idxs.sent[name] and #mail.selected_idxs.sent[name] > 0 then
for i, selected_msg in ipairs(mail.selected_idxs.sent[name]) do
if message.id == selected_msg then
selected_id = i
break
end
end
end
if selected_id > 0 then
formspec[#formspec + 1] = ",#466432"
else
formspec[#formspec + 1] = ","
end
formspec[#formspec + 1] = ","
formspec[#formspec + 1] = minetest.formspec_escape(message.to)
formspec[#formspec + 1] = ","
@ -54,10 +74,6 @@ function mail.show_sent(name, sortfieldindex, sortdirection, filter)
formspec[#formspec + 1] = S("(No subject)")
end
end
if mail.selected_idxs.sent[name] then
formspec[#formspec + 1] = ";"
formspec[#formspec + 1] = tostring(mail.selected_idxs.sent[name] + 1)
end
formspec[#formspec + 1] = "]"
else
formspec[#formspec + 1] = "]label[2.25,4.5;" .. S("No mail") .. "]"