annotate mod_muc_block_pm/mod_muc_block_pm.lua @ 5591: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
parents 291a45919988
children e469642e6a6c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5591
c7e532ac6bf7 mod_muc_block_pm: Update to 0.12+ API, use roles instead of affiliations
Kim Alvefur <zash@zash.se>
parents: 4027
diff changeset
1 local st = require "util.stanza";
2588
69d3e0037435 mod_muc_block_pm: Prevent unaffiliated users from sending private messages in MUC
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2
5591
c7e532ac6bf7 mod_muc_block_pm: Update to 0.12+ API, use roles instead of affiliations
Kim Alvefur <zash@zash.se>
parents: 4027
diff changeset
3 module:hook("muc-private-message", function(event)
c7e532ac6bf7 mod_muc_block_pm: Update to 0.12+ API, use roles instead of affiliations
Kim Alvefur <zash@zash.se>
parents: 4027
diff changeset
4 local stanza, room = event.stanza, event.room;
c7e532ac6bf7 mod_muc_block_pm: Update to 0.12+ API, use roles instead of affiliations
Kim Alvefur <zash@zash.se>
parents: 4027
diff changeset
5 local from_occupant = room:get_occupant_by_nick(stanza.attr.from);
c7e532ac6bf7 mod_muc_block_pm: Update to 0.12+ API, use roles instead of affiliations
Kim Alvefur <zash@zash.se>
parents: 4027
diff changeset
6
c7e532ac6bf7 mod_muc_block_pm: Update to 0.12+ API, use roles instead of affiliations
Kim Alvefur <zash@zash.se>
parents: 4027
diff changeset
7 if from_occupant and from_occupant.role == "moderator" then
c7e532ac6bf7 mod_muc_block_pm: Update to 0.12+ API, use roles instead of affiliations
Kim Alvefur <zash@zash.se>
parents: 4027
diff changeset
8 return -- moderators may message anyone
3636
afedc2430b0d mod_muc_block_pm: Add support for Prosody 0.11
JC Brand <jc@opkode.com>
parents: 2588
diff changeset
9 end
2588
69d3e0037435 mod_muc_block_pm: Prevent unaffiliated users from sending private messages in MUC
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10
5591
c7e532ac6bf7 mod_muc_block_pm: Update to 0.12+ API, use roles instead of affiliations
Kim Alvefur <zash@zash.se>
parents: 4027
diff changeset
11 local to_occupant = room:get_occupant_by_nick(stanza.attr.to)
c7e532ac6bf7 mod_muc_block_pm: Update to 0.12+ API, use roles instead of affiliations
Kim Alvefur <zash@zash.se>
parents: 4027
diff changeset
12 if to_occupant and to_occupant.role == "moderator" then
c7e532ac6bf7 mod_muc_block_pm: Update to 0.12+ API, use roles instead of affiliations
Kim Alvefur <zash@zash.se>
parents: 4027
diff changeset
13 return -- messaging moderators is ok
4027
291a45919988 mod_muc_block_pm: Don't respond to error stanzas
JC Brand <jc@opkode.com>
parents: 3636
diff changeset
14 end
2588
69d3e0037435 mod_muc_block_pm: Prevent unaffiliated users from sending private messages in MUC
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15
5591
c7e532ac6bf7 mod_muc_block_pm: Update to 0.12+ API, use roles instead of affiliations
Kim Alvefur <zash@zash.se>
parents: 4027
diff changeset
16 room:route_to_occupant(from_occupant, st.error_reply(stanza, "cancel", "policy-violation", "Private messages are disabled", room.jid))
c7e532ac6bf7 mod_muc_block_pm: Update to 0.12+ API, use roles instead of affiliations
Kim Alvefur <zash@zash.se>
parents: 4027
diff changeset
17 return false;
2588
69d3e0037435 mod_muc_block_pm: Prevent unaffiliated users from sending private messages in MUC
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 end, 1);