Add mute list setting

Add sharing between mute_list and beerchat

Add check for mute list
This commit is contained in:
Athozus 2023-12-29 22:51:42 +01:00
parent e45d56439f
commit 103c4ae441
5 changed files with 69 additions and 3 deletions

View File

@ -441,8 +441,11 @@ function mail.get_setting(playername, key)
or {entry.settings[key]})[1]
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
mail.set_setting(playername, key, value, false) -- update the setting in mail storage and don't transfer it again
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

View File

@ -103,6 +103,9 @@ function mail.show_inbox(name, sortfieldindex, sortdirection, filter)
if message.spam then
table.insert(displayed_color, "warning")
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] = ","
formspec[#formspec + 1] = minetest.formspec_escape(message.from)

View File

@ -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.8;2.75,1;replyall;]] .. S("Reply all") .. [[]
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,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") .. [[]
@ -145,6 +148,16 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
elseif fields.unmarkspam then
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
if mail.get_setting(name, "trash_move_enable") and mail.selected_idxs.boxtab[name] ~= 4 then
mail.trash_mail(name, message.id)

View File

@ -7,6 +7,7 @@ local generic_colors = {
new = "#00F529",
warning = "#FF8800",
disabled = "#332222",
muted = "#CCCCCC",
}
local function get_base_color(c)

View File

@ -45,11 +45,16 @@ mail.settings = {
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
},
mute_list = {
type = "list", default = {}, group = "spam", index = 1,
label = S("Mute list")
},
}
mail.settings_groups = {
{ name = "notifications", label = S("Notifications")},
{ name = "message_list", label = S("Message list")},
{ name = "spam", label = S("Spam")},
{ name = "other", label = S("Other")}
}
@ -59,3 +64,44 @@ for s, d in pairs(mail.settings) do
mail.selected_idxs["index_" .. s] = {}
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