Software / code / prosody-modules
Comparison
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 |
comparison
equal
deleted
inserted
replaced
| 5675:eade7ff9f52c | 5676:62c6e17a5e9d |
|---|---|
| 1 local bare_jid = require"util.jid".bare; | 1 local st = require "util.stanza"; |
| 2 local st = require"util.stanza"; | |
| 3 | 2 |
| 4 -- Support both old and new MUC code | 3 module:hook("muc-disco#info", function(event) |
| 5 local mod_muc = module:depends"muc"; | 4 table.insert(event.form, { name = "muc#roomconfig_allowpm"; value = "moderators" }); |
| 6 local rooms = rawget(mod_muc, "rooms"); | 5 end); |
| 7 local get_room_from_jid = rawget(mod_muc, "get_room_from_jid") or | 6 |
| 8 function (jid) | 7 module:hook("muc-private-message", function(event) |
| 9 return rooms[jid]; | 8 local stanza, room = event.stanza, event.room; |
| 9 local from_occupant = room:get_occupant_by_nick(stanza.attr.from); | |
| 10 | |
| 11 if from_occupant and from_occupant.role == "moderator" then | |
| 12 return -- moderators may message anyone | |
| 10 end | 13 end |
| 11 | 14 |
| 12 module:hook("message/full", function(event) | 15 local to_occupant = room:get_occupant_by_nick(stanza.attr.to) |
| 13 local stanza, origin = event.stanza, event.origin; | 16 if to_occupant and to_occupant.role == "moderator" then |
| 14 if stanza.attr.type == "error" then | 17 return -- messaging moderators is ok |
| 15 return | |
| 16 end | 18 end |
| 17 local to, from = stanza.attr.to, stanza.attr.from; | |
| 18 local room = get_room_from_jid(bare_jid(to)); | |
| 19 local to_occupant = room and room._occupants[to]; | |
| 20 local from_occupant = room and room._occupants[room._jid_nick[from]] | |
| 21 if not ( to_occupant and from_occupant ) then return end | |
| 22 | 19 |
| 23 if from_occupant.affiliation then | 20 if to_occupant.bare_jid == from_occupant.bare_jid then |
| 24 to_occupant._pm_block_override = true; | 21 return -- to yourself is okay, used by some clients to sync read state in public channels |
| 25 elseif not from_occupant._pm_block_override then | |
| 26 origin.send(st.error_reply(stanza, "cancel", "not-authorized", "Private messages are disabled")); | |
| 27 return true; | |
| 28 end | 22 end |
| 23 | |
| 24 room:route_to_occupant(from_occupant, st.error_reply(stanza, "cancel", "policy-violation", "Private messages are disabled", room.jid)) | |
| 25 return false; | |
| 29 end, 1); | 26 end, 1); |