Skip to content

Commit

Permalink
Add mute list setting
Browse files Browse the repository at this point in the history
Add sharing between mute_list and beerchat

Add check for mute list
  • Loading branch information
Athozus committed Feb 1, 2024
1 parent e45d564 commit 103c4ae
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 3 deletions.
7 changes: 5 additions & 2 deletions storage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions ui/inbox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 14 additions & 1 deletion ui/message.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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") .. [[]
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions util/colors.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ local generic_colors = {
new = "#00F529",
warning = "#FF8800",
disabled = "#332222",
muted = "#CCCCCC",
}

local function get_base_color(c)
Expand Down
46 changes: 46 additions & 0 deletions util/settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")}
}

Expand All @@ -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

0 comments on commit 103c4ae

Please sign in to comment.