mirror of
https://github.com/mt-mods/mail.git
synced 2025-07-05 14:10:31 -04:00
fix some things, adjust GUI elements
- messages are now actually sent (bug in parse player list) - no more crashes on sending mail (forgot to make variables local) - actually handle CC and BCC fields instead of leaving them empty, duh - make new functions be under the mail namespace - add util functions to ensure the new format, parse and player list as well as checking whether a player is in that list or not - rearrange some GUI elements (tighter spacing, grouping, increase window height to be consistent) - convert mails to new format only as needed (old mails stay intact in case someone reverts to old version) - mails are shaded differently in inbox, depending on whether the player is in the TO field - FROM, TO and CC fields are all displayed when reading a mail - add "Reply All" button (TO includes all original recipients plus the sender, but excluding the player himself, while adopting the CC field. To contrast: "Reply" just sets the original sender as TO and leaves the rest empty) - move reply, replyall and forward to their own functions in GUI (was duplicated for inbox and show mail) - don't needlessly set messages table when we do nothing but go back
This commit is contained in:
parent
f5f21feb49
commit
ea0de708da
3 changed files with 150 additions and 54 deletions
|
@ -2,7 +2,18 @@
|
|||
return the field normalized (comma separated, single space)
|
||||
and add individual player names to recipient list
|
||||
--]]
|
||||
function normalize_players_and_add_recipients(field, recipients)
|
||||
function mail.normalize_players_and_add_recipients(field, recipients)
|
||||
local order = mail.parse_player_list(field)
|
||||
for i,c in ipairs(order) do
|
||||
if recipients[string.lower(c)] == nil then
|
||||
recipients[string.lower(c)] = c
|
||||
end
|
||||
end
|
||||
return mail.concat_player_list(order)
|
||||
end
|
||||
|
||||
|
||||
function mail.parse_player_list(field)
|
||||
local separator = ", "
|
||||
local pattern = "([^" .. separator .. "]+)"
|
||||
|
||||
|
@ -10,17 +21,36 @@ function normalize_players_and_add_recipients(field, recipients)
|
|||
local player_set = {}
|
||||
local order = {}
|
||||
field:gsub(pattern, function(c)
|
||||
if player_set[string.lower(c)] ~= nil then
|
||||
if player_set[string.lower(c)] == nil then
|
||||
player_set[string.lower(c)] = c
|
||||
order[#order+1] = c
|
||||
|
||||
-- also sort into recipients
|
||||
if recipients[string.lower(c)] ~= nil then
|
||||
recipients[string.lower(c)] = c
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
return order
|
||||
end
|
||||
|
||||
function mail.concat_player_list(order)
|
||||
-- turn list of players back into normalized string
|
||||
return table.concat(order, ", ")
|
||||
end
|
||||
|
||||
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
|
||||
if name == c then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
function mail.ensure_new_format(message)
|
||||
if message.sender then
|
||||
message.from = message.sender
|
||||
message.to = name
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue