Software /
code /
prosody-modules
Comparison
mod_muc_block_pm/mod_muc_block_pm.lua @ 5598:c7e532ac6bf7
mod_muc_block_pm: Update to 0.12+ API, use roles instead of affiliations
The module was possibly broken with 0.12 before.
This changes the behavior to allow only messages to or from moderators.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 12 Jul 2023 15:47:20 +0200 |
parent | 4027:291a45919988 |
child | 5616:e469642e6a6c |
comparison
equal
deleted
inserted
replaced
5597:b681948a01f1 | 5598:c7e532ac6bf7 |
---|---|
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-private-message", function(event) |
5 local mod_muc = module:depends"muc"; | 4 local stanza, room = event.stanza, event.room; |
6 local rooms = rawget(mod_muc, "rooms"); | 5 local from_occupant = room:get_occupant_by_nick(stanza.attr.from); |
7 local get_room_from_jid = rawget(mod_muc, "get_room_from_jid") or | 6 |
8 function (jid) | 7 if from_occupant and from_occupant.role == "moderator" then |
9 return rooms[jid]; | 8 return -- moderators may message anyone |
10 end | 9 end |
11 | 10 |
12 module:hook("message/full", function(event) | 11 local to_occupant = room:get_occupant_by_nick(stanza.attr.to) |
13 local stanza, origin = event.stanza, event.origin; | 12 if to_occupant and to_occupant.role == "moderator" then |
14 if stanza.attr.type == "error" then | 13 return -- messaging moderators is ok |
15 return | |
16 end | 14 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 | 15 |
23 if from_occupant.affiliation then | 16 room:route_to_occupant(from_occupant, st.error_reply(stanza, "cancel", "policy-violation", "Private messages are disabled", room.jid)) |
24 to_occupant._pm_block_override = true; | 17 return false; |
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 | |
29 end, 1); | 18 end, 1); |