mirror of
https://github.com/mt-mods/mail.git
synced 2025-03-15 06:01:25 +00:00
Add mute list setting
Add sharing between mute_list and beerchat Add check for mute list
This commit is contained in:
parent
e45d56439f
commit
103c4ae441
5 changed files with 69 additions and 3 deletions
|
@ -441,8 +441,11 @@ function mail.get_setting(playername, key)
|
||||||
or {entry.settings[key]})[1]
|
or {entry.settings[key]})[1]
|
||||||
|
|
||||||
if mail.settings[key].sync then -- in case this setting is shared with another mod
|
if mail.settings[key].sync then -- in case this setting is shared with another mod
|
||||||
value = mail.settings[key].sync(playername, key) -- get new value
|
local sync_value = mail.settings[key].sync(playername) -- get new value
|
||||||
mail.set_setting(playername, key, value, false) -- update the setting in mail storage and don't transfer it again
|
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
|
end
|
||||||
|
|
||||||
return value
|
return value
|
||||||
|
|
|
@ -103,6 +103,9 @@ function mail.show_inbox(name, sortfieldindex, sortdirection, filter)
|
||||||
if message.spam then
|
if message.spam then
|
||||||
table.insert(displayed_color, "warning")
|
table.insert(displayed_color, "warning")
|
||||||
end
|
end
|
||||||
|
if table.indexof(mail.get_setting(name, "mute_list"), message.from) >= 1 then
|
||||||
|
table.insert(displayed_color, "muted")
|
||||||
|
end
|
||||||
formspec[#formspec + 1] = "," .. mail.get_color(displayed_color)
|
formspec[#formspec + 1] = "," .. mail.get_color(displayed_color)
|
||||||
formspec[#formspec + 1] = ","
|
formspec[#formspec + 1] = ","
|
||||||
formspec[#formspec + 1] = minetest.formspec_escape(message.from)
|
formspec[#formspec + 1] = minetest.formspec_escape(message.from)
|
||||||
|
|
|
@ -37,10 +37,13 @@ function mail.show_message(name, id)
|
||||||
button[7.25,1.0;2.75,1;reply;]] .. S("Reply") .. [[]
|
button[7.25,1.0;2.75,1;reply;]] .. S("Reply") .. [[]
|
||||||
button[7.25,1.8;2.75,1;replyall;]] .. S("Reply all") .. [[]
|
button[7.25,1.8;2.75,1;replyall;]] .. S("Reply all") .. [[]
|
||||||
button[7.25,2.6;2.75,1;forward;]] .. S("Forward") .. [[]
|
button[7.25,2.6;2.75,1;forward;]] .. S("Forward") .. [[]
|
||||||
|
|
||||||
button[7.25,3.6;2.75,1;markspam;]] .. S("Mark Spam") .. [[]
|
button[7.25,3.6;2.75,1;markspam;]] .. S("Mark Spam") .. [[]
|
||||||
button[7.25,4.4;2.75,1;unmarkspam;]] .. S("Unmark Spam") .. [[]
|
button[7.25,4.4;2.75,1;unmarkspam;]] .. S("Unmark Spam") .. [[]
|
||||||
|
|
||||||
box[7.25,5.4;2.5,4.0;]] .. mail.get_color("disabled") .. [[]
|
button[7.25,5.4;2.75,1;togglemute;]] .. S("(Un)mute sender") .. [[]
|
||||||
|
|
||||||
|
box[7.25,6.4;2.5,3.0;]] .. mail.get_color("disabled") .. [[]
|
||||||
|
|
||||||
button[7.25,9.5;2.75,1;delete;]] .. S("Delete") .. [[]
|
button[7.25,9.5;2.75,1;delete;]] .. S("Delete") .. [[]
|
||||||
|
|
||||||
|
@ -145,6 +148,16 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
elseif fields.unmarkspam then
|
elseif fields.unmarkspam then
|
||||||
mail.unmark_spam(name, message.id)
|
mail.unmark_spam(name, message.id)
|
||||||
|
|
||||||
|
elseif fields.togglemute then
|
||||||
|
local mutes = table.copy(mail.get_setting(name, "mute_list"))
|
||||||
|
local mute_indexof = table.indexof(mutes, message.from)
|
||||||
|
if mute_indexof == -1 then -- mute
|
||||||
|
table.insert(mutes, message.from)
|
||||||
|
else -- unmute
|
||||||
|
table.remove(mutes, mute_indexof)
|
||||||
|
end
|
||||||
|
mail.set_setting(name, "mute_list", mutes)
|
||||||
|
|
||||||
elseif fields.delete then
|
elseif fields.delete then
|
||||||
if mail.get_setting(name, "trash_move_enable") and mail.selected_idxs.boxtab[name] ~= 4 then
|
if mail.get_setting(name, "trash_move_enable") and mail.selected_idxs.boxtab[name] ~= 4 then
|
||||||
mail.trash_mail(name, message.id)
|
mail.trash_mail(name, message.id)
|
||||||
|
|
|
@ -7,6 +7,7 @@ local generic_colors = {
|
||||||
new = "#00F529",
|
new = "#00F529",
|
||||||
warning = "#FF8800",
|
warning = "#FF8800",
|
||||||
disabled = "#332222",
|
disabled = "#332222",
|
||||||
|
muted = "#CCCCCC",
|
||||||
}
|
}
|
||||||
|
|
||||||
local function get_base_color(c)
|
local function get_base_color(c)
|
||||||
|
|
|
@ -45,11 +45,16 @@ mail.settings = {
|
||||||
type = "string", default = "%Y-%m-%d %X", group = "other", index = 3, label = S("Date format"),
|
type = "string", default = "%Y-%m-%d %X", group = "other", index = 3, label = S("Date format"),
|
||||||
dataset = {"%Y-%m-%d %X", "%d/%m/%y %X", "%A %d %B %Y %X"}, format = os.date
|
dataset = {"%Y-%m-%d %X", "%d/%m/%y %X", "%A %d %B %Y %X"}, format = os.date
|
||||||
},
|
},
|
||||||
|
mute_list = {
|
||||||
|
type = "list", default = {}, group = "spam", index = 1,
|
||||||
|
label = S("Mute list")
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
mail.settings_groups = {
|
mail.settings_groups = {
|
||||||
{ name = "notifications", label = S("Notifications")},
|
{ name = "notifications", label = S("Notifications")},
|
||||||
{ name = "message_list", label = S("Message list")},
|
{ name = "message_list", label = S("Message list")},
|
||||||
|
{ name = "spam", label = S("Spam")},
|
||||||
{ name = "other", label = S("Other")}
|
{ name = "other", label = S("Other")}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,3 +64,44 @@ for s, d in pairs(mail.settings) do
|
||||||
mail.selected_idxs["index_" .. s] = {}
|
mail.selected_idxs["index_" .. s] = {}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function mail.settings.mute_list.check(name, value)
|
||||||
|
local valid_players = {}
|
||||||
|
for _, p in ipairs(value) do
|
||||||
|
if p ~= name and minetest.player_exists(p) then
|
||||||
|
table.insert(valid_players, p)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return valid_players
|
||||||
|
end
|
||||||
|
|
||||||
|
function mail.settings.mute_list.sync(name)
|
||||||
|
if minetest.get_modpath("beerchat") then
|
||||||
|
local players = {}
|
||||||
|
for other_player, _ in minetest.get_auth_handler().iterate() do
|
||||||
|
if beerchat.has_player_muted_player(name, other_player) then
|
||||||
|
table.insert(players, other_player)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return players
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
function mail.settings.mute_list.transfer(name, value)
|
||||||
|
if minetest.get_modpath("beerchat") then
|
||||||
|
for other_player, _ in minetest.get_auth_handler().iterate() do -- unmute all
|
||||||
|
if not beerchat.execute_callbacks("before_mute", name, other_player) then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
minetest.get_player_by_name(name):get_meta():set_string(
|
||||||
|
"beerchat:muted:" .. other_player, "")
|
||||||
|
end
|
||||||
|
for _, other_player in ipairs(value) do -- then mute only players in table
|
||||||
|
minetest.get_player_by_name(name):get_meta():set_string(
|
||||||
|
"beerchat:muted:" .. other_player, "true")
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue