mail/storage.lua

493 lines
12 KiB
Lua
Raw Normal View History

View sent messages (new database, add maillists) (#26) * Add tabheader & sent formspec * Add show_sent function and show sent messages * Remove comment on selected_idxs test (show_sent) * Add variable to keep the previous tab instead of going back to the first one * Remove index variable verification on mark read/unread buttons since they are necessarily clicked on inbox view * Resize messages table to be aligned with close button at the bottom * Show date time (#27) * Show date in message reading * Fix wrong registered dates Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Rework header layout to add better space for date --------- Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Add insertion of messages into global storage mail.messages.json * Receive player messages from global storage * Add automatic generation of status for a new message (unread) * Mark read/unread/delete a message * Fix messages loading * Show every message received/sent via specific functions * Use global contacts functions and reconfigure add/remove functions * Create mail lists formspec based on contacts * Add deleting contact * Add ability to create mail lists * Fix inability to edit contact * Rework on editing/deletion of contacts/maillists * Add at symbol as prefix on maillists view * Add ability to choose default status (to/cc/bcc) Signed-off-by: Athozus <athozus@gmail.com> * Add ability to add multiples players and choose their default status (to/cc/bcc) * Add ability to use maillist in messages and receive messages from them * Fix repetition of code causing a crash * Avoid multiples occurences of the same messages due to player both in maillist and receivers * Fix selected indexes for inbox/sent Now separated, fixed show_message() func selection of id from table dcl/read btn * Fix many issues related to maillists Notably : edit, delete, selection, creation, registration of players * Set up database version v3 and its migration from v2 + Check versions to choose v1->v2 or v2->v3 * Fix mtt.lua Due to old function getMessages(), replaced by getPlayerInboxMessages() * Add 10 seconds security to mtt.lua * Fix migrate.lua non-declared variable * Send msg table with string keys in mtt * Better log messages * Add message check * Fix mtt crash * Better syntax in storage.lua * Fix bcc forgotten in mail.send() * Fix mtt issue * Better compatibility for messages storage Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Replace mail.split by builtin func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func in storage.lua * re-add mtt if * luacheck on PR * add check for an ancient issue with missing `to` field * Fix luacheck on storage.lua * Fix luacheck warnings in migrate.lua * Fix luacheck warnings in gui.lua * Fix luacheck (too long lines) in storage.lua * Unused loop values in migrate.lua * Whitespace line in gui.lua * Whitespace line (init.lua) * Whitespace line (api.lua) * Significantly improve maillist behaviour Replace maillist by its players when sending a message List of players separated by , Avoid doublons when editing more than 2 times a maillist * Fix luacheck * Fix table insertions at first index when no needed * Use funcs * Do not add maillist as a new contact when sending a mail * Fix removing elements from tables * Check maillists not added in contacts * storage rewrite wip * storage format docs * refactor ui components * show_compose cleanup * remove unused channel.lua * error -> err * status refactoring * contacts refactoring * maillist refactoring * docs * tests * fix some issues * re-enable migrations * contributors * prefix mail entries in the mod storage * internalize old mail-paths to migration module * add v1 and v2 player db examples and migration test * Ui improvements & fixes Move events code (if fields.x then) to events.lua (instead of inbox.lua), fix tab selection when going backward * Show most recent messages at first (outbox) * unified-inv fix --------- Signed-off-by: Athozus <athozus@gmail.com> Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> Co-authored-by: BuckarooBanzay <BuckarooBanzay@users.noreply.github.com>
2023-03-29 18:25:01 +03:00
-- storage getter/setter
local STORAGE_PREFIX = "mail/"
2019-09-16 09:06:54 +03:00
View sent messages (new database, add maillists) (#26) * Add tabheader & sent formspec * Add show_sent function and show sent messages * Remove comment on selected_idxs test (show_sent) * Add variable to keep the previous tab instead of going back to the first one * Remove index variable verification on mark read/unread buttons since they are necessarily clicked on inbox view * Resize messages table to be aligned with close button at the bottom * Show date time (#27) * Show date in message reading * Fix wrong registered dates Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Rework header layout to add better space for date --------- Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Add insertion of messages into global storage mail.messages.json * Receive player messages from global storage * Add automatic generation of status for a new message (unread) * Mark read/unread/delete a message * Fix messages loading * Show every message received/sent via specific functions * Use global contacts functions and reconfigure add/remove functions * Create mail lists formspec based on contacts * Add deleting contact * Add ability to create mail lists * Fix inability to edit contact * Rework on editing/deletion of contacts/maillists * Add at symbol as prefix on maillists view * Add ability to choose default status (to/cc/bcc) Signed-off-by: Athozus <athozus@gmail.com> * Add ability to add multiples players and choose their default status (to/cc/bcc) * Add ability to use maillist in messages and receive messages from them * Fix repetition of code causing a crash * Avoid multiples occurences of the same messages due to player both in maillist and receivers * Fix selected indexes for inbox/sent Now separated, fixed show_message() func selection of id from table dcl/read btn * Fix many issues related to maillists Notably : edit, delete, selection, creation, registration of players * Set up database version v3 and its migration from v2 + Check versions to choose v1->v2 or v2->v3 * Fix mtt.lua Due to old function getMessages(), replaced by getPlayerInboxMessages() * Add 10 seconds security to mtt.lua * Fix migrate.lua non-declared variable * Send msg table with string keys in mtt * Better log messages * Add message check * Fix mtt crash * Better syntax in storage.lua * Fix bcc forgotten in mail.send() * Fix mtt issue * Better compatibility for messages storage Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Replace mail.split by builtin func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func in storage.lua * re-add mtt if * luacheck on PR * add check for an ancient issue with missing `to` field * Fix luacheck on storage.lua * Fix luacheck warnings in migrate.lua * Fix luacheck warnings in gui.lua * Fix luacheck (too long lines) in storage.lua * Unused loop values in migrate.lua * Whitespace line in gui.lua * Whitespace line (init.lua) * Whitespace line (api.lua) * Significantly improve maillist behaviour Replace maillist by its players when sending a message List of players separated by , Avoid doublons when editing more than 2 times a maillist * Fix luacheck * Fix table insertions at first index when no needed * Use funcs * Do not add maillist as a new contact when sending a mail * Fix removing elements from tables * Check maillists not added in contacts * storage rewrite wip * storage format docs * refactor ui components * show_compose cleanup * remove unused channel.lua * error -> err * status refactoring * contacts refactoring * maillist refactoring * docs * tests * fix some issues * re-enable migrations * contributors * prefix mail entries in the mod storage * internalize old mail-paths to migration module * add v1 and v2 player db examples and migration test * Ui improvements & fixes Move events code (if fields.x then) to events.lua (instead of inbox.lua), fix tab selection when going backward * Show most recent messages at first (outbox) * unified-inv fix --------- Signed-off-by: Athozus <athozus@gmail.com> Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> Co-authored-by: BuckarooBanzay <BuckarooBanzay@users.noreply.github.com>
2023-03-29 18:25:01 +03:00
-- create or populate empty fields on an entry
local function populate_entry(e)
e = e or {}
e.contacts = e.contacts or {}
e.inbox = e.inbox or {}
e.outbox = e.outbox or {}
e.drafts = e.drafts or {}
e.trash = e.trash or {}
View sent messages (new database, add maillists) (#26) * Add tabheader & sent formspec * Add show_sent function and show sent messages * Remove comment on selected_idxs test (show_sent) * Add variable to keep the previous tab instead of going back to the first one * Remove index variable verification on mark read/unread buttons since they are necessarily clicked on inbox view * Resize messages table to be aligned with close button at the bottom * Show date time (#27) * Show date in message reading * Fix wrong registered dates Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Rework header layout to add better space for date --------- Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Add insertion of messages into global storage mail.messages.json * Receive player messages from global storage * Add automatic generation of status for a new message (unread) * Mark read/unread/delete a message * Fix messages loading * Show every message received/sent via specific functions * Use global contacts functions and reconfigure add/remove functions * Create mail lists formspec based on contacts * Add deleting contact * Add ability to create mail lists * Fix inability to edit contact * Rework on editing/deletion of contacts/maillists * Add at symbol as prefix on maillists view * Add ability to choose default status (to/cc/bcc) Signed-off-by: Athozus <athozus@gmail.com> * Add ability to add multiples players and choose their default status (to/cc/bcc) * Add ability to use maillist in messages and receive messages from them * Fix repetition of code causing a crash * Avoid multiples occurences of the same messages due to player both in maillist and receivers * Fix selected indexes for inbox/sent Now separated, fixed show_message() func selection of id from table dcl/read btn * Fix many issues related to maillists Notably : edit, delete, selection, creation, registration of players * Set up database version v3 and its migration from v2 + Check versions to choose v1->v2 or v2->v3 * Fix mtt.lua Due to old function getMessages(), replaced by getPlayerInboxMessages() * Add 10 seconds security to mtt.lua * Fix migrate.lua non-declared variable * Send msg table with string keys in mtt * Better log messages * Add message check * Fix mtt crash * Better syntax in storage.lua * Fix bcc forgotten in mail.send() * Fix mtt issue * Better compatibility for messages storage Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Replace mail.split by builtin func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func in storage.lua * re-add mtt if * luacheck on PR * add check for an ancient issue with missing `to` field * Fix luacheck on storage.lua * Fix luacheck warnings in migrate.lua * Fix luacheck warnings in gui.lua * Fix luacheck (too long lines) in storage.lua * Unused loop values in migrate.lua * Whitespace line in gui.lua * Whitespace line (init.lua) * Whitespace line (api.lua) * Significantly improve maillist behaviour Replace maillist by its players when sending a message List of players separated by , Avoid doublons when editing more than 2 times a maillist * Fix luacheck * Fix table insertions at first index when no needed * Use funcs * Do not add maillist as a new contact when sending a mail * Fix removing elements from tables * Check maillists not added in contacts * storage rewrite wip * storage format docs * refactor ui components * show_compose cleanup * remove unused channel.lua * error -> err * status refactoring * contacts refactoring * maillist refactoring * docs * tests * fix some issues * re-enable migrations * contributors * prefix mail entries in the mod storage * internalize old mail-paths to migration module * add v1 and v2 player db examples and migration test * Ui improvements & fixes Move events code (if fields.x then) to events.lua (instead of inbox.lua), fix tab selection when going backward * Show most recent messages at first (outbox) * unified-inv fix --------- Signed-off-by: Athozus <athozus@gmail.com> Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> Co-authored-by: BuckarooBanzay <BuckarooBanzay@users.noreply.github.com>
2023-03-29 18:25:01 +03:00
e.lists = e.lists or {}
e.settings = e.settings or {}
View sent messages (new database, add maillists) (#26) * Add tabheader & sent formspec * Add show_sent function and show sent messages * Remove comment on selected_idxs test (show_sent) * Add variable to keep the previous tab instead of going back to the first one * Remove index variable verification on mark read/unread buttons since they are necessarily clicked on inbox view * Resize messages table to be aligned with close button at the bottom * Show date time (#27) * Show date in message reading * Fix wrong registered dates Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Rework header layout to add better space for date --------- Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Add insertion of messages into global storage mail.messages.json * Receive player messages from global storage * Add automatic generation of status for a new message (unread) * Mark read/unread/delete a message * Fix messages loading * Show every message received/sent via specific functions * Use global contacts functions and reconfigure add/remove functions * Create mail lists formspec based on contacts * Add deleting contact * Add ability to create mail lists * Fix inability to edit contact * Rework on editing/deletion of contacts/maillists * Add at symbol as prefix on maillists view * Add ability to choose default status (to/cc/bcc) Signed-off-by: Athozus <athozus@gmail.com> * Add ability to add multiples players and choose their default status (to/cc/bcc) * Add ability to use maillist in messages and receive messages from them * Fix repetition of code causing a crash * Avoid multiples occurences of the same messages due to player both in maillist and receivers * Fix selected indexes for inbox/sent Now separated, fixed show_message() func selection of id from table dcl/read btn * Fix many issues related to maillists Notably : edit, delete, selection, creation, registration of players * Set up database version v3 and its migration from v2 + Check versions to choose v1->v2 or v2->v3 * Fix mtt.lua Due to old function getMessages(), replaced by getPlayerInboxMessages() * Add 10 seconds security to mtt.lua * Fix migrate.lua non-declared variable * Send msg table with string keys in mtt * Better log messages * Add message check * Fix mtt crash * Better syntax in storage.lua * Fix bcc forgotten in mail.send() * Fix mtt issue * Better compatibility for messages storage Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Replace mail.split by builtin func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func in storage.lua * re-add mtt if * luacheck on PR * add check for an ancient issue with missing `to` field * Fix luacheck on storage.lua * Fix luacheck warnings in migrate.lua * Fix luacheck warnings in gui.lua * Fix luacheck (too long lines) in storage.lua * Unused loop values in migrate.lua * Whitespace line in gui.lua * Whitespace line (init.lua) * Whitespace line (api.lua) * Significantly improve maillist behaviour Replace maillist by its players when sending a message List of players separated by , Avoid doublons when editing more than 2 times a maillist * Fix luacheck * Fix table insertions at first index when no needed * Use funcs * Do not add maillist as a new contact when sending a mail * Fix removing elements from tables * Check maillists not added in contacts * storage rewrite wip * storage format docs * refactor ui components * show_compose cleanup * remove unused channel.lua * error -> err * status refactoring * contacts refactoring * maillist refactoring * docs * tests * fix some issues * re-enable migrations * contributors * prefix mail entries in the mod storage * internalize old mail-paths to migration module * add v1 and v2 player db examples and migration test * Ui improvements & fixes Move events code (if fields.x then) to events.lua (instead of inbox.lua), fix tab selection when going backward * Show most recent messages at first (outbox) * unified-inv fix --------- Signed-off-by: Athozus <athozus@gmail.com> Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> Co-authored-by: BuckarooBanzay <BuckarooBanzay@users.noreply.github.com>
2023-03-29 18:25:01 +03:00
return e
2019-09-16 09:06:54 +03:00
end
local cache = {}
-- retrieve the storage entry for the player
View sent messages (new database, add maillists) (#26) * Add tabheader & sent formspec * Add show_sent function and show sent messages * Remove comment on selected_idxs test (show_sent) * Add variable to keep the previous tab instead of going back to the first one * Remove index variable verification on mark read/unread buttons since they are necessarily clicked on inbox view * Resize messages table to be aligned with close button at the bottom * Show date time (#27) * Show date in message reading * Fix wrong registered dates Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Rework header layout to add better space for date --------- Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Add insertion of messages into global storage mail.messages.json * Receive player messages from global storage * Add automatic generation of status for a new message (unread) * Mark read/unread/delete a message * Fix messages loading * Show every message received/sent via specific functions * Use global contacts functions and reconfigure add/remove functions * Create mail lists formspec based on contacts * Add deleting contact * Add ability to create mail lists * Fix inability to edit contact * Rework on editing/deletion of contacts/maillists * Add at symbol as prefix on maillists view * Add ability to choose default status (to/cc/bcc) Signed-off-by: Athozus <athozus@gmail.com> * Add ability to add multiples players and choose their default status (to/cc/bcc) * Add ability to use maillist in messages and receive messages from them * Fix repetition of code causing a crash * Avoid multiples occurences of the same messages due to player both in maillist and receivers * Fix selected indexes for inbox/sent Now separated, fixed show_message() func selection of id from table dcl/read btn * Fix many issues related to maillists Notably : edit, delete, selection, creation, registration of players * Set up database version v3 and its migration from v2 + Check versions to choose v1->v2 or v2->v3 * Fix mtt.lua Due to old function getMessages(), replaced by getPlayerInboxMessages() * Add 10 seconds security to mtt.lua * Fix migrate.lua non-declared variable * Send msg table with string keys in mtt * Better log messages * Add message check * Fix mtt crash * Better syntax in storage.lua * Fix bcc forgotten in mail.send() * Fix mtt issue * Better compatibility for messages storage Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Replace mail.split by builtin func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func in storage.lua * re-add mtt if * luacheck on PR * add check for an ancient issue with missing `to` field * Fix luacheck on storage.lua * Fix luacheck warnings in migrate.lua * Fix luacheck warnings in gui.lua * Fix luacheck (too long lines) in storage.lua * Unused loop values in migrate.lua * Whitespace line in gui.lua * Whitespace line (init.lua) * Whitespace line (api.lua) * Significantly improve maillist behaviour Replace maillist by its players when sending a message List of players separated by , Avoid doublons when editing more than 2 times a maillist * Fix luacheck * Fix table insertions at first index when no needed * Use funcs * Do not add maillist as a new contact when sending a mail * Fix removing elements from tables * Check maillists not added in contacts * storage rewrite wip * storage format docs * refactor ui components * show_compose cleanup * remove unused channel.lua * error -> err * status refactoring * contacts refactoring * maillist refactoring * docs * tests * fix some issues * re-enable migrations * contributors * prefix mail entries in the mod storage * internalize old mail-paths to migration module * add v1 and v2 player db examples and migration test * Ui improvements & fixes Move events code (if fields.x then) to events.lua (instead of inbox.lua), fix tab selection when going backward * Show most recent messages at first (outbox) * unified-inv fix --------- Signed-off-by: Athozus <athozus@gmail.com> Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> Co-authored-by: BuckarooBanzay <BuckarooBanzay@users.noreply.github.com>
2023-03-29 18:25:01 +03:00
function mail.get_storage_entry(playername)
local key = STORAGE_PREFIX .. playername
if cache[key] then
-- use cached entry
return cache[key]
end
local str = mail.storage:get_string(key)
local entry
View sent messages (new database, add maillists) (#26) * Add tabheader & sent formspec * Add show_sent function and show sent messages * Remove comment on selected_idxs test (show_sent) * Add variable to keep the previous tab instead of going back to the first one * Remove index variable verification on mark read/unread buttons since they are necessarily clicked on inbox view * Resize messages table to be aligned with close button at the bottom * Show date time (#27) * Show date in message reading * Fix wrong registered dates Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Rework header layout to add better space for date --------- Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Add insertion of messages into global storage mail.messages.json * Receive player messages from global storage * Add automatic generation of status for a new message (unread) * Mark read/unread/delete a message * Fix messages loading * Show every message received/sent via specific functions * Use global contacts functions and reconfigure add/remove functions * Create mail lists formspec based on contacts * Add deleting contact * Add ability to create mail lists * Fix inability to edit contact * Rework on editing/deletion of contacts/maillists * Add at symbol as prefix on maillists view * Add ability to choose default status (to/cc/bcc) Signed-off-by: Athozus <athozus@gmail.com> * Add ability to add multiples players and choose their default status (to/cc/bcc) * Add ability to use maillist in messages and receive messages from them * Fix repetition of code causing a crash * Avoid multiples occurences of the same messages due to player both in maillist and receivers * Fix selected indexes for inbox/sent Now separated, fixed show_message() func selection of id from table dcl/read btn * Fix many issues related to maillists Notably : edit, delete, selection, creation, registration of players * Set up database version v3 and its migration from v2 + Check versions to choose v1->v2 or v2->v3 * Fix mtt.lua Due to old function getMessages(), replaced by getPlayerInboxMessages() * Add 10 seconds security to mtt.lua * Fix migrate.lua non-declared variable * Send msg table with string keys in mtt * Better log messages * Add message check * Fix mtt crash * Better syntax in storage.lua * Fix bcc forgotten in mail.send() * Fix mtt issue * Better compatibility for messages storage Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Replace mail.split by builtin func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func in storage.lua * re-add mtt if * luacheck on PR * add check for an ancient issue with missing `to` field * Fix luacheck on storage.lua * Fix luacheck warnings in migrate.lua * Fix luacheck warnings in gui.lua * Fix luacheck (too long lines) in storage.lua * Unused loop values in migrate.lua * Whitespace line in gui.lua * Whitespace line (init.lua) * Whitespace line (api.lua) * Significantly improve maillist behaviour Replace maillist by its players when sending a message List of players separated by , Avoid doublons when editing more than 2 times a maillist * Fix luacheck * Fix table insertions at first index when no needed * Use funcs * Do not add maillist as a new contact when sending a mail * Fix removing elements from tables * Check maillists not added in contacts * storage rewrite wip * storage format docs * refactor ui components * show_compose cleanup * remove unused channel.lua * error -> err * status refactoring * contacts refactoring * maillist refactoring * docs * tests * fix some issues * re-enable migrations * contributors * prefix mail entries in the mod storage * internalize old mail-paths to migration module * add v1 and v2 player db examples and migration test * Ui improvements & fixes Move events code (if fields.x then) to events.lua (instead of inbox.lua), fix tab selection when going backward * Show most recent messages at first (outbox) * unified-inv fix --------- Signed-off-by: Athozus <athozus@gmail.com> Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> Co-authored-by: BuckarooBanzay <BuckarooBanzay@users.noreply.github.com>
2023-03-29 18:25:01 +03:00
if str == "" then
-- new entry
entry = populate_entry()
View sent messages (new database, add maillists) (#26) * Add tabheader & sent formspec * Add show_sent function and show sent messages * Remove comment on selected_idxs test (show_sent) * Add variable to keep the previous tab instead of going back to the first one * Remove index variable verification on mark read/unread buttons since they are necessarily clicked on inbox view * Resize messages table to be aligned with close button at the bottom * Show date time (#27) * Show date in message reading * Fix wrong registered dates Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Rework header layout to add better space for date --------- Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Add insertion of messages into global storage mail.messages.json * Receive player messages from global storage * Add automatic generation of status for a new message (unread) * Mark read/unread/delete a message * Fix messages loading * Show every message received/sent via specific functions * Use global contacts functions and reconfigure add/remove functions * Create mail lists formspec based on contacts * Add deleting contact * Add ability to create mail lists * Fix inability to edit contact * Rework on editing/deletion of contacts/maillists * Add at symbol as prefix on maillists view * Add ability to choose default status (to/cc/bcc) Signed-off-by: Athozus <athozus@gmail.com> * Add ability to add multiples players and choose their default status (to/cc/bcc) * Add ability to use maillist in messages and receive messages from them * Fix repetition of code causing a crash * Avoid multiples occurences of the same messages due to player both in maillist and receivers * Fix selected indexes for inbox/sent Now separated, fixed show_message() func selection of id from table dcl/read btn * Fix many issues related to maillists Notably : edit, delete, selection, creation, registration of players * Set up database version v3 and its migration from v2 + Check versions to choose v1->v2 or v2->v3 * Fix mtt.lua Due to old function getMessages(), replaced by getPlayerInboxMessages() * Add 10 seconds security to mtt.lua * Fix migrate.lua non-declared variable * Send msg table with string keys in mtt * Better log messages * Add message check * Fix mtt crash * Better syntax in storage.lua * Fix bcc forgotten in mail.send() * Fix mtt issue * Better compatibility for messages storage Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Replace mail.split by builtin func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func in storage.lua * re-add mtt if * luacheck on PR * add check for an ancient issue with missing `to` field * Fix luacheck on storage.lua * Fix luacheck warnings in migrate.lua * Fix luacheck warnings in gui.lua * Fix luacheck (too long lines) in storage.lua * Unused loop values in migrate.lua * Whitespace line in gui.lua * Whitespace line (init.lua) * Whitespace line (api.lua) * Significantly improve maillist behaviour Replace maillist by its players when sending a message List of players separated by , Avoid doublons when editing more than 2 times a maillist * Fix luacheck * Fix table insertions at first index when no needed * Use funcs * Do not add maillist as a new contact when sending a mail * Fix removing elements from tables * Check maillists not added in contacts * storage rewrite wip * storage format docs * refactor ui components * show_compose cleanup * remove unused channel.lua * error -> err * status refactoring * contacts refactoring * maillist refactoring * docs * tests * fix some issues * re-enable migrations * contributors * prefix mail entries in the mod storage * internalize old mail-paths to migration module * add v1 and v2 player db examples and migration test * Ui improvements & fixes Move events code (if fields.x then) to events.lua (instead of inbox.lua), fix tab selection when going backward * Show most recent messages at first (outbox) * unified-inv fix --------- Signed-off-by: Athozus <athozus@gmail.com> Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> Co-authored-by: BuckarooBanzay <BuckarooBanzay@users.noreply.github.com>
2023-03-29 18:25:01 +03:00
else
-- deserialize existing entry
local e = minetest.parse_json(str)
entry = populate_entry(e)
View sent messages (new database, add maillists) (#26) * Add tabheader & sent formspec * Add show_sent function and show sent messages * Remove comment on selected_idxs test (show_sent) * Add variable to keep the previous tab instead of going back to the first one * Remove index variable verification on mark read/unread buttons since they are necessarily clicked on inbox view * Resize messages table to be aligned with close button at the bottom * Show date time (#27) * Show date in message reading * Fix wrong registered dates Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Rework header layout to add better space for date --------- Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Add insertion of messages into global storage mail.messages.json * Receive player messages from global storage * Add automatic generation of status for a new message (unread) * Mark read/unread/delete a message * Fix messages loading * Show every message received/sent via specific functions * Use global contacts functions and reconfigure add/remove functions * Create mail lists formspec based on contacts * Add deleting contact * Add ability to create mail lists * Fix inability to edit contact * Rework on editing/deletion of contacts/maillists * Add at symbol as prefix on maillists view * Add ability to choose default status (to/cc/bcc) Signed-off-by: Athozus <athozus@gmail.com> * Add ability to add multiples players and choose their default status (to/cc/bcc) * Add ability to use maillist in messages and receive messages from them * Fix repetition of code causing a crash * Avoid multiples occurences of the same messages due to player both in maillist and receivers * Fix selected indexes for inbox/sent Now separated, fixed show_message() func selection of id from table dcl/read btn * Fix many issues related to maillists Notably : edit, delete, selection, creation, registration of players * Set up database version v3 and its migration from v2 + Check versions to choose v1->v2 or v2->v3 * Fix mtt.lua Due to old function getMessages(), replaced by getPlayerInboxMessages() * Add 10 seconds security to mtt.lua * Fix migrate.lua non-declared variable * Send msg table with string keys in mtt * Better log messages * Add message check * Fix mtt crash * Better syntax in storage.lua * Fix bcc forgotten in mail.send() * Fix mtt issue * Better compatibility for messages storage Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Replace mail.split by builtin func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func in storage.lua * re-add mtt if * luacheck on PR * add check for an ancient issue with missing `to` field * Fix luacheck on storage.lua * Fix luacheck warnings in migrate.lua * Fix luacheck warnings in gui.lua * Fix luacheck (too long lines) in storage.lua * Unused loop values in migrate.lua * Whitespace line in gui.lua * Whitespace line (init.lua) * Whitespace line (api.lua) * Significantly improve maillist behaviour Replace maillist by its players when sending a message List of players separated by , Avoid doublons when editing more than 2 times a maillist * Fix luacheck * Fix table insertions at first index when no needed * Use funcs * Do not add maillist as a new contact when sending a mail * Fix removing elements from tables * Check maillists not added in contacts * storage rewrite wip * storage format docs * refactor ui components * show_compose cleanup * remove unused channel.lua * error -> err * status refactoring * contacts refactoring * maillist refactoring * docs * tests * fix some issues * re-enable migrations * contributors * prefix mail entries in the mod storage * internalize old mail-paths to migration module * add v1 and v2 player db examples and migration test * Ui improvements & fixes Move events code (if fields.x then) to events.lua (instead of inbox.lua), fix tab selection when going backward * Show most recent messages at first (outbox) * unified-inv fix --------- Signed-off-by: Athozus <athozus@gmail.com> Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> Co-authored-by: BuckarooBanzay <BuckarooBanzay@users.noreply.github.com>
2023-03-29 18:25:01 +03:00
end
-- cache for next time
cache[key] = entry
return entry
end
-- entries queued for saving
local save_queued_entries = {}
-- save the storage entry for the player
View sent messages (new database, add maillists) (#26) * Add tabheader & sent formspec * Add show_sent function and show sent messages * Remove comment on selected_idxs test (show_sent) * Add variable to keep the previous tab instead of going back to the first one * Remove index variable verification on mark read/unread buttons since they are necessarily clicked on inbox view * Resize messages table to be aligned with close button at the bottom * Show date time (#27) * Show date in message reading * Fix wrong registered dates Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Rework header layout to add better space for date --------- Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Add insertion of messages into global storage mail.messages.json * Receive player messages from global storage * Add automatic generation of status for a new message (unread) * Mark read/unread/delete a message * Fix messages loading * Show every message received/sent via specific functions * Use global contacts functions and reconfigure add/remove functions * Create mail lists formspec based on contacts * Add deleting contact * Add ability to create mail lists * Fix inability to edit contact * Rework on editing/deletion of contacts/maillists * Add at symbol as prefix on maillists view * Add ability to choose default status (to/cc/bcc) Signed-off-by: Athozus <athozus@gmail.com> * Add ability to add multiples players and choose their default status (to/cc/bcc) * Add ability to use maillist in messages and receive messages from them * Fix repetition of code causing a crash * Avoid multiples occurences of the same messages due to player both in maillist and receivers * Fix selected indexes for inbox/sent Now separated, fixed show_message() func selection of id from table dcl/read btn * Fix many issues related to maillists Notably : edit, delete, selection, creation, registration of players * Set up database version v3 and its migration from v2 + Check versions to choose v1->v2 or v2->v3 * Fix mtt.lua Due to old function getMessages(), replaced by getPlayerInboxMessages() * Add 10 seconds security to mtt.lua * Fix migrate.lua non-declared variable * Send msg table with string keys in mtt * Better log messages * Add message check * Fix mtt crash * Better syntax in storage.lua * Fix bcc forgotten in mail.send() * Fix mtt issue * Better compatibility for messages storage Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Replace mail.split by builtin func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func in storage.lua * re-add mtt if * luacheck on PR * add check for an ancient issue with missing `to` field * Fix luacheck on storage.lua * Fix luacheck warnings in migrate.lua * Fix luacheck warnings in gui.lua * Fix luacheck (too long lines) in storage.lua * Unused loop values in migrate.lua * Whitespace line in gui.lua * Whitespace line (init.lua) * Whitespace line (api.lua) * Significantly improve maillist behaviour Replace maillist by its players when sending a message List of players separated by , Avoid doublons when editing more than 2 times a maillist * Fix luacheck * Fix table insertions at first index when no needed * Use funcs * Do not add maillist as a new contact when sending a mail * Fix removing elements from tables * Check maillists not added in contacts * storage rewrite wip * storage format docs * refactor ui components * show_compose cleanup * remove unused channel.lua * error -> err * status refactoring * contacts refactoring * maillist refactoring * docs * tests * fix some issues * re-enable migrations * contributors * prefix mail entries in the mod storage * internalize old mail-paths to migration module * add v1 and v2 player db examples and migration test * Ui improvements & fixes Move events code (if fields.x then) to events.lua (instead of inbox.lua), fix tab selection when going backward * Show most recent messages at first (outbox) * unified-inv fix --------- Signed-off-by: Athozus <athozus@gmail.com> Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> Co-authored-by: BuckarooBanzay <BuckarooBanzay@users.noreply.github.com>
2023-03-29 18:25:01 +03:00
function mail.set_storage_entry(playername, entry)
local key = STORAGE_PREFIX .. playername
-- cache
cache[key] = entry
-- enqueue for writing
save_queued_entries[key] = entry
View sent messages (new database, add maillists) (#26) * Add tabheader & sent formspec * Add show_sent function and show sent messages * Remove comment on selected_idxs test (show_sent) * Add variable to keep the previous tab instead of going back to the first one * Remove index variable verification on mark read/unread buttons since they are necessarily clicked on inbox view * Resize messages table to be aligned with close button at the bottom * Show date time (#27) * Show date in message reading * Fix wrong registered dates Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Rework header layout to add better space for date --------- Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Add insertion of messages into global storage mail.messages.json * Receive player messages from global storage * Add automatic generation of status for a new message (unread) * Mark read/unread/delete a message * Fix messages loading * Show every message received/sent via specific functions * Use global contacts functions and reconfigure add/remove functions * Create mail lists formspec based on contacts * Add deleting contact * Add ability to create mail lists * Fix inability to edit contact * Rework on editing/deletion of contacts/maillists * Add at symbol as prefix on maillists view * Add ability to choose default status (to/cc/bcc) Signed-off-by: Athozus <athozus@gmail.com> * Add ability to add multiples players and choose their default status (to/cc/bcc) * Add ability to use maillist in messages and receive messages from them * Fix repetition of code causing a crash * Avoid multiples occurences of the same messages due to player both in maillist and receivers * Fix selected indexes for inbox/sent Now separated, fixed show_message() func selection of id from table dcl/read btn * Fix many issues related to maillists Notably : edit, delete, selection, creation, registration of players * Set up database version v3 and its migration from v2 + Check versions to choose v1->v2 or v2->v3 * Fix mtt.lua Due to old function getMessages(), replaced by getPlayerInboxMessages() * Add 10 seconds security to mtt.lua * Fix migrate.lua non-declared variable * Send msg table with string keys in mtt * Better log messages * Add message check * Fix mtt crash * Better syntax in storage.lua * Fix bcc forgotten in mail.send() * Fix mtt issue * Better compatibility for messages storage Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Replace mail.split by builtin func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func in storage.lua * re-add mtt if * luacheck on PR * add check for an ancient issue with missing `to` field * Fix luacheck on storage.lua * Fix luacheck warnings in migrate.lua * Fix luacheck warnings in gui.lua * Fix luacheck (too long lines) in storage.lua * Unused loop values in migrate.lua * Whitespace line in gui.lua * Whitespace line (init.lua) * Whitespace line (api.lua) * Significantly improve maillist behaviour Replace maillist by its players when sending a message List of players separated by , Avoid doublons when editing more than 2 times a maillist * Fix luacheck * Fix table insertions at first index when no needed * Use funcs * Do not add maillist as a new contact when sending a mail * Fix removing elements from tables * Check maillists not added in contacts * storage rewrite wip * storage format docs * refactor ui components * show_compose cleanup * remove unused channel.lua * error -> err * status refactoring * contacts refactoring * maillist refactoring * docs * tests * fix some issues * re-enable migrations * contributors * prefix mail entries in the mod storage * internalize old mail-paths to migration module * add v1 and v2 player db examples and migration test * Ui improvements & fixes Move events code (if fields.x then) to events.lua (instead of inbox.lua), fix tab selection when going backward * Show most recent messages at first (outbox) * unified-inv fix --------- Signed-off-by: Athozus <athozus@gmail.com> Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> Co-authored-by: BuckarooBanzay <BuckarooBanzay@users.noreply.github.com>
2023-03-29 18:25:01 +03:00
end
local function save_worker()
for key, entry in pairs(save_queued_entries) do
-- write to backend
mail.storage:set_string(key, minetest.write_json(entry))
end
-- clear queue
save_queued_entries = {}
-- clear cached entries
cache = {}
-- save every second
minetest.after(1, save_worker)
end
-- start save-worker loop
save_worker()
-- save on shutdown
minetest.register_on_shutdown(save_worker)
View sent messages (new database, add maillists) (#26) * Add tabheader & sent formspec * Add show_sent function and show sent messages * Remove comment on selected_idxs test (show_sent) * Add variable to keep the previous tab instead of going back to the first one * Remove index variable verification on mark read/unread buttons since they are necessarily clicked on inbox view * Resize messages table to be aligned with close button at the bottom * Show date time (#27) * Show date in message reading * Fix wrong registered dates Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Rework header layout to add better space for date --------- Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Add insertion of messages into global storage mail.messages.json * Receive player messages from global storage * Add automatic generation of status for a new message (unread) * Mark read/unread/delete a message * Fix messages loading * Show every message received/sent via specific functions * Use global contacts functions and reconfigure add/remove functions * Create mail lists formspec based on contacts * Add deleting contact * Add ability to create mail lists * Fix inability to edit contact * Rework on editing/deletion of contacts/maillists * Add at symbol as prefix on maillists view * Add ability to choose default status (to/cc/bcc) Signed-off-by: Athozus <athozus@gmail.com> * Add ability to add multiples players and choose their default status (to/cc/bcc) * Add ability to use maillist in messages and receive messages from them * Fix repetition of code causing a crash * Avoid multiples occurences of the same messages due to player both in maillist and receivers * Fix selected indexes for inbox/sent Now separated, fixed show_message() func selection of id from table dcl/read btn * Fix many issues related to maillists Notably : edit, delete, selection, creation, registration of players * Set up database version v3 and its migration from v2 + Check versions to choose v1->v2 or v2->v3 * Fix mtt.lua Due to old function getMessages(), replaced by getPlayerInboxMessages() * Add 10 seconds security to mtt.lua * Fix migrate.lua non-declared variable * Send msg table with string keys in mtt * Better log messages * Add message check * Fix mtt crash * Better syntax in storage.lua * Fix bcc forgotten in mail.send() * Fix mtt issue * Better compatibility for messages storage Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Replace mail.split by builtin func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func in storage.lua * re-add mtt if * luacheck on PR * add check for an ancient issue with missing `to` field * Fix luacheck on storage.lua * Fix luacheck warnings in migrate.lua * Fix luacheck warnings in gui.lua * Fix luacheck (too long lines) in storage.lua * Unused loop values in migrate.lua * Whitespace line in gui.lua * Whitespace line (init.lua) * Whitespace line (api.lua) * Significantly improve maillist behaviour Replace maillist by its players when sending a message List of players separated by , Avoid doublons when editing more than 2 times a maillist * Fix luacheck * Fix table insertions at first index when no needed * Use funcs * Do not add maillist as a new contact when sending a mail * Fix removing elements from tables * Check maillists not added in contacts * storage rewrite wip * storage format docs * refactor ui components * show_compose cleanup * remove unused channel.lua * error -> err * status refactoring * contacts refactoring * maillist refactoring * docs * tests * fix some issues * re-enable migrations * contributors * prefix mail entries in the mod storage * internalize old mail-paths to migration module * add v1 and v2 player db examples and migration test * Ui improvements & fixes Move events code (if fields.x then) to events.lua (instead of inbox.lua), fix tab selection when going backward * Show most recent messages at first (outbox) * unified-inv fix --------- Signed-off-by: Athozus <athozus@gmail.com> Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> Co-authored-by: BuckarooBanzay <BuckarooBanzay@users.noreply.github.com>
2023-03-29 18:25:01 +03:00
-- get a mail by id from the players in- or outbox
function mail.get_message(playername, msg_id)
local entry = mail.get_storage_entry(playername)
for _, msg in ipairs(entry.inbox) do
if msg.id == msg_id then
return msg
2022-08-06 21:23:35 +03:00
end
View sent messages (new database, add maillists) (#26) * Add tabheader & sent formspec * Add show_sent function and show sent messages * Remove comment on selected_idxs test (show_sent) * Add variable to keep the previous tab instead of going back to the first one * Remove index variable verification on mark read/unread buttons since they are necessarily clicked on inbox view * Resize messages table to be aligned with close button at the bottom * Show date time (#27) * Show date in message reading * Fix wrong registered dates Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Rework header layout to add better space for date --------- Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Add insertion of messages into global storage mail.messages.json * Receive player messages from global storage * Add automatic generation of status for a new message (unread) * Mark read/unread/delete a message * Fix messages loading * Show every message received/sent via specific functions * Use global contacts functions and reconfigure add/remove functions * Create mail lists formspec based on contacts * Add deleting contact * Add ability to create mail lists * Fix inability to edit contact * Rework on editing/deletion of contacts/maillists * Add at symbol as prefix on maillists view * Add ability to choose default status (to/cc/bcc) Signed-off-by: Athozus <athozus@gmail.com> * Add ability to add multiples players and choose their default status (to/cc/bcc) * Add ability to use maillist in messages and receive messages from them * Fix repetition of code causing a crash * Avoid multiples occurences of the same messages due to player both in maillist and receivers * Fix selected indexes for inbox/sent Now separated, fixed show_message() func selection of id from table dcl/read btn * Fix many issues related to maillists Notably : edit, delete, selection, creation, registration of players * Set up database version v3 and its migration from v2 + Check versions to choose v1->v2 or v2->v3 * Fix mtt.lua Due to old function getMessages(), replaced by getPlayerInboxMessages() * Add 10 seconds security to mtt.lua * Fix migrate.lua non-declared variable * Send msg table with string keys in mtt * Better log messages * Add message check * Fix mtt crash * Better syntax in storage.lua * Fix bcc forgotten in mail.send() * Fix mtt issue * Better compatibility for messages storage Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Replace mail.split by builtin func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func in storage.lua * re-add mtt if * luacheck on PR * add check for an ancient issue with missing `to` field * Fix luacheck on storage.lua * Fix luacheck warnings in migrate.lua * Fix luacheck warnings in gui.lua * Fix luacheck (too long lines) in storage.lua * Unused loop values in migrate.lua * Whitespace line in gui.lua * Whitespace line (init.lua) * Whitespace line (api.lua) * Significantly improve maillist behaviour Replace maillist by its players when sending a message List of players separated by , Avoid doublons when editing more than 2 times a maillist * Fix luacheck * Fix table insertions at first index when no needed * Use funcs * Do not add maillist as a new contact when sending a mail * Fix removing elements from tables * Check maillists not added in contacts * storage rewrite wip * storage format docs * refactor ui components * show_compose cleanup * remove unused channel.lua * error -> err * status refactoring * contacts refactoring * maillist refactoring * docs * tests * fix some issues * re-enable migrations * contributors * prefix mail entries in the mod storage * internalize old mail-paths to migration module * add v1 and v2 player db examples and migration test * Ui improvements & fixes Move events code (if fields.x then) to events.lua (instead of inbox.lua), fix tab selection when going backward * Show most recent messages at first (outbox) * unified-inv fix --------- Signed-off-by: Athozus <athozus@gmail.com> Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> Co-authored-by: BuckarooBanzay <BuckarooBanzay@users.noreply.github.com>
2023-03-29 18:25:01 +03:00
end
for _, msg in ipairs(entry.outbox) do
if msg.id == msg_id then
return msg
end
end
for _, msg in ipairs(entry.drafts) do
if msg.id == msg_id then
return msg
end
end
for _, msg in ipairs(entry.trash) do
if msg.id == msg_id then
return msg
end
end
end
-- get player boxes where a message appears
function mail.get_message_boxes(playername, msg_id)
local entry = mail.get_storage_entry(playername)
local boxes = {}
for _, msg in ipairs(entry.inbox) do
if msg.id == msg_id then
table.insert(boxes, "inbox")
end
end
for _, msg in ipairs(entry.outbox) do
if msg.id == msg_id then
table.insert(boxes, "outbox")
end
end
for _, msg in ipairs(entry.drafts) do
if msg.id == msg_id then
table.insert(boxes, "drafts")
end
end
for _, msg in ipairs(entry.trash) do
if msg.id == msg_id then
table.insert(boxes, "trash")
end
end
return boxes
View sent messages (new database, add maillists) (#26) * Add tabheader & sent formspec * Add show_sent function and show sent messages * Remove comment on selected_idxs test (show_sent) * Add variable to keep the previous tab instead of going back to the first one * Remove index variable verification on mark read/unread buttons since they are necessarily clicked on inbox view * Resize messages table to be aligned with close button at the bottom * Show date time (#27) * Show date in message reading * Fix wrong registered dates Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Rework header layout to add better space for date --------- Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Add insertion of messages into global storage mail.messages.json * Receive player messages from global storage * Add automatic generation of status for a new message (unread) * Mark read/unread/delete a message * Fix messages loading * Show every message received/sent via specific functions * Use global contacts functions and reconfigure add/remove functions * Create mail lists formspec based on contacts * Add deleting contact * Add ability to create mail lists * Fix inability to edit contact * Rework on editing/deletion of contacts/maillists * Add at symbol as prefix on maillists view * Add ability to choose default status (to/cc/bcc) Signed-off-by: Athozus <athozus@gmail.com> * Add ability to add multiples players and choose their default status (to/cc/bcc) * Add ability to use maillist in messages and receive messages from them * Fix repetition of code causing a crash * Avoid multiples occurences of the same messages due to player both in maillist and receivers * Fix selected indexes for inbox/sent Now separated, fixed show_message() func selection of id from table dcl/read btn * Fix many issues related to maillists Notably : edit, delete, selection, creation, registration of players * Set up database version v3 and its migration from v2 + Check versions to choose v1->v2 or v2->v3 * Fix mtt.lua Due to old function getMessages(), replaced by getPlayerInboxMessages() * Add 10 seconds security to mtt.lua * Fix migrate.lua non-declared variable * Send msg table with string keys in mtt * Better log messages * Add message check * Fix mtt crash * Better syntax in storage.lua * Fix bcc forgotten in mail.send() * Fix mtt issue * Better compatibility for messages storage Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Replace mail.split by builtin func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func in storage.lua * re-add mtt if * luacheck on PR * add check for an ancient issue with missing `to` field * Fix luacheck on storage.lua * Fix luacheck warnings in migrate.lua * Fix luacheck warnings in gui.lua * Fix luacheck (too long lines) in storage.lua * Unused loop values in migrate.lua * Whitespace line in gui.lua * Whitespace line (init.lua) * Whitespace line (api.lua) * Significantly improve maillist behaviour Replace maillist by its players when sending a message List of players separated by , Avoid doublons when editing more than 2 times a maillist * Fix luacheck * Fix table insertions at first index when no needed * Use funcs * Do not add maillist as a new contact when sending a mail * Fix removing elements from tables * Check maillists not added in contacts * storage rewrite wip * storage format docs * refactor ui components * show_compose cleanup * remove unused channel.lua * error -> err * status refactoring * contacts refactoring * maillist refactoring * docs * tests * fix some issues * re-enable migrations * contributors * prefix mail entries in the mod storage * internalize old mail-paths to migration module * add v1 and v2 player db examples and migration test * Ui improvements & fixes Move events code (if fields.x then) to events.lua (instead of inbox.lua), fix tab selection when going backward * Show most recent messages at first (outbox) * unified-inv fix --------- Signed-off-by: Athozus <athozus@gmail.com> Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> Co-authored-by: BuckarooBanzay <BuckarooBanzay@users.noreply.github.com>
2023-03-29 18:25:01 +03:00
end
2022-08-06 21:23:35 +03:00
local function safe_find(str, sub)
return str and sub and str:find(sub, 1, true) or nil
end
function mail.sort_messages(messages, sortfield, descending, filter)
local results = {}
-- Filtering
if filter and filter ~= "" then
for _, msg in ipairs(messages) do
if safe_find(msg.from, filter) or safe_find(msg.to, filter) or safe_find(msg.subject, filter) then
table.insert(results, msg)
end
end
else
for i = 1, #messages do
results[i] = messages[i]
end
end
-- Sorting
if sortfield ~= nil then
if descending then
table.sort(results, function(a, b) return a[sortfield] > b[sortfield] end)
else
table.sort(results, function(a, b) return a[sortfield] < b[sortfield] end)
end
end
return results
end
View sent messages (new database, add maillists) (#26) * Add tabheader & sent formspec * Add show_sent function and show sent messages * Remove comment on selected_idxs test (show_sent) * Add variable to keep the previous tab instead of going back to the first one * Remove index variable verification on mark read/unread buttons since they are necessarily clicked on inbox view * Resize messages table to be aligned with close button at the bottom * Show date time (#27) * Show date in message reading * Fix wrong registered dates Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Rework header layout to add better space for date --------- Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Add insertion of messages into global storage mail.messages.json * Receive player messages from global storage * Add automatic generation of status for a new message (unread) * Mark read/unread/delete a message * Fix messages loading * Show every message received/sent via specific functions * Use global contacts functions and reconfigure add/remove functions * Create mail lists formspec based on contacts * Add deleting contact * Add ability to create mail lists * Fix inability to edit contact * Rework on editing/deletion of contacts/maillists * Add at symbol as prefix on maillists view * Add ability to choose default status (to/cc/bcc) Signed-off-by: Athozus <athozus@gmail.com> * Add ability to add multiples players and choose their default status (to/cc/bcc) * Add ability to use maillist in messages and receive messages from them * Fix repetition of code causing a crash * Avoid multiples occurences of the same messages due to player both in maillist and receivers * Fix selected indexes for inbox/sent Now separated, fixed show_message() func selection of id from table dcl/read btn * Fix many issues related to maillists Notably : edit, delete, selection, creation, registration of players * Set up database version v3 and its migration from v2 + Check versions to choose v1->v2 or v2->v3 * Fix mtt.lua Due to old function getMessages(), replaced by getPlayerInboxMessages() * Add 10 seconds security to mtt.lua * Fix migrate.lua non-declared variable * Send msg table with string keys in mtt * Better log messages * Add message check * Fix mtt crash * Better syntax in storage.lua * Fix bcc forgotten in mail.send() * Fix mtt issue * Better compatibility for messages storage Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Replace mail.split by builtin func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func in storage.lua * re-add mtt if * luacheck on PR * add check for an ancient issue with missing `to` field * Fix luacheck on storage.lua * Fix luacheck warnings in migrate.lua * Fix luacheck warnings in gui.lua * Fix luacheck (too long lines) in storage.lua * Unused loop values in migrate.lua * Whitespace line in gui.lua * Whitespace line (init.lua) * Whitespace line (api.lua) * Significantly improve maillist behaviour Replace maillist by its players when sending a message List of players separated by , Avoid doublons when editing more than 2 times a maillist * Fix luacheck * Fix table insertions at first index when no needed * Use funcs * Do not add maillist as a new contact when sending a mail * Fix removing elements from tables * Check maillists not added in contacts * storage rewrite wip * storage format docs * refactor ui components * show_compose cleanup * remove unused channel.lua * error -> err * status refactoring * contacts refactoring * maillist refactoring * docs * tests * fix some issues * re-enable migrations * contributors * prefix mail entries in the mod storage * internalize old mail-paths to migration module * add v1 and v2 player db examples and migration test * Ui improvements & fixes Move events code (if fields.x then) to events.lua (instead of inbox.lua), fix tab selection when going backward * Show most recent messages at first (outbox) * unified-inv fix --------- Signed-off-by: Athozus <athozus@gmail.com> Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> Co-authored-by: BuckarooBanzay <BuckarooBanzay@users.noreply.github.com>
2023-03-29 18:25:01 +03:00
-- marks a mail read by its id
function mail.mark_read(playername, msg_ids)
View sent messages (new database, add maillists) (#26) * Add tabheader & sent formspec * Add show_sent function and show sent messages * Remove comment on selected_idxs test (show_sent) * Add variable to keep the previous tab instead of going back to the first one * Remove index variable verification on mark read/unread buttons since they are necessarily clicked on inbox view * Resize messages table to be aligned with close button at the bottom * Show date time (#27) * Show date in message reading * Fix wrong registered dates Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Rework header layout to add better space for date --------- Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Add insertion of messages into global storage mail.messages.json * Receive player messages from global storage * Add automatic generation of status for a new message (unread) * Mark read/unread/delete a message * Fix messages loading * Show every message received/sent via specific functions * Use global contacts functions and reconfigure add/remove functions * Create mail lists formspec based on contacts * Add deleting contact * Add ability to create mail lists * Fix inability to edit contact * Rework on editing/deletion of contacts/maillists * Add at symbol as prefix on maillists view * Add ability to choose default status (to/cc/bcc) Signed-off-by: Athozus <athozus@gmail.com> * Add ability to add multiples players and choose their default status (to/cc/bcc) * Add ability to use maillist in messages and receive messages from them * Fix repetition of code causing a crash * Avoid multiples occurences of the same messages due to player both in maillist and receivers * Fix selected indexes for inbox/sent Now separated, fixed show_message() func selection of id from table dcl/read btn * Fix many issues related to maillists Notably : edit, delete, selection, creation, registration of players * Set up database version v3 and its migration from v2 + Check versions to choose v1->v2 or v2->v3 * Fix mtt.lua Due to old function getMessages(), replaced by getPlayerInboxMessages() * Add 10 seconds security to mtt.lua * Fix migrate.lua non-declared variable * Send msg table with string keys in mtt * Better log messages * Add message check * Fix mtt crash * Better syntax in storage.lua * Fix bcc forgotten in mail.send() * Fix mtt issue * Better compatibility for messages storage Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Replace mail.split by builtin func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func in storage.lua * re-add mtt if * luacheck on PR * add check for an ancient issue with missing `to` field * Fix luacheck on storage.lua * Fix luacheck warnings in migrate.lua * Fix luacheck warnings in gui.lua * Fix luacheck (too long lines) in storage.lua * Unused loop values in migrate.lua * Whitespace line in gui.lua * Whitespace line (init.lua) * Whitespace line (api.lua) * Significantly improve maillist behaviour Replace maillist by its players when sending a message List of players separated by , Avoid doublons when editing more than 2 times a maillist * Fix luacheck * Fix table insertions at first index when no needed * Use funcs * Do not add maillist as a new contact when sending a mail * Fix removing elements from tables * Check maillists not added in contacts * storage rewrite wip * storage format docs * refactor ui components * show_compose cleanup * remove unused channel.lua * error -> err * status refactoring * contacts refactoring * maillist refactoring * docs * tests * fix some issues * re-enable migrations * contributors * prefix mail entries in the mod storage * internalize old mail-paths to migration module * add v1 and v2 player db examples and migration test * Ui improvements & fixes Move events code (if fields.x then) to events.lua (instead of inbox.lua), fix tab selection when going backward * Show most recent messages at first (outbox) * unified-inv fix --------- Signed-off-by: Athozus <athozus@gmail.com> Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> Co-authored-by: BuckarooBanzay <BuckarooBanzay@users.noreply.github.com>
2023-03-29 18:25:01 +03:00
local entry = mail.get_storage_entry(playername)
if type(msg_ids) ~= "table" then -- if this is not a table
msg_ids = { msg_ids }
end
for _, read_msg_id in ipairs(msg_ids) do
for _, entry_msg in ipairs(entry.inbox) do
if entry_msg.id == read_msg_id then
entry_msg.read = true
end
View sent messages (new database, add maillists) (#26) * Add tabheader & sent formspec * Add show_sent function and show sent messages * Remove comment on selected_idxs test (show_sent) * Add variable to keep the previous tab instead of going back to the first one * Remove index variable verification on mark read/unread buttons since they are necessarily clicked on inbox view * Resize messages table to be aligned with close button at the bottom * Show date time (#27) * Show date in message reading * Fix wrong registered dates Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Rework header layout to add better space for date --------- Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Add insertion of messages into global storage mail.messages.json * Receive player messages from global storage * Add automatic generation of status for a new message (unread) * Mark read/unread/delete a message * Fix messages loading * Show every message received/sent via specific functions * Use global contacts functions and reconfigure add/remove functions * Create mail lists formspec based on contacts * Add deleting contact * Add ability to create mail lists * Fix inability to edit contact * Rework on editing/deletion of contacts/maillists * Add at symbol as prefix on maillists view * Add ability to choose default status (to/cc/bcc) Signed-off-by: Athozus <athozus@gmail.com> * Add ability to add multiples players and choose their default status (to/cc/bcc) * Add ability to use maillist in messages and receive messages from them * Fix repetition of code causing a crash * Avoid multiples occurences of the same messages due to player both in maillist and receivers * Fix selected indexes for inbox/sent Now separated, fixed show_message() func selection of id from table dcl/read btn * Fix many issues related to maillists Notably : edit, delete, selection, creation, registration of players * Set up database version v3 and its migration from v2 + Check versions to choose v1->v2 or v2->v3 * Fix mtt.lua Due to old function getMessages(), replaced by getPlayerInboxMessages() * Add 10 seconds security to mtt.lua * Fix migrate.lua non-declared variable * Send msg table with string keys in mtt * Better log messages * Add message check * Fix mtt crash * Better syntax in storage.lua * Fix bcc forgotten in mail.send() * Fix mtt issue * Better compatibility for messages storage Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Replace mail.split by builtin func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func in storage.lua * re-add mtt if * luacheck on PR * add check for an ancient issue with missing `to` field * Fix luacheck on storage.lua * Fix luacheck warnings in migrate.lua * Fix luacheck warnings in gui.lua * Fix luacheck (too long lines) in storage.lua * Unused loop values in migrate.lua * Whitespace line in gui.lua * Whitespace line (init.lua) * Whitespace line (api.lua) * Significantly improve maillist behaviour Replace maillist by its players when sending a message List of players separated by , Avoid doublons when editing more than 2 times a maillist * Fix luacheck * Fix table insertions at first index when no needed * Use funcs * Do not add maillist as a new contact when sending a mail * Fix removing elements from tables * Check maillists not added in contacts * storage rewrite wip * storage format docs * refactor ui components * show_compose cleanup * remove unused channel.lua * error -> err * status refactoring * contacts refactoring * maillist refactoring * docs * tests * fix some issues * re-enable migrations * contributors * prefix mail entries in the mod storage * internalize old mail-paths to migration module * add v1 and v2 player db examples and migration test * Ui improvements & fixes Move events code (if fields.x then) to events.lua (instead of inbox.lua), fix tab selection when going backward * Show most recent messages at first (outbox) * unified-inv fix --------- Signed-off-by: Athozus <athozus@gmail.com> Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> Co-authored-by: BuckarooBanzay <BuckarooBanzay@users.noreply.github.com>
2023-03-29 18:25:01 +03:00
end
2019-09-16 09:06:54 +03:00
end
mail.set_storage_entry(playername, entry)
mail.hud_update(playername, entry.inbox)
return
View sent messages (new database, add maillists) (#26) * Add tabheader & sent formspec * Add show_sent function and show sent messages * Remove comment on selected_idxs test (show_sent) * Add variable to keep the previous tab instead of going back to the first one * Remove index variable verification on mark read/unread buttons since they are necessarily clicked on inbox view * Resize messages table to be aligned with close button at the bottom * Show date time (#27) * Show date in message reading * Fix wrong registered dates Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Rework header layout to add better space for date --------- Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Add insertion of messages into global storage mail.messages.json * Receive player messages from global storage * Add automatic generation of status for a new message (unread) * Mark read/unread/delete a message * Fix messages loading * Show every message received/sent via specific functions * Use global contacts functions and reconfigure add/remove functions * Create mail lists formspec based on contacts * Add deleting contact * Add ability to create mail lists * Fix inability to edit contact * Rework on editing/deletion of contacts/maillists * Add at symbol as prefix on maillists view * Add ability to choose default status (to/cc/bcc) Signed-off-by: Athozus <athozus@gmail.com> * Add ability to add multiples players and choose their default status (to/cc/bcc) * Add ability to use maillist in messages and receive messages from them * Fix repetition of code causing a crash * Avoid multiples occurences of the same messages due to player both in maillist and receivers * Fix selected indexes for inbox/sent Now separated, fixed show_message() func selection of id from table dcl/read btn * Fix many issues related to maillists Notably : edit, delete, selection, creation, registration of players * Set up database version v3 and its migration from v2 + Check versions to choose v1->v2 or v2->v3 * Fix mtt.lua Due to old function getMessages(), replaced by getPlayerInboxMessages() * Add 10 seconds security to mtt.lua * Fix migrate.lua non-declared variable * Send msg table with string keys in mtt * Better log messages * Add message check * Fix mtt crash * Better syntax in storage.lua * Fix bcc forgotten in mail.send() * Fix mtt issue * Better compatibility for messages storage Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Replace mail.split by builtin func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func in storage.lua * re-add mtt if * luacheck on PR * add check for an ancient issue with missing `to` field * Fix luacheck on storage.lua * Fix luacheck warnings in migrate.lua * Fix luacheck warnings in gui.lua * Fix luacheck (too long lines) in storage.lua * Unused loop values in migrate.lua * Whitespace line in gui.lua * Whitespace line (init.lua) * Whitespace line (api.lua) * Significantly improve maillist behaviour Replace maillist by its players when sending a message List of players separated by , Avoid doublons when editing more than 2 times a maillist * Fix luacheck * Fix table insertions at first index when no needed * Use funcs * Do not add maillist as a new contact when sending a mail * Fix removing elements from tables * Check maillists not added in contacts * storage rewrite wip * storage format docs * refactor ui components * show_compose cleanup * remove unused channel.lua * error -> err * status refactoring * contacts refactoring * maillist refactoring * docs * tests * fix some issues * re-enable migrations * contributors * prefix mail entries in the mod storage * internalize old mail-paths to migration module * add v1 and v2 player db examples and migration test * Ui improvements & fixes Move events code (if fields.x then) to events.lua (instead of inbox.lua), fix tab selection when going backward * Show most recent messages at first (outbox) * unified-inv fix --------- Signed-off-by: Athozus <athozus@gmail.com> Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> Co-authored-by: BuckarooBanzay <BuckarooBanzay@users.noreply.github.com>
2023-03-29 18:25:01 +03:00
end
2019-09-16 09:06:54 +03:00
View sent messages (new database, add maillists) (#26) * Add tabheader & sent formspec * Add show_sent function and show sent messages * Remove comment on selected_idxs test (show_sent) * Add variable to keep the previous tab instead of going back to the first one * Remove index variable verification on mark read/unread buttons since they are necessarily clicked on inbox view * Resize messages table to be aligned with close button at the bottom * Show date time (#27) * Show date in message reading * Fix wrong registered dates Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Rework header layout to add better space for date --------- Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Add insertion of messages into global storage mail.messages.json * Receive player messages from global storage * Add automatic generation of status for a new message (unread) * Mark read/unread/delete a message * Fix messages loading * Show every message received/sent via specific functions * Use global contacts functions and reconfigure add/remove functions * Create mail lists formspec based on contacts * Add deleting contact * Add ability to create mail lists * Fix inability to edit contact * Rework on editing/deletion of contacts/maillists * Add at symbol as prefix on maillists view * Add ability to choose default status (to/cc/bcc) Signed-off-by: Athozus <athozus@gmail.com> * Add ability to add multiples players and choose their default status (to/cc/bcc) * Add ability to use maillist in messages and receive messages from them * Fix repetition of code causing a crash * Avoid multiples occurences of the same messages due to player both in maillist and receivers * Fix selected indexes for inbox/sent Now separated, fixed show_message() func selection of id from table dcl/read btn * Fix many issues related to maillists Notably : edit, delete, selection, creation, registration of players * Set up database version v3 and its migration from v2 + Check versions to choose v1->v2 or v2->v3 * Fix mtt.lua Due to old function getMessages(), replaced by getPlayerInboxMessages() * Add 10 seconds security to mtt.lua * Fix migrate.lua non-declared variable * Send msg table with string keys in mtt * Better log messages * Add message check * Fix mtt crash * Better syntax in storage.lua * Fix bcc forgotten in mail.send() * Fix mtt issue * Better compatibility for messages storage Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Replace mail.split by builtin func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func in storage.lua * re-add mtt if * luacheck on PR * add check for an ancient issue with missing `to` field * Fix luacheck on storage.lua * Fix luacheck warnings in migrate.lua * Fix luacheck warnings in gui.lua * Fix luacheck (too long lines) in storage.lua * Unused loop values in migrate.lua * Whitespace line in gui.lua * Whitespace line (init.lua) * Whitespace line (api.lua) * Significantly improve maillist behaviour Replace maillist by its players when sending a message List of players separated by , Avoid doublons when editing more than 2 times a maillist * Fix luacheck * Fix table insertions at first index when no needed * Use funcs * Do not add maillist as a new contact when sending a mail * Fix removing elements from tables * Check maillists not added in contacts * storage rewrite wip * storage format docs * refactor ui components * show_compose cleanup * remove unused channel.lua * error -> err * status refactoring * contacts refactoring * maillist refactoring * docs * tests * fix some issues * re-enable migrations * contributors * prefix mail entries in the mod storage * internalize old mail-paths to migration module * add v1 and v2 player db examples and migration test * Ui improvements & fixes Move events code (if fields.x then) to events.lua (instead of inbox.lua), fix tab selection when going backward * Show most recent messages at first (outbox) * unified-inv fix --------- Signed-off-by: Athozus <athozus@gmail.com> Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> Co-authored-by: BuckarooBanzay <BuckarooBanzay@users.noreply.github.com>
2023-03-29 18:25:01 +03:00
-- marks a mail unread by its id
function mail.mark_unread(playername, msg_ids)
View sent messages (new database, add maillists) (#26) * Add tabheader & sent formspec * Add show_sent function and show sent messages * Remove comment on selected_idxs test (show_sent) * Add variable to keep the previous tab instead of going back to the first one * Remove index variable verification on mark read/unread buttons since they are necessarily clicked on inbox view * Resize messages table to be aligned with close button at the bottom * Show date time (#27) * Show date in message reading * Fix wrong registered dates Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Rework header layout to add better space for date --------- Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Add insertion of messages into global storage mail.messages.json * Receive player messages from global storage * Add automatic generation of status for a new message (unread) * Mark read/unread/delete a message * Fix messages loading * Show every message received/sent via specific functions * Use global contacts functions and reconfigure add/remove functions * Create mail lists formspec based on contacts * Add deleting contact * Add ability to create mail lists * Fix inability to edit contact * Rework on editing/deletion of contacts/maillists * Add at symbol as prefix on maillists view * Add ability to choose default status (to/cc/bcc) Signed-off-by: Athozus <athozus@gmail.com> * Add ability to add multiples players and choose their default status (to/cc/bcc) * Add ability to use maillist in messages and receive messages from them * Fix repetition of code causing a crash * Avoid multiples occurences of the same messages due to player both in maillist and receivers * Fix selected indexes for inbox/sent Now separated, fixed show_message() func selection of id from table dcl/read btn * Fix many issues related to maillists Notably : edit, delete, selection, creation, registration of players * Set up database version v3 and its migration from v2 + Check versions to choose v1->v2 or v2->v3 * Fix mtt.lua Due to old function getMessages(), replaced by getPlayerInboxMessages() * Add 10 seconds security to mtt.lua * Fix migrate.lua non-declared variable * Send msg table with string keys in mtt * Better log messages * Add message check * Fix mtt crash * Better syntax in storage.lua * Fix bcc forgotten in mail.send() * Fix mtt issue * Better compatibility for messages storage Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Replace mail.split by builtin func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func in storage.lua * re-add mtt if * luacheck on PR * add check for an ancient issue with missing `to` field * Fix luacheck on storage.lua * Fix luacheck warnings in migrate.lua * Fix luacheck warnings in gui.lua * Fix luacheck (too long lines) in storage.lua * Unused loop values in migrate.lua * Whitespace line in gui.lua * Whitespace line (init.lua) * Whitespace line (api.lua) * Significantly improve maillist behaviour Replace maillist by its players when sending a message List of players separated by , Avoid doublons when editing more than 2 times a maillist * Fix luacheck * Fix table insertions at first index when no needed * Use funcs * Do not add maillist as a new contact when sending a mail * Fix removing elements from tables * Check maillists not added in contacts * storage rewrite wip * storage format docs * refactor ui components * show_compose cleanup * remove unused channel.lua * error -> err * status refactoring * contacts refactoring * maillist refactoring * docs * tests * fix some issues * re-enable migrations * contributors * prefix mail entries in the mod storage * internalize old mail-paths to migration module * add v1 and v2 player db examples and migration test * Ui improvements & fixes Move events code (if fields.x then) to events.lua (instead of inbox.lua), fix tab selection when going backward * Show most recent messages at first (outbox) * unified-inv fix --------- Signed-off-by: Athozus <athozus@gmail.com> Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> Co-authored-by: BuckarooBanzay <BuckarooBanzay@users.noreply.github.com>
2023-03-29 18:25:01 +03:00
local entry = mail.get_storage_entry(playername)
if type(msg_ids) ~= "table" then -- if this is not a table
msg_ids = { msg_ids }
end
for _, unread_msg_id in ipairs(msg_ids) do
for _, entry_msg in ipairs(entry.inbox) do
if entry_msg.id == unread_msg_id then
entry_msg.read = false
end
View sent messages (new database, add maillists) (#26) * Add tabheader & sent formspec * Add show_sent function and show sent messages * Remove comment on selected_idxs test (show_sent) * Add variable to keep the previous tab instead of going back to the first one * Remove index variable verification on mark read/unread buttons since they are necessarily clicked on inbox view * Resize messages table to be aligned with close button at the bottom * Show date time (#27) * Show date in message reading * Fix wrong registered dates Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Rework header layout to add better space for date --------- Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Add insertion of messages into global storage mail.messages.json * Receive player messages from global storage * Add automatic generation of status for a new message (unread) * Mark read/unread/delete a message * Fix messages loading * Show every message received/sent via specific functions * Use global contacts functions and reconfigure add/remove functions * Create mail lists formspec based on contacts * Add deleting contact * Add ability to create mail lists * Fix inability to edit contact * Rework on editing/deletion of contacts/maillists * Add at symbol as prefix on maillists view * Add ability to choose default status (to/cc/bcc) Signed-off-by: Athozus <athozus@gmail.com> * Add ability to add multiples players and choose their default status (to/cc/bcc) * Add ability to use maillist in messages and receive messages from them * Fix repetition of code causing a crash * Avoid multiples occurences of the same messages due to player both in maillist and receivers * Fix selected indexes for inbox/sent Now separated, fixed show_message() func selection of id from table dcl/read btn * Fix many issues related to maillists Notably : edit, delete, selection, creation, registration of players * Set up database version v3 and its migration from v2 + Check versions to choose v1->v2 or v2->v3 * Fix mtt.lua Due to old function getMessages(), replaced by getPlayerInboxMessages() * Add 10 seconds security to mtt.lua * Fix migrate.lua non-declared variable * Send msg table with string keys in mtt * Better log messages * Add message check * Fix mtt crash * Better syntax in storage.lua * Fix bcc forgotten in mail.send() * Fix mtt issue * Better compatibility for messages storage Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Replace mail.split by builtin func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func in storage.lua * re-add mtt if * luacheck on PR * add check for an ancient issue with missing `to` field * Fix luacheck on storage.lua * Fix luacheck warnings in migrate.lua * Fix luacheck warnings in gui.lua * Fix luacheck (too long lines) in storage.lua * Unused loop values in migrate.lua * Whitespace line in gui.lua * Whitespace line (init.lua) * Whitespace line (api.lua) * Significantly improve maillist behaviour Replace maillist by its players when sending a message List of players separated by , Avoid doublons when editing more than 2 times a maillist * Fix luacheck * Fix table insertions at first index when no needed * Use funcs * Do not add maillist as a new contact when sending a mail * Fix removing elements from tables * Check maillists not added in contacts * storage rewrite wip * storage format docs * refactor ui components * show_compose cleanup * remove unused channel.lua * error -> err * status refactoring * contacts refactoring * maillist refactoring * docs * tests * fix some issues * re-enable migrations * contributors * prefix mail entries in the mod storage * internalize old mail-paths to migration module * add v1 and v2 player db examples and migration test * Ui improvements & fixes Move events code (if fields.x then) to events.lua (instead of inbox.lua), fix tab selection when going backward * Show most recent messages at first (outbox) * unified-inv fix --------- Signed-off-by: Athozus <athozus@gmail.com> Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> Co-authored-by: BuckarooBanzay <BuckarooBanzay@users.noreply.github.com>
2023-03-29 18:25:01 +03:00
end
end
mail.set_storage_entry(playername, entry)
return
2019-09-16 09:06:54 +03:00
end
-- marks a mail as a spam
function mail.mark_spam(playername, msg_ids)
local entry = mail.get_storage_entry(playername)
if type(msg_ids) ~= "table" then -- if this is not a table
msg_ids = { msg_ids }
end
for _, spam_msg_id in ipairs(msg_ids) do
for _, entry_msg in ipairs(entry.inbox) do
if entry_msg.id == spam_msg_id then
entry_msg.spam = true
end
end
end
mail.set_storage_entry(playername, entry)
return
end
-- marks a mail as a non-spam
function mail.unmark_spam(playername, msg_ids)
local entry = mail.get_storage_entry(playername)
if type(msg_ids) ~= "table" then -- if this is not a table
msg_ids = { msg_ids }
end
for _, unspam_msg_id in ipairs(msg_ids) do
for _, entry_msg in ipairs(entry.inbox) do
if entry_msg.id == unspam_msg_id then
entry_msg.spam = false
end
end
end
mail.set_storage_entry(playername, entry)
return
end
View sent messages (new database, add maillists) (#26) * Add tabheader & sent formspec * Add show_sent function and show sent messages * Remove comment on selected_idxs test (show_sent) * Add variable to keep the previous tab instead of going back to the first one * Remove index variable verification on mark read/unread buttons since they are necessarily clicked on inbox view * Resize messages table to be aligned with close button at the bottom * Show date time (#27) * Show date in message reading * Fix wrong registered dates Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Rework header layout to add better space for date --------- Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Add insertion of messages into global storage mail.messages.json * Receive player messages from global storage * Add automatic generation of status for a new message (unread) * Mark read/unread/delete a message * Fix messages loading * Show every message received/sent via specific functions * Use global contacts functions and reconfigure add/remove functions * Create mail lists formspec based on contacts * Add deleting contact * Add ability to create mail lists * Fix inability to edit contact * Rework on editing/deletion of contacts/maillists * Add at symbol as prefix on maillists view * Add ability to choose default status (to/cc/bcc) Signed-off-by: Athozus <athozus@gmail.com> * Add ability to add multiples players and choose their default status (to/cc/bcc) * Add ability to use maillist in messages and receive messages from them * Fix repetition of code causing a crash * Avoid multiples occurences of the same messages due to player both in maillist and receivers * Fix selected indexes for inbox/sent Now separated, fixed show_message() func selection of id from table dcl/read btn * Fix many issues related to maillists Notably : edit, delete, selection, creation, registration of players * Set up database version v3 and its migration from v2 + Check versions to choose v1->v2 or v2->v3 * Fix mtt.lua Due to old function getMessages(), replaced by getPlayerInboxMessages() * Add 10 seconds security to mtt.lua * Fix migrate.lua non-declared variable * Send msg table with string keys in mtt * Better log messages * Add message check * Fix mtt crash * Better syntax in storage.lua * Fix bcc forgotten in mail.send() * Fix mtt issue * Better compatibility for messages storage Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Replace mail.split by builtin func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func in storage.lua * re-add mtt if * luacheck on PR * add check for an ancient issue with missing `to` field * Fix luacheck on storage.lua * Fix luacheck warnings in migrate.lua * Fix luacheck warnings in gui.lua * Fix luacheck (too long lines) in storage.lua * Unused loop values in migrate.lua * Whitespace line in gui.lua * Whitespace line (init.lua) * Whitespace line (api.lua) * Significantly improve maillist behaviour Replace maillist by its players when sending a message List of players separated by , Avoid doublons when editing more than 2 times a maillist * Fix luacheck * Fix table insertions at first index when no needed * Use funcs * Do not add maillist as a new contact when sending a mail * Fix removing elements from tables * Check maillists not added in contacts * storage rewrite wip * storage format docs * refactor ui components * show_compose cleanup * remove unused channel.lua * error -> err * status refactoring * contacts refactoring * maillist refactoring * docs * tests * fix some issues * re-enable migrations * contributors * prefix mail entries in the mod storage * internalize old mail-paths to migration module * add v1 and v2 player db examples and migration test * Ui improvements & fixes Move events code (if fields.x then) to events.lua (instead of inbox.lua), fix tab selection when going backward * Show most recent messages at first (outbox) * unified-inv fix --------- Signed-off-by: Athozus <athozus@gmail.com> Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> Co-authored-by: BuckarooBanzay <BuckarooBanzay@users.noreply.github.com>
2023-03-29 18:25:01 +03:00
-- deletes a mail by its id
function mail.delete_mail(playername, msg_ids, delete_in_trash)
View sent messages (new database, add maillists) (#26) * Add tabheader & sent formspec * Add show_sent function and show sent messages * Remove comment on selected_idxs test (show_sent) * Add variable to keep the previous tab instead of going back to the first one * Remove index variable verification on mark read/unread buttons since they are necessarily clicked on inbox view * Resize messages table to be aligned with close button at the bottom * Show date time (#27) * Show date in message reading * Fix wrong registered dates Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Rework header layout to add better space for date --------- Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Add insertion of messages into global storage mail.messages.json * Receive player messages from global storage * Add automatic generation of status for a new message (unread) * Mark read/unread/delete a message * Fix messages loading * Show every message received/sent via specific functions * Use global contacts functions and reconfigure add/remove functions * Create mail lists formspec based on contacts * Add deleting contact * Add ability to create mail lists * Fix inability to edit contact * Rework on editing/deletion of contacts/maillists * Add at symbol as prefix on maillists view * Add ability to choose default status (to/cc/bcc) Signed-off-by: Athozus <athozus@gmail.com> * Add ability to add multiples players and choose their default status (to/cc/bcc) * Add ability to use maillist in messages and receive messages from them * Fix repetition of code causing a crash * Avoid multiples occurences of the same messages due to player both in maillist and receivers * Fix selected indexes for inbox/sent Now separated, fixed show_message() func selection of id from table dcl/read btn * Fix many issues related to maillists Notably : edit, delete, selection, creation, registration of players * Set up database version v3 and its migration from v2 + Check versions to choose v1->v2 or v2->v3 * Fix mtt.lua Due to old function getMessages(), replaced by getPlayerInboxMessages() * Add 10 seconds security to mtt.lua * Fix migrate.lua non-declared variable * Send msg table with string keys in mtt * Better log messages * Add message check * Fix mtt crash * Better syntax in storage.lua * Fix bcc forgotten in mail.send() * Fix mtt issue * Better compatibility for messages storage Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Replace mail.split by builtin func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func in storage.lua * re-add mtt if * luacheck on PR * add check for an ancient issue with missing `to` field * Fix luacheck on storage.lua * Fix luacheck warnings in migrate.lua * Fix luacheck warnings in gui.lua * Fix luacheck (too long lines) in storage.lua * Unused loop values in migrate.lua * Whitespace line in gui.lua * Whitespace line (init.lua) * Whitespace line (api.lua) * Significantly improve maillist behaviour Replace maillist by its players when sending a message List of players separated by , Avoid doublons when editing more than 2 times a maillist * Fix luacheck * Fix table insertions at first index when no needed * Use funcs * Do not add maillist as a new contact when sending a mail * Fix removing elements from tables * Check maillists not added in contacts * storage rewrite wip * storage format docs * refactor ui components * show_compose cleanup * remove unused channel.lua * error -> err * status refactoring * contacts refactoring * maillist refactoring * docs * tests * fix some issues * re-enable migrations * contributors * prefix mail entries in the mod storage * internalize old mail-paths to migration module * add v1 and v2 player db examples and migration test * Ui improvements & fixes Move events code (if fields.x then) to events.lua (instead of inbox.lua), fix tab selection when going backward * Show most recent messages at first (outbox) * unified-inv fix --------- Signed-off-by: Athozus <athozus@gmail.com> Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> Co-authored-by: BuckarooBanzay <BuckarooBanzay@users.noreply.github.com>
2023-03-29 18:25:01 +03:00
local entry = mail.get_storage_entry(playername)
if type(msg_ids) ~= "table" then -- if this is not a table
msg_ids = { msg_ids }
end
2023-06-06 08:02:57 +03:00
for i = #entry.inbox, 1, -1 do
for _, deleted_msg in ipairs(msg_ids) do
if entry.inbox[i].id == deleted_msg then
table.remove(entry.inbox, i)
break
end
View sent messages (new database, add maillists) (#26) * Add tabheader & sent formspec * Add show_sent function and show sent messages * Remove comment on selected_idxs test (show_sent) * Add variable to keep the previous tab instead of going back to the first one * Remove index variable verification on mark read/unread buttons since they are necessarily clicked on inbox view * Resize messages table to be aligned with close button at the bottom * Show date time (#27) * Show date in message reading * Fix wrong registered dates Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Rework header layout to add better space for date --------- Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Add insertion of messages into global storage mail.messages.json * Receive player messages from global storage * Add automatic generation of status for a new message (unread) * Mark read/unread/delete a message * Fix messages loading * Show every message received/sent via specific functions * Use global contacts functions and reconfigure add/remove functions * Create mail lists formspec based on contacts * Add deleting contact * Add ability to create mail lists * Fix inability to edit contact * Rework on editing/deletion of contacts/maillists * Add at symbol as prefix on maillists view * Add ability to choose default status (to/cc/bcc) Signed-off-by: Athozus <athozus@gmail.com> * Add ability to add multiples players and choose their default status (to/cc/bcc) * Add ability to use maillist in messages and receive messages from them * Fix repetition of code causing a crash * Avoid multiples occurences of the same messages due to player both in maillist and receivers * Fix selected indexes for inbox/sent Now separated, fixed show_message() func selection of id from table dcl/read btn * Fix many issues related to maillists Notably : edit, delete, selection, creation, registration of players * Set up database version v3 and its migration from v2 + Check versions to choose v1->v2 or v2->v3 * Fix mtt.lua Due to old function getMessages(), replaced by getPlayerInboxMessages() * Add 10 seconds security to mtt.lua * Fix migrate.lua non-declared variable * Send msg table with string keys in mtt * Better log messages * Add message check * Fix mtt crash * Better syntax in storage.lua * Fix bcc forgotten in mail.send() * Fix mtt issue * Better compatibility for messages storage Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Replace mail.split by builtin func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func in storage.lua * re-add mtt if * luacheck on PR * add check for an ancient issue with missing `to` field * Fix luacheck on storage.lua * Fix luacheck warnings in migrate.lua * Fix luacheck warnings in gui.lua * Fix luacheck (too long lines) in storage.lua * Unused loop values in migrate.lua * Whitespace line in gui.lua * Whitespace line (init.lua) * Whitespace line (api.lua) * Significantly improve maillist behaviour Replace maillist by its players when sending a message List of players separated by , Avoid doublons when editing more than 2 times a maillist * Fix luacheck * Fix table insertions at first index when no needed * Use funcs * Do not add maillist as a new contact when sending a mail * Fix removing elements from tables * Check maillists not added in contacts * storage rewrite wip * storage format docs * refactor ui components * show_compose cleanup * remove unused channel.lua * error -> err * status refactoring * contacts refactoring * maillist refactoring * docs * tests * fix some issues * re-enable migrations * contributors * prefix mail entries in the mod storage * internalize old mail-paths to migration module * add v1 and v2 player db examples and migration test * Ui improvements & fixes Move events code (if fields.x then) to events.lua (instead of inbox.lua), fix tab selection when going backward * Show most recent messages at first (outbox) * unified-inv fix --------- Signed-off-by: Athozus <athozus@gmail.com> Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> Co-authored-by: BuckarooBanzay <BuckarooBanzay@users.noreply.github.com>
2023-03-29 18:25:01 +03:00
end
end
2023-06-06 08:02:57 +03:00
for i = #entry.outbox, 1, -1 do
for _, deleted_msg in ipairs(msg_ids) do
if entry.outbox[i].id == deleted_msg then
table.remove(entry.outbox, i)
break
end
View sent messages (new database, add maillists) (#26) * Add tabheader & sent formspec * Add show_sent function and show sent messages * Remove comment on selected_idxs test (show_sent) * Add variable to keep the previous tab instead of going back to the first one * Remove index variable verification on mark read/unread buttons since they are necessarily clicked on inbox view * Resize messages table to be aligned with close button at the bottom * Show date time (#27) * Show date in message reading * Fix wrong registered dates Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Rework header layout to add better space for date --------- Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Add insertion of messages into global storage mail.messages.json * Receive player messages from global storage * Add automatic generation of status for a new message (unread) * Mark read/unread/delete a message * Fix messages loading * Show every message received/sent via specific functions * Use global contacts functions and reconfigure add/remove functions * Create mail lists formspec based on contacts * Add deleting contact * Add ability to create mail lists * Fix inability to edit contact * Rework on editing/deletion of contacts/maillists * Add at symbol as prefix on maillists view * Add ability to choose default status (to/cc/bcc) Signed-off-by: Athozus <athozus@gmail.com> * Add ability to add multiples players and choose their default status (to/cc/bcc) * Add ability to use maillist in messages and receive messages from them * Fix repetition of code causing a crash * Avoid multiples occurences of the same messages due to player both in maillist and receivers * Fix selected indexes for inbox/sent Now separated, fixed show_message() func selection of id from table dcl/read btn * Fix many issues related to maillists Notably : edit, delete, selection, creation, registration of players * Set up database version v3 and its migration from v2 + Check versions to choose v1->v2 or v2->v3 * Fix mtt.lua Due to old function getMessages(), replaced by getPlayerInboxMessages() * Add 10 seconds security to mtt.lua * Fix migrate.lua non-declared variable * Send msg table with string keys in mtt * Better log messages * Add message check * Fix mtt crash * Better syntax in storage.lua * Fix bcc forgotten in mail.send() * Fix mtt issue * Better compatibility for messages storage Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Replace mail.split by builtin func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func in storage.lua * re-add mtt if * luacheck on PR * add check for an ancient issue with missing `to` field * Fix luacheck on storage.lua * Fix luacheck warnings in migrate.lua * Fix luacheck warnings in gui.lua * Fix luacheck (too long lines) in storage.lua * Unused loop values in migrate.lua * Whitespace line in gui.lua * Whitespace line (init.lua) * Whitespace line (api.lua) * Significantly improve maillist behaviour Replace maillist by its players when sending a message List of players separated by , Avoid doublons when editing more than 2 times a maillist * Fix luacheck * Fix table insertions at first index when no needed * Use funcs * Do not add maillist as a new contact when sending a mail * Fix removing elements from tables * Check maillists not added in contacts * storage rewrite wip * storage format docs * refactor ui components * show_compose cleanup * remove unused channel.lua * error -> err * status refactoring * contacts refactoring * maillist refactoring * docs * tests * fix some issues * re-enable migrations * contributors * prefix mail entries in the mod storage * internalize old mail-paths to migration module * add v1 and v2 player db examples and migration test * Ui improvements & fixes Move events code (if fields.x then) to events.lua (instead of inbox.lua), fix tab selection when going backward * Show most recent messages at first (outbox) * unified-inv fix --------- Signed-off-by: Athozus <athozus@gmail.com> Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> Co-authored-by: BuckarooBanzay <BuckarooBanzay@users.noreply.github.com>
2023-03-29 18:25:01 +03:00
end
end
2023-06-06 08:02:57 +03:00
for i = #entry.drafts, 1, -1 do
for _, deleted_msg in ipairs(msg_ids) do
if entry.drafts[i].id == deleted_msg then
table.remove(entry.drafts, i)
break
end
end
end
if delete_in_trash then
for i = #entry.trash, 1, -1 do
for _, deleted_msg in ipairs(msg_ids) do
if entry.trash[i].id == deleted_msg then
table.remove(entry.trash, i)
break
end
end
end
end
mail.set_storage_entry(playername, entry)
mail.hud_update(playername, entry.inbox)
return
end
-- move to trash mails by id
function mail.trash_mail(playername, msg_ids)
local entry = mail.get_storage_entry(playername)
if type(msg_ids) ~= "table" then -- if this is not a table
msg_ids = { msg_ids }
end
for _, id in ipairs(msg_ids) do
local msg = mail.get_message(playername, id)
msg.previous_boxes = mail.get_message_boxes(playername, id)
table.insert(entry.trash, 1, msg)
end
mail.set_storage_entry(playername, entry)
mail.delete_mail(playername, msg_ids)
return
end
-- restore a mail from trash
function mail.restore_mail(playername, msg_id)
local entry = mail.get_storage_entry(playername)
for i, msg in ipairs(entry.trash) do
if msg.id == msg_id then
-- not anymore store previous boxes in json
local previous_boxes = msg.previous_boxes
msg.previous_boxes = nil
-- restore it in all previous boxes
for _, box in ipairs(previous_boxes) do
table.insert(entry[box], msg)
end
-- then delete it from trash
table.remove(entry.trash, i)
end
end
mail.set_storage_entry(playername, entry)
return
View sent messages (new database, add maillists) (#26) * Add tabheader & sent formspec * Add show_sent function and show sent messages * Remove comment on selected_idxs test (show_sent) * Add variable to keep the previous tab instead of going back to the first one * Remove index variable verification on mark read/unread buttons since they are necessarily clicked on inbox view * Resize messages table to be aligned with close button at the bottom * Show date time (#27) * Show date in message reading * Fix wrong registered dates Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Rework header layout to add better space for date --------- Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Add insertion of messages into global storage mail.messages.json * Receive player messages from global storage * Add automatic generation of status for a new message (unread) * Mark read/unread/delete a message * Fix messages loading * Show every message received/sent via specific functions * Use global contacts functions and reconfigure add/remove functions * Create mail lists formspec based on contacts * Add deleting contact * Add ability to create mail lists * Fix inability to edit contact * Rework on editing/deletion of contacts/maillists * Add at symbol as prefix on maillists view * Add ability to choose default status (to/cc/bcc) Signed-off-by: Athozus <athozus@gmail.com> * Add ability to add multiples players and choose their default status (to/cc/bcc) * Add ability to use maillist in messages and receive messages from them * Fix repetition of code causing a crash * Avoid multiples occurences of the same messages due to player both in maillist and receivers * Fix selected indexes for inbox/sent Now separated, fixed show_message() func selection of id from table dcl/read btn * Fix many issues related to maillists Notably : edit, delete, selection, creation, registration of players * Set up database version v3 and its migration from v2 + Check versions to choose v1->v2 or v2->v3 * Fix mtt.lua Due to old function getMessages(), replaced by getPlayerInboxMessages() * Add 10 seconds security to mtt.lua * Fix migrate.lua non-declared variable * Send msg table with string keys in mtt * Better log messages * Add message check * Fix mtt crash * Better syntax in storage.lua * Fix bcc forgotten in mail.send() * Fix mtt issue * Better compatibility for messages storage Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Replace mail.split by builtin func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func in storage.lua * re-add mtt if * luacheck on PR * add check for an ancient issue with missing `to` field * Fix luacheck on storage.lua * Fix luacheck warnings in migrate.lua * Fix luacheck warnings in gui.lua * Fix luacheck (too long lines) in storage.lua * Unused loop values in migrate.lua * Whitespace line in gui.lua * Whitespace line (init.lua) * Whitespace line (api.lua) * Significantly improve maillist behaviour Replace maillist by its players when sending a message List of players separated by , Avoid doublons when editing more than 2 times a maillist * Fix luacheck * Fix table insertions at first index when no needed * Use funcs * Do not add maillist as a new contact when sending a mail * Fix removing elements from tables * Check maillists not added in contacts * storage rewrite wip * storage format docs * refactor ui components * show_compose cleanup * remove unused channel.lua * error -> err * status refactoring * contacts refactoring * maillist refactoring * docs * tests * fix some issues * re-enable migrations * contributors * prefix mail entries in the mod storage * internalize old mail-paths to migration module * add v1 and v2 player db examples and migration test * Ui improvements & fixes Move events code (if fields.x then) to events.lua (instead of inbox.lua), fix tab selection when going backward * Show most recent messages at first (outbox) * unified-inv fix --------- Signed-off-by: Athozus <athozus@gmail.com> Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> Co-authored-by: BuckarooBanzay <BuckarooBanzay@users.noreply.github.com>
2023-03-29 18:25:01 +03:00
end
2023-06-20 00:17:11 +03:00
-- clear the trash
function mail.empty_trash(playername)
local entry = mail.get_storage_entry(playername)
entry.trash = {}
mail.set_storage_entry(playername, entry)
return
end
View sent messages (new database, add maillists) (#26) * Add tabheader & sent formspec * Add show_sent function and show sent messages * Remove comment on selected_idxs test (show_sent) * Add variable to keep the previous tab instead of going back to the first one * Remove index variable verification on mark read/unread buttons since they are necessarily clicked on inbox view * Resize messages table to be aligned with close button at the bottom * Show date time (#27) * Show date in message reading * Fix wrong registered dates Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Rework header layout to add better space for date --------- Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Add insertion of messages into global storage mail.messages.json * Receive player messages from global storage * Add automatic generation of status for a new message (unread) * Mark read/unread/delete a message * Fix messages loading * Show every message received/sent via specific functions * Use global contacts functions and reconfigure add/remove functions * Create mail lists formspec based on contacts * Add deleting contact * Add ability to create mail lists * Fix inability to edit contact * Rework on editing/deletion of contacts/maillists * Add at symbol as prefix on maillists view * Add ability to choose default status (to/cc/bcc) Signed-off-by: Athozus <athozus@gmail.com> * Add ability to add multiples players and choose their default status (to/cc/bcc) * Add ability to use maillist in messages and receive messages from them * Fix repetition of code causing a crash * Avoid multiples occurences of the same messages due to player both in maillist and receivers * Fix selected indexes for inbox/sent Now separated, fixed show_message() func selection of id from table dcl/read btn * Fix many issues related to maillists Notably : edit, delete, selection, creation, registration of players * Set up database version v3 and its migration from v2 + Check versions to choose v1->v2 or v2->v3 * Fix mtt.lua Due to old function getMessages(), replaced by getPlayerInboxMessages() * Add 10 seconds security to mtt.lua * Fix migrate.lua non-declared variable * Send msg table with string keys in mtt * Better log messages * Add message check * Fix mtt crash * Better syntax in storage.lua * Fix bcc forgotten in mail.send() * Fix mtt issue * Better compatibility for messages storage Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Replace mail.split by builtin func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func in storage.lua * re-add mtt if * luacheck on PR * add check for an ancient issue with missing `to` field * Fix luacheck on storage.lua * Fix luacheck warnings in migrate.lua * Fix luacheck warnings in gui.lua * Fix luacheck (too long lines) in storage.lua * Unused loop values in migrate.lua * Whitespace line in gui.lua * Whitespace line (init.lua) * Whitespace line (api.lua) * Significantly improve maillist behaviour Replace maillist by its players when sending a message List of players separated by , Avoid doublons when editing more than 2 times a maillist * Fix luacheck * Fix table insertions at first index when no needed * Use funcs * Do not add maillist as a new contact when sending a mail * Fix removing elements from tables * Check maillists not added in contacts * storage rewrite wip * storage format docs * refactor ui components * show_compose cleanup * remove unused channel.lua * error -> err * status refactoring * contacts refactoring * maillist refactoring * docs * tests * fix some issues * re-enable migrations * contributors * prefix mail entries in the mod storage * internalize old mail-paths to migration module * add v1 and v2 player db examples and migration test * Ui improvements & fixes Move events code (if fields.x then) to events.lua (instead of inbox.lua), fix tab selection when going backward * Show most recent messages at first (outbox) * unified-inv fix --------- Signed-off-by: Athozus <athozus@gmail.com> Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> Co-authored-by: BuckarooBanzay <BuckarooBanzay@users.noreply.github.com>
2023-03-29 18:25:01 +03:00
-- add or update a contact
function mail.update_contact(playername, contact)
local entry = mail.get_storage_entry(playername)
local existing_updated = false
for i, existing_contact in ipairs(entry.contacts) do
if existing_contact.name == contact.name then
-- update
entry.contacts[i] = contact
existing_updated = true
break
end
end
if not existing_updated then
-- insert
table.insert(entry.contacts, contact)
end
mail.set_storage_entry(playername, entry)
end
-- deletes a contact
function mail.delete_contact(playername, contactname)
local entry = mail.get_storage_entry(playername)
for i, existing_contact in ipairs(entry.contacts) do
if existing_contact.name == contactname then
-- delete
table.remove(entry.contacts, i)
mail.set_storage_entry(playername, entry)
return
end
end
end
View sent messages (new database, add maillists) (#26) * Add tabheader & sent formspec * Add show_sent function and show sent messages * Remove comment on selected_idxs test (show_sent) * Add variable to keep the previous tab instead of going back to the first one * Remove index variable verification on mark read/unread buttons since they are necessarily clicked on inbox view * Resize messages table to be aligned with close button at the bottom * Show date time (#27) * Show date in message reading * Fix wrong registered dates Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Rework header layout to add better space for date --------- Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Add insertion of messages into global storage mail.messages.json * Receive player messages from global storage * Add automatic generation of status for a new message (unread) * Mark read/unread/delete a message * Fix messages loading * Show every message received/sent via specific functions * Use global contacts functions and reconfigure add/remove functions * Create mail lists formspec based on contacts * Add deleting contact * Add ability to create mail lists * Fix inability to edit contact * Rework on editing/deletion of contacts/maillists * Add at symbol as prefix on maillists view * Add ability to choose default status (to/cc/bcc) Signed-off-by: Athozus <athozus@gmail.com> * Add ability to add multiples players and choose their default status (to/cc/bcc) * Add ability to use maillist in messages and receive messages from them * Fix repetition of code causing a crash * Avoid multiples occurences of the same messages due to player both in maillist and receivers * Fix selected indexes for inbox/sent Now separated, fixed show_message() func selection of id from table dcl/read btn * Fix many issues related to maillists Notably : edit, delete, selection, creation, registration of players * Set up database version v3 and its migration from v2 + Check versions to choose v1->v2 or v2->v3 * Fix mtt.lua Due to old function getMessages(), replaced by getPlayerInboxMessages() * Add 10 seconds security to mtt.lua * Fix migrate.lua non-declared variable * Send msg table with string keys in mtt * Better log messages * Add message check * Fix mtt crash * Better syntax in storage.lua * Fix bcc forgotten in mail.send() * Fix mtt issue * Better compatibility for messages storage Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Replace mail.split by builtin func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func in storage.lua * re-add mtt if * luacheck on PR * add check for an ancient issue with missing `to` field * Fix luacheck on storage.lua * Fix luacheck warnings in migrate.lua * Fix luacheck warnings in gui.lua * Fix luacheck (too long lines) in storage.lua * Unused loop values in migrate.lua * Whitespace line in gui.lua * Whitespace line (init.lua) * Whitespace line (api.lua) * Significantly improve maillist behaviour Replace maillist by its players when sending a message List of players separated by , Avoid doublons when editing more than 2 times a maillist * Fix luacheck * Fix table insertions at first index when no needed * Use funcs * Do not add maillist as a new contact when sending a mail * Fix removing elements from tables * Check maillists not added in contacts * storage rewrite wip * storage format docs * refactor ui components * show_compose cleanup * remove unused channel.lua * error -> err * status refactoring * contacts refactoring * maillist refactoring * docs * tests * fix some issues * re-enable migrations * contributors * prefix mail entries in the mod storage * internalize old mail-paths to migration module * add v1 and v2 player db examples and migration test * Ui improvements & fixes Move events code (if fields.x then) to events.lua (instead of inbox.lua), fix tab selection when going backward * Show most recent messages at first (outbox) * unified-inv fix --------- Signed-off-by: Athozus <athozus@gmail.com> Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> Co-authored-by: BuckarooBanzay <BuckarooBanzay@users.noreply.github.com>
2023-03-29 18:25:01 +03:00
-- get all contacts
function mail.get_contacts(playername)
local entry = mail.get_storage_entry(playername)
return entry.contacts
end
2023-05-05 14:13:09 +03:00
-- get a contact
function mail.get_contact(playername, contactname)
local entry = mail.get_storage_entry(playername)
for _, existing_contact in ipairs(entry.contacts) do
if existing_contact.name == contactname then
return existing_contact
end
end
return false
end
View sent messages (new database, add maillists) (#26) * Add tabheader & sent formspec * Add show_sent function and show sent messages * Remove comment on selected_idxs test (show_sent) * Add variable to keep the previous tab instead of going back to the first one * Remove index variable verification on mark read/unread buttons since they are necessarily clicked on inbox view * Resize messages table to be aligned with close button at the bottom * Show date time (#27) * Show date in message reading * Fix wrong registered dates Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Rework header layout to add better space for date --------- Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Add insertion of messages into global storage mail.messages.json * Receive player messages from global storage * Add automatic generation of status for a new message (unread) * Mark read/unread/delete a message * Fix messages loading * Show every message received/sent via specific functions * Use global contacts functions and reconfigure add/remove functions * Create mail lists formspec based on contacts * Add deleting contact * Add ability to create mail lists * Fix inability to edit contact * Rework on editing/deletion of contacts/maillists * Add at symbol as prefix on maillists view * Add ability to choose default status (to/cc/bcc) Signed-off-by: Athozus <athozus@gmail.com> * Add ability to add multiples players and choose their default status (to/cc/bcc) * Add ability to use maillist in messages and receive messages from them * Fix repetition of code causing a crash * Avoid multiples occurences of the same messages due to player both in maillist and receivers * Fix selected indexes for inbox/sent Now separated, fixed show_message() func selection of id from table dcl/read btn * Fix many issues related to maillists Notably : edit, delete, selection, creation, registration of players * Set up database version v3 and its migration from v2 + Check versions to choose v1->v2 or v2->v3 * Fix mtt.lua Due to old function getMessages(), replaced by getPlayerInboxMessages() * Add 10 seconds security to mtt.lua * Fix migrate.lua non-declared variable * Send msg table with string keys in mtt * Better log messages * Add message check * Fix mtt crash * Better syntax in storage.lua * Fix bcc forgotten in mail.send() * Fix mtt issue * Better compatibility for messages storage Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Replace mail.split by builtin func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func in storage.lua * re-add mtt if * luacheck on PR * add check for an ancient issue with missing `to` field * Fix luacheck on storage.lua * Fix luacheck warnings in migrate.lua * Fix luacheck warnings in gui.lua * Fix luacheck (too long lines) in storage.lua * Unused loop values in migrate.lua * Whitespace line in gui.lua * Whitespace line (init.lua) * Whitespace line (api.lua) * Significantly improve maillist behaviour Replace maillist by its players when sending a message List of players separated by , Avoid doublons when editing more than 2 times a maillist * Fix luacheck * Fix table insertions at first index when no needed * Use funcs * Do not add maillist as a new contact when sending a mail * Fix removing elements from tables * Check maillists not added in contacts * storage rewrite wip * storage format docs * refactor ui components * show_compose cleanup * remove unused channel.lua * error -> err * status refactoring * contacts refactoring * maillist refactoring * docs * tests * fix some issues * re-enable migrations * contributors * prefix mail entries in the mod storage * internalize old mail-paths to migration module * add v1 and v2 player db examples and migration test * Ui improvements & fixes Move events code (if fields.x then) to events.lua (instead of inbox.lua), fix tab selection when going backward * Show most recent messages at first (outbox) * unified-inv fix --------- Signed-off-by: Athozus <athozus@gmail.com> Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> Co-authored-by: BuckarooBanzay <BuckarooBanzay@users.noreply.github.com>
2023-03-29 18:25:01 +03:00
-- returns the maillists of a player
function mail.get_maillists(playername)
local entry = mail.get_storage_entry(playername)
return entry.lists
end
-- returns the maillists of a player
function mail.get_maillist_by_name(playername, listname)
local entry = mail.get_storage_entry(playername)
for _, list in ipairs(entry.lists) do
if list.name == listname then
return list
end
end
end
-- updates or creates a maillist
function mail.update_maillist(playername, list, old_list_name)
View sent messages (new database, add maillists) (#26) * Add tabheader & sent formspec * Add show_sent function and show sent messages * Remove comment on selected_idxs test (show_sent) * Add variable to keep the previous tab instead of going back to the first one * Remove index variable verification on mark read/unread buttons since they are necessarily clicked on inbox view * Resize messages table to be aligned with close button at the bottom * Show date time (#27) * Show date in message reading * Fix wrong registered dates Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Rework header layout to add better space for date --------- Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Add insertion of messages into global storage mail.messages.json * Receive player messages from global storage * Add automatic generation of status for a new message (unread) * Mark read/unread/delete a message * Fix messages loading * Show every message received/sent via specific functions * Use global contacts functions and reconfigure add/remove functions * Create mail lists formspec based on contacts * Add deleting contact * Add ability to create mail lists * Fix inability to edit contact * Rework on editing/deletion of contacts/maillists * Add at symbol as prefix on maillists view * Add ability to choose default status (to/cc/bcc) Signed-off-by: Athozus <athozus@gmail.com> * Add ability to add multiples players and choose their default status (to/cc/bcc) * Add ability to use maillist in messages and receive messages from them * Fix repetition of code causing a crash * Avoid multiples occurences of the same messages due to player both in maillist and receivers * Fix selected indexes for inbox/sent Now separated, fixed show_message() func selection of id from table dcl/read btn * Fix many issues related to maillists Notably : edit, delete, selection, creation, registration of players * Set up database version v3 and its migration from v2 + Check versions to choose v1->v2 or v2->v3 * Fix mtt.lua Due to old function getMessages(), replaced by getPlayerInboxMessages() * Add 10 seconds security to mtt.lua * Fix migrate.lua non-declared variable * Send msg table with string keys in mtt * Better log messages * Add message check * Fix mtt crash * Better syntax in storage.lua * Fix bcc forgotten in mail.send() * Fix mtt issue * Better compatibility for messages storage Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Replace mail.split by builtin func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func in storage.lua * re-add mtt if * luacheck on PR * add check for an ancient issue with missing `to` field * Fix luacheck on storage.lua * Fix luacheck warnings in migrate.lua * Fix luacheck warnings in gui.lua * Fix luacheck (too long lines) in storage.lua * Unused loop values in migrate.lua * Whitespace line in gui.lua * Whitespace line (init.lua) * Whitespace line (api.lua) * Significantly improve maillist behaviour Replace maillist by its players when sending a message List of players separated by , Avoid doublons when editing more than 2 times a maillist * Fix luacheck * Fix table insertions at first index when no needed * Use funcs * Do not add maillist as a new contact when sending a mail * Fix removing elements from tables * Check maillists not added in contacts * storage rewrite wip * storage format docs * refactor ui components * show_compose cleanup * remove unused channel.lua * error -> err * status refactoring * contacts refactoring * maillist refactoring * docs * tests * fix some issues * re-enable migrations * contributors * prefix mail entries in the mod storage * internalize old mail-paths to migration module * add v1 and v2 player db examples and migration test * Ui improvements & fixes Move events code (if fields.x then) to events.lua (instead of inbox.lua), fix tab selection when going backward * Show most recent messages at first (outbox) * unified-inv fix --------- Signed-off-by: Athozus <athozus@gmail.com> Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> Co-authored-by: BuckarooBanzay <BuckarooBanzay@users.noreply.github.com>
2023-03-29 18:25:01 +03:00
local entry = mail.get_storage_entry(playername)
for i, existing_list in ipairs(entry.lists) do
if existing_list.name == old_list_name then
-- delete
table.remove(entry.lists, i)
View sent messages (new database, add maillists) (#26) * Add tabheader & sent formspec * Add show_sent function and show sent messages * Remove comment on selected_idxs test (show_sent) * Add variable to keep the previous tab instead of going back to the first one * Remove index variable verification on mark read/unread buttons since they are necessarily clicked on inbox view * Resize messages table to be aligned with close button at the bottom * Show date time (#27) * Show date in message reading * Fix wrong registered dates Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Rework header layout to add better space for date --------- Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Add insertion of messages into global storage mail.messages.json * Receive player messages from global storage * Add automatic generation of status for a new message (unread) * Mark read/unread/delete a message * Fix messages loading * Show every message received/sent via specific functions * Use global contacts functions and reconfigure add/remove functions * Create mail lists formspec based on contacts * Add deleting contact * Add ability to create mail lists * Fix inability to edit contact * Rework on editing/deletion of contacts/maillists * Add at symbol as prefix on maillists view * Add ability to choose default status (to/cc/bcc) Signed-off-by: Athozus <athozus@gmail.com> * Add ability to add multiples players and choose their default status (to/cc/bcc) * Add ability to use maillist in messages and receive messages from them * Fix repetition of code causing a crash * Avoid multiples occurences of the same messages due to player both in maillist and receivers * Fix selected indexes for inbox/sent Now separated, fixed show_message() func selection of id from table dcl/read btn * Fix many issues related to maillists Notably : edit, delete, selection, creation, registration of players * Set up database version v3 and its migration from v2 + Check versions to choose v1->v2 or v2->v3 * Fix mtt.lua Due to old function getMessages(), replaced by getPlayerInboxMessages() * Add 10 seconds security to mtt.lua * Fix migrate.lua non-declared variable * Send msg table with string keys in mtt * Better log messages * Add message check * Fix mtt crash * Better syntax in storage.lua * Fix bcc forgotten in mail.send() * Fix mtt issue * Better compatibility for messages storage Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Replace mail.split by builtin func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func in storage.lua * re-add mtt if * luacheck on PR * add check for an ancient issue with missing `to` field * Fix luacheck on storage.lua * Fix luacheck warnings in migrate.lua * Fix luacheck warnings in gui.lua * Fix luacheck (too long lines) in storage.lua * Unused loop values in migrate.lua * Whitespace line in gui.lua * Whitespace line (init.lua) * Whitespace line (api.lua) * Significantly improve maillist behaviour Replace maillist by its players when sending a message List of players separated by , Avoid doublons when editing more than 2 times a maillist * Fix luacheck * Fix table insertions at first index when no needed * Use funcs * Do not add maillist as a new contact when sending a mail * Fix removing elements from tables * Check maillists not added in contacts * storage rewrite wip * storage format docs * refactor ui components * show_compose cleanup * remove unused channel.lua * error -> err * status refactoring * contacts refactoring * maillist refactoring * docs * tests * fix some issues * re-enable migrations * contributors * prefix mail entries in the mod storage * internalize old mail-paths to migration module * add v1 and v2 player db examples and migration test * Ui improvements & fixes Move events code (if fields.x then) to events.lua (instead of inbox.lua), fix tab selection when going backward * Show most recent messages at first (outbox) * unified-inv fix --------- Signed-off-by: Athozus <athozus@gmail.com> Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> Co-authored-by: BuckarooBanzay <BuckarooBanzay@users.noreply.github.com>
2023-03-29 18:25:01 +03:00
break
end
end
-- insert
table.insert(entry.lists, list)
View sent messages (new database, add maillists) (#26) * Add tabheader & sent formspec * Add show_sent function and show sent messages * Remove comment on selected_idxs test (show_sent) * Add variable to keep the previous tab instead of going back to the first one * Remove index variable verification on mark read/unread buttons since they are necessarily clicked on inbox view * Resize messages table to be aligned with close button at the bottom * Show date time (#27) * Show date in message reading * Fix wrong registered dates Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Rework header layout to add better space for date --------- Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Add insertion of messages into global storage mail.messages.json * Receive player messages from global storage * Add automatic generation of status for a new message (unread) * Mark read/unread/delete a message * Fix messages loading * Show every message received/sent via specific functions * Use global contacts functions and reconfigure add/remove functions * Create mail lists formspec based on contacts * Add deleting contact * Add ability to create mail lists * Fix inability to edit contact * Rework on editing/deletion of contacts/maillists * Add at symbol as prefix on maillists view * Add ability to choose default status (to/cc/bcc) Signed-off-by: Athozus <athozus@gmail.com> * Add ability to add multiples players and choose their default status (to/cc/bcc) * Add ability to use maillist in messages and receive messages from them * Fix repetition of code causing a crash * Avoid multiples occurences of the same messages due to player both in maillist and receivers * Fix selected indexes for inbox/sent Now separated, fixed show_message() func selection of id from table dcl/read btn * Fix many issues related to maillists Notably : edit, delete, selection, creation, registration of players * Set up database version v3 and its migration from v2 + Check versions to choose v1->v2 or v2->v3 * Fix mtt.lua Due to old function getMessages(), replaced by getPlayerInboxMessages() * Add 10 seconds security to mtt.lua * Fix migrate.lua non-declared variable * Send msg table with string keys in mtt * Better log messages * Add message check * Fix mtt crash * Better syntax in storage.lua * Fix bcc forgotten in mail.send() * Fix mtt issue * Better compatibility for messages storage Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Replace mail.split by builtin func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func in storage.lua * re-add mtt if * luacheck on PR * add check for an ancient issue with missing `to` field * Fix luacheck on storage.lua * Fix luacheck warnings in migrate.lua * Fix luacheck warnings in gui.lua * Fix luacheck (too long lines) in storage.lua * Unused loop values in migrate.lua * Whitespace line in gui.lua * Whitespace line (init.lua) * Whitespace line (api.lua) * Significantly improve maillist behaviour Replace maillist by its players when sending a message List of players separated by , Avoid doublons when editing more than 2 times a maillist * Fix luacheck * Fix table insertions at first index when no needed * Use funcs * Do not add maillist as a new contact when sending a mail * Fix removing elements from tables * Check maillists not added in contacts * storage rewrite wip * storage format docs * refactor ui components * show_compose cleanup * remove unused channel.lua * error -> err * status refactoring * contacts refactoring * maillist refactoring * docs * tests * fix some issues * re-enable migrations * contributors * prefix mail entries in the mod storage * internalize old mail-paths to migration module * add v1 and v2 player db examples and migration test * Ui improvements & fixes Move events code (if fields.x then) to events.lua (instead of inbox.lua), fix tab selection when going backward * Show most recent messages at first (outbox) * unified-inv fix --------- Signed-off-by: Athozus <athozus@gmail.com> Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> Co-authored-by: BuckarooBanzay <BuckarooBanzay@users.noreply.github.com>
2023-03-29 18:25:01 +03:00
mail.set_storage_entry(playername, entry)
end
function mail.delete_maillist(playername, listname)
local entry = mail.get_storage_entry(playername)
for i, list in ipairs(entry.lists) do
if list.name == listname then
-- delete
table.remove(entry.lists, i)
mail.set_storage_entry(playername, entry)
return
end
end
end
function mail.extractMaillists(receivers_string, maillists_owner)
local receivers = mail.parse_player_list(receivers_string) -- extracted receivers
View sent messages (new database, add maillists) (#26) * Add tabheader & sent formspec * Add show_sent function and show sent messages * Remove comment on selected_idxs test (show_sent) * Add variable to keep the previous tab instead of going back to the first one * Remove index variable verification on mark read/unread buttons since they are necessarily clicked on inbox view * Resize messages table to be aligned with close button at the bottom * Show date time (#27) * Show date in message reading * Fix wrong registered dates Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Rework header layout to add better space for date --------- Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Add insertion of messages into global storage mail.messages.json * Receive player messages from global storage * Add automatic generation of status for a new message (unread) * Mark read/unread/delete a message * Fix messages loading * Show every message received/sent via specific functions * Use global contacts functions and reconfigure add/remove functions * Create mail lists formspec based on contacts * Add deleting contact * Add ability to create mail lists * Fix inability to edit contact * Rework on editing/deletion of contacts/maillists * Add at symbol as prefix on maillists view * Add ability to choose default status (to/cc/bcc) Signed-off-by: Athozus <athozus@gmail.com> * Add ability to add multiples players and choose their default status (to/cc/bcc) * Add ability to use maillist in messages and receive messages from them * Fix repetition of code causing a crash * Avoid multiples occurences of the same messages due to player both in maillist and receivers * Fix selected indexes for inbox/sent Now separated, fixed show_message() func selection of id from table dcl/read btn * Fix many issues related to maillists Notably : edit, delete, selection, creation, registration of players * Set up database version v3 and its migration from v2 + Check versions to choose v1->v2 or v2->v3 * Fix mtt.lua Due to old function getMessages(), replaced by getPlayerInboxMessages() * Add 10 seconds security to mtt.lua * Fix migrate.lua non-declared variable * Send msg table with string keys in mtt * Better log messages * Add message check * Fix mtt crash * Better syntax in storage.lua * Fix bcc forgotten in mail.send() * Fix mtt issue * Better compatibility for messages storage Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Replace mail.split by builtin func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func in storage.lua * re-add mtt if * luacheck on PR * add check for an ancient issue with missing `to` field * Fix luacheck on storage.lua * Fix luacheck warnings in migrate.lua * Fix luacheck warnings in gui.lua * Fix luacheck (too long lines) in storage.lua * Unused loop values in migrate.lua * Whitespace line in gui.lua * Whitespace line (init.lua) * Whitespace line (api.lua) * Significantly improve maillist behaviour Replace maillist by its players when sending a message List of players separated by , Avoid doublons when editing more than 2 times a maillist * Fix luacheck * Fix table insertions at first index when no needed * Use funcs * Do not add maillist as a new contact when sending a mail * Fix removing elements from tables * Check maillists not added in contacts * storage rewrite wip * storage format docs * refactor ui components * show_compose cleanup * remove unused channel.lua * error -> err * status refactoring * contacts refactoring * maillist refactoring * docs * tests * fix some issues * re-enable migrations * contributors * prefix mail entries in the mod storage * internalize old mail-paths to migration module * add v1 and v2 player db examples and migration test * Ui improvements & fixes Move events code (if fields.x then) to events.lua (instead of inbox.lua), fix tab selection when going backward * Show most recent messages at first (outbox) * unified-inv fix --------- Signed-off-by: Athozus <athozus@gmail.com> Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> Co-authored-by: BuckarooBanzay <BuckarooBanzay@users.noreply.github.com>
2023-03-29 18:25:01 +03:00
-- extract players from mailing lists
while string.find(receivers_string, "@") do
local globalReceivers = mail.parse_player_list(receivers_string) -- receivers including maillists
receivers = {}
for _, receiver in ipairs(globalReceivers) do
local receiverInfo = receiver:split("@") -- @maillist
if receiverInfo[1] and receiver == "@" .. receiverInfo[1] then
local maillist = mail.get_maillist_by_name(maillists_owner, receiverInfo[1])
if maillist then
for _, playername in ipairs(maillist.players) do
table.insert(receivers, playername)
end
View sent messages (new database, add maillists) (#26) * Add tabheader & sent formspec * Add show_sent function and show sent messages * Remove comment on selected_idxs test (show_sent) * Add variable to keep the previous tab instead of going back to the first one * Remove index variable verification on mark read/unread buttons since they are necessarily clicked on inbox view * Resize messages table to be aligned with close button at the bottom * Show date time (#27) * Show date in message reading * Fix wrong registered dates Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Rework header layout to add better space for date --------- Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Add insertion of messages into global storage mail.messages.json * Receive player messages from global storage * Add automatic generation of status for a new message (unread) * Mark read/unread/delete a message * Fix messages loading * Show every message received/sent via specific functions * Use global contacts functions and reconfigure add/remove functions * Create mail lists formspec based on contacts * Add deleting contact * Add ability to create mail lists * Fix inability to edit contact * Rework on editing/deletion of contacts/maillists * Add at symbol as prefix on maillists view * Add ability to choose default status (to/cc/bcc) Signed-off-by: Athozus <athozus@gmail.com> * Add ability to add multiples players and choose their default status (to/cc/bcc) * Add ability to use maillist in messages and receive messages from them * Fix repetition of code causing a crash * Avoid multiples occurences of the same messages due to player both in maillist and receivers * Fix selected indexes for inbox/sent Now separated, fixed show_message() func selection of id from table dcl/read btn * Fix many issues related to maillists Notably : edit, delete, selection, creation, registration of players * Set up database version v3 and its migration from v2 + Check versions to choose v1->v2 or v2->v3 * Fix mtt.lua Due to old function getMessages(), replaced by getPlayerInboxMessages() * Add 10 seconds security to mtt.lua * Fix migrate.lua non-declared variable * Send msg table with string keys in mtt * Better log messages * Add message check * Fix mtt crash * Better syntax in storage.lua * Fix bcc forgotten in mail.send() * Fix mtt issue * Better compatibility for messages storage Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Replace mail.split by builtin func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func in storage.lua * re-add mtt if * luacheck on PR * add check for an ancient issue with missing `to` field * Fix luacheck on storage.lua * Fix luacheck warnings in migrate.lua * Fix luacheck warnings in gui.lua * Fix luacheck (too long lines) in storage.lua * Unused loop values in migrate.lua * Whitespace line in gui.lua * Whitespace line (init.lua) * Whitespace line (api.lua) * Significantly improve maillist behaviour Replace maillist by its players when sending a message List of players separated by , Avoid doublons when editing more than 2 times a maillist * Fix luacheck * Fix table insertions at first index when no needed * Use funcs * Do not add maillist as a new contact when sending a mail * Fix removing elements from tables * Check maillists not added in contacts * storage rewrite wip * storage format docs * refactor ui components * show_compose cleanup * remove unused channel.lua * error -> err * status refactoring * contacts refactoring * maillist refactoring * docs * tests * fix some issues * re-enable migrations * contributors * prefix mail entries in the mod storage * internalize old mail-paths to migration module * add v1 and v2 player db examples and migration test * Ui improvements & fixes Move events code (if fields.x then) to events.lua (instead of inbox.lua), fix tab selection when going backward * Show most recent messages at first (outbox) * unified-inv fix --------- Signed-off-by: Athozus <athozus@gmail.com> Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> Co-authored-by: BuckarooBanzay <BuckarooBanzay@users.noreply.github.com>
2023-03-29 18:25:01 +03:00
end
else -- in case of player
table.insert(receivers, receiver)
View sent messages (new database, add maillists) (#26) * Add tabheader & sent formspec * Add show_sent function and show sent messages * Remove comment on selected_idxs test (show_sent) * Add variable to keep the previous tab instead of going back to the first one * Remove index variable verification on mark read/unread buttons since they are necessarily clicked on inbox view * Resize messages table to be aligned with close button at the bottom * Show date time (#27) * Show date in message reading * Fix wrong registered dates Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Rework header layout to add better space for date --------- Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Add insertion of messages into global storage mail.messages.json * Receive player messages from global storage * Add automatic generation of status for a new message (unread) * Mark read/unread/delete a message * Fix messages loading * Show every message received/sent via specific functions * Use global contacts functions and reconfigure add/remove functions * Create mail lists formspec based on contacts * Add deleting contact * Add ability to create mail lists * Fix inability to edit contact * Rework on editing/deletion of contacts/maillists * Add at symbol as prefix on maillists view * Add ability to choose default status (to/cc/bcc) Signed-off-by: Athozus <athozus@gmail.com> * Add ability to add multiples players and choose their default status (to/cc/bcc) * Add ability to use maillist in messages and receive messages from them * Fix repetition of code causing a crash * Avoid multiples occurences of the same messages due to player both in maillist and receivers * Fix selected indexes for inbox/sent Now separated, fixed show_message() func selection of id from table dcl/read btn * Fix many issues related to maillists Notably : edit, delete, selection, creation, registration of players * Set up database version v3 and its migration from v2 + Check versions to choose v1->v2 or v2->v3 * Fix mtt.lua Due to old function getMessages(), replaced by getPlayerInboxMessages() * Add 10 seconds security to mtt.lua * Fix migrate.lua non-declared variable * Send msg table with string keys in mtt * Better log messages * Add message check * Fix mtt crash * Better syntax in storage.lua * Fix bcc forgotten in mail.send() * Fix mtt issue * Better compatibility for messages storage Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Replace mail.split by builtin func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func in storage.lua * re-add mtt if * luacheck on PR * add check for an ancient issue with missing `to` field * Fix luacheck on storage.lua * Fix luacheck warnings in migrate.lua * Fix luacheck warnings in gui.lua * Fix luacheck (too long lines) in storage.lua * Unused loop values in migrate.lua * Whitespace line in gui.lua * Whitespace line (init.lua) * Whitespace line (api.lua) * Significantly improve maillist behaviour Replace maillist by its players when sending a message List of players separated by , Avoid doublons when editing more than 2 times a maillist * Fix luacheck * Fix table insertions at first index when no needed * Use funcs * Do not add maillist as a new contact when sending a mail * Fix removing elements from tables * Check maillists not added in contacts * storage rewrite wip * storage format docs * refactor ui components * show_compose cleanup * remove unused channel.lua * error -> err * status refactoring * contacts refactoring * maillist refactoring * docs * tests * fix some issues * re-enable migrations * contributors * prefix mail entries in the mod storage * internalize old mail-paths to migration module * add v1 and v2 player db examples and migration test * Ui improvements & fixes Move events code (if fields.x then) to events.lua (instead of inbox.lua), fix tab selection when going backward * Show most recent messages at first (outbox) * unified-inv fix --------- Signed-off-by: Athozus <athozus@gmail.com> Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> Co-authored-by: BuckarooBanzay <BuckarooBanzay@users.noreply.github.com>
2023-03-29 18:25:01 +03:00
end
end
receivers_string = mail.concat_player_list(receivers)
View sent messages (new database, add maillists) (#26) * Add tabheader & sent formspec * Add show_sent function and show sent messages * Remove comment on selected_idxs test (show_sent) * Add variable to keep the previous tab instead of going back to the first one * Remove index variable verification on mark read/unread buttons since they are necessarily clicked on inbox view * Resize messages table to be aligned with close button at the bottom * Show date time (#27) * Show date in message reading * Fix wrong registered dates Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Rework header layout to add better space for date --------- Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Add insertion of messages into global storage mail.messages.json * Receive player messages from global storage * Add automatic generation of status for a new message (unread) * Mark read/unread/delete a message * Fix messages loading * Show every message received/sent via specific functions * Use global contacts functions and reconfigure add/remove functions * Create mail lists formspec based on contacts * Add deleting contact * Add ability to create mail lists * Fix inability to edit contact * Rework on editing/deletion of contacts/maillists * Add at symbol as prefix on maillists view * Add ability to choose default status (to/cc/bcc) Signed-off-by: Athozus <athozus@gmail.com> * Add ability to add multiples players and choose their default status (to/cc/bcc) * Add ability to use maillist in messages and receive messages from them * Fix repetition of code causing a crash * Avoid multiples occurences of the same messages due to player both in maillist and receivers * Fix selected indexes for inbox/sent Now separated, fixed show_message() func selection of id from table dcl/read btn * Fix many issues related to maillists Notably : edit, delete, selection, creation, registration of players * Set up database version v3 and its migration from v2 + Check versions to choose v1->v2 or v2->v3 * Fix mtt.lua Due to old function getMessages(), replaced by getPlayerInboxMessages() * Add 10 seconds security to mtt.lua * Fix migrate.lua non-declared variable * Send msg table with string keys in mtt * Better log messages * Add message check * Fix mtt crash * Better syntax in storage.lua * Fix bcc forgotten in mail.send() * Fix mtt issue * Better compatibility for messages storage Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Replace mail.split by builtin func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * Use builtin split func in storage.lua * re-add mtt if * luacheck on PR * add check for an ancient issue with missing `to` field * Fix luacheck on storage.lua * Fix luacheck warnings in migrate.lua * Fix luacheck warnings in gui.lua * Fix luacheck (too long lines) in storage.lua * Unused loop values in migrate.lua * Whitespace line in gui.lua * Whitespace line (init.lua) * Whitespace line (api.lua) * Significantly improve maillist behaviour Replace maillist by its players when sending a message List of players separated by , Avoid doublons when editing more than 2 times a maillist * Fix luacheck * Fix table insertions at first index when no needed * Use funcs * Do not add maillist as a new contact when sending a mail * Fix removing elements from tables * Check maillists not added in contacts * storage rewrite wip * storage format docs * refactor ui components * show_compose cleanup * remove unused channel.lua * error -> err * status refactoring * contacts refactoring * maillist refactoring * docs * tests * fix some issues * re-enable migrations * contributors * prefix mail entries in the mod storage * internalize old mail-paths to migration module * add v1 and v2 player db examples and migration test * Ui improvements & fixes Move events code (if fields.x then) to events.lua (instead of inbox.lua), fix tab selection when going backward * Show most recent messages at first (outbox) * unified-inv fix --------- Signed-off-by: Athozus <athozus@gmail.com> Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> Co-authored-by: BuckarooBanzay <BuckarooBanzay@users.noreply.github.com>
2023-03-29 18:25:01 +03:00
end
return receivers
end
function mail.get_setting_default_value(key)
return mail.settings[key].default
end
function mail.get_setting(playername, key)
local entry = mail.get_storage_entry(playername)
local value = (entry.settings[key] == nil
and {mail.get_setting_default_value(key)}
or {entry.settings[key]})[1]
if mail.settings[key].sync then -- in case this setting is shared with another mod
local sync_value = mail.settings[key].sync(playername) -- get new value
if sync_value then
value = sync_value
mail.set_setting(playername, key, value, true) -- update the setting in mail storage and don't transfer it again
end
end
return value
end
-- add or update a setting
function mail.set_setting(playername, key, value, not_transfer)
local entry = mail.get_storage_entry(playername)
2024-02-01 12:40:24 +03:00
local valid_value = value
if mail.settings[key].check then
valid_value = mail.settings[key].check(playername, value)
end
entry.settings[key] = valid_value
mail.set_storage_entry(playername, entry)
if not not_transfer and mail.settings[key].transfer then -- in case this setting is shared with another mod
2024-02-01 12:40:24 +03:00
mail.settings[key].transfer(playername, valid_value)
end
end
function mail.reset_settings(playername)
local entry = mail.get_storage_entry(playername)
entry.settings = {}
mail.set_storage_entry(playername, entry)
end
2020-10-13 20:20:18 +03:00
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
table.sort(a, f)
local i = 0 -- iterator variable
local iter = function() -- iterator function
i = i + 1
if a[i] == nil then
return nil
else
--return a[i], t[a[i]]
-- add the current position and the length for convenience
return a[i], t[a[i]], i, #a
end
end
return iter
end