Software /
code /
prosody-modules
Diff
mod_muc_block_pm/mod_muc_block_pm.lua @ 5676:62c6e17a5e9d
Merge
author | Stephen Paul Weber <singpolyma@singpolyma.net> |
---|---|
date | Mon, 18 Sep 2023 08:24:19 -0500 |
parent | 5617:67f7df9892bb |
line wrap: on
line diff
--- a/mod_muc_block_pm/mod_muc_block_pm.lua Mon Sep 18 08:22:07 2023 -0500 +++ b/mod_muc_block_pm/mod_muc_block_pm.lua Mon Sep 18 08:24:19 2023 -0500 @@ -1,29 +1,26 @@ -local bare_jid = require"util.jid".bare; -local st = require"util.stanza"; +local st = require "util.stanza"; + +module:hook("muc-disco#info", function(event) + table.insert(event.form, { name = "muc#roomconfig_allowpm"; value = "moderators" }); +end); --- Support both old and new MUC code -local mod_muc = module:depends"muc"; -local rooms = rawget(mod_muc, "rooms"); -local get_room_from_jid = rawget(mod_muc, "get_room_from_jid") or - function (jid) - return rooms[jid]; +module:hook("muc-private-message", function(event) + local stanza, room = event.stanza, event.room; + local from_occupant = room:get_occupant_by_nick(stanza.attr.from); + + if from_occupant and from_occupant.role == "moderator" then + return -- moderators may message anyone end -module:hook("message/full", function(event) - local stanza, origin = event.stanza, event.origin; - if stanza.attr.type == "error" then - return + local to_occupant = room:get_occupant_by_nick(stanza.attr.to) + if to_occupant and to_occupant.role == "moderator" then + return -- messaging moderators is ok end - local to, from = stanza.attr.to, stanza.attr.from; - local room = get_room_from_jid(bare_jid(to)); - local to_occupant = room and room._occupants[to]; - local from_occupant = room and room._occupants[room._jid_nick[from]] - if not ( to_occupant and from_occupant ) then return end - if from_occupant.affiliation then - to_occupant._pm_block_override = true; - elseif not from_occupant._pm_block_override then - origin.send(st.error_reply(stanza, "cancel", "not-authorized", "Private messages are disabled")); - return true; + if to_occupant.bare_jid == from_occupant.bare_jid then + return -- to yourself is okay, used by some clients to sync read state in public channels end + + room:route_to_occupant(from_occupant, st.error_reply(stanza, "cancel", "policy-violation", "Private messages are disabled", room.jid)) + return false; end, 1);