diff options
author | Kim Alvefur <zash@zash.se> | 2017-10-20 05:19:25 +0200 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2017-10-20 05:19:25 +0200 |
commit | a0efb3692146c15913fb91d7e47fb742385956a4 (patch) | |
tree | 41cd42d634db1237e0207af6e449be8a20c77c48 /plugins/muc/moderated.lib.lua | |
parent | 19f3e9adb9db9829046503e6594041e54159dbca (diff) | |
download | prosody-a0efb3692146c15913fb91d7e47fb742385956a4.tar.gz prosody-a0efb3692146c15913fb91d7e47fb742385956a4.zip |
MUC: Support MUC voice requests and approvals in moderated rooms (closes #655) (thanks to Lance Stout)
Diffstat (limited to 'plugins/muc/moderated.lib.lua')
-rw-r--r-- | plugins/muc/moderated.lib.lua | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/plugins/muc/moderated.lib.lua b/plugins/muc/moderated.lib.lua index 8354c585..9b435bef 100644 --- a/plugins/muc/moderated.lib.lua +++ b/plugins/muc/moderated.lib.lua @@ -7,6 +7,10 @@ -- COPYING file in the source package for more information. -- +local st = require "util.stanza"; +local dataform = require "util.dataforms"; + + local function get_moderated(room) return room._data.moderated; end @@ -45,6 +49,71 @@ module:hook("muc-get-default-role", function(event) end end, 1); +module:hook("muc-voice-request", function(event) + if event.occupant.role == "visitor" then + local form = dataform.new({ + title = "Voice Request"; + { + name = "FORM_TYPE"; + type = "hidden"; + value = "http://jabber.org/protocol/muc#request"; + }, + { + name = "muc#role"; + type = "text-single"; + label = "Requested Role"; + value = "participant"; + }, + { + name = "muc#jid"; + type = "jid-single"; + label = "User ID"; + value = event.stanza.attr.from; + }, + { + name = "muc#roomnick"; + type = "text-single"; + label = "Room Nickname"; + value = event.occupant.nick; + }, + { + name = "muc#request_allow"; + type = "boolean"; + label = "Grant voice to this person?"; + value = false; + } + }); + + local message = st.message({ type = "normal"; from = event.room.jid }):add_child(form:form()):up(); + + event.room:broadcast(message, function (nick, occupant) + return occupant.role == "moderator"; + end); + end +end); + +module:hook("muc-voice-response", function(event) + local actor = event.stanza.attr.from; + local affected_occupant = event.room:get_occupant_by_real_jid(event.fields["muc#jid"]); + + if event.occupant.role ~= "moderator" then + return; + end + + if not event.fields["muc#request_allow"] then + return; + end + + if not affected_occupant then + return; + end + + if affected_occupant.role == "visitor" then + event.room:set_role(actor, affected_occupant.nick, "participant", "Voice granted"); + end +end); + + return { get = get_moderated; set = set_moderated; |