aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/muc/muc.lib.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2017-10-20 05:19:25 +0200
committerKim Alvefur <zash@zash.se>2017-10-20 05:19:25 +0200
commit7a1e5db391d482820c83a98c3b8b11865c262c37 (patch)
tree41cd42d634db1237e0207af6e449be8a20c77c48 /plugins/muc/muc.lib.lua
parent2a3e98fc42dc817a32c4de6454e7d8945a313ad1 (diff)
downloadprosody-7a1e5db391d482820c83a98c3b8b11865c262c37.tar.gz
prosody-7a1e5db391d482820c83a98c3b8b11865c262c37.zip
MUC: Support MUC voice requests and approvals in moderated rooms (closes #655) (thanks to Lance Stout)
Diffstat (limited to 'plugins/muc/muc.lib.lua')
-rw-r--r--plugins/muc/muc.lib.lua50
1 files changed, 50 insertions, 0 deletions
diff --git a/plugins/muc/muc.lib.lua b/plugins/muc/muc.lib.lua
index 7c3d3af9..83cd9fb5 100644
--- a/plugins/muc/muc.lib.lua
+++ b/plugins/muc/muc.lib.lua
@@ -778,6 +778,34 @@ function room_mt:get_form_layout(actor)
return module:fire_event("muc-config-form", { room = self, actor = actor, form = form }) or form;
end
+function room_mt:get_voice_form_layout()
+ local form = dataform.new({
+ {
+ name = "FORM_TYPE";
+ type = "hidden";
+ value = "http://jabber.org/protocol/muc#request";
+ },
+ {
+ name = "muc#jid";
+ type = "jid-single";
+ },
+ {
+ name = "muc#roomnick";
+ type = "text-single";
+ },
+ {
+ name = "muc#role";
+ type = "text-single";
+ },
+ {
+ name = "muc#request_allow";
+ type = "boolean";
+ }
+ });
+
+ return form;
+end
+
function room_mt:process_form(origin, stanza)
local form = stanza.tags[1]:get_child("x", "jabber:x:data");
if form.attr.type == "cancel" then
@@ -1143,6 +1171,28 @@ function room_mt:handle_message_to_room(origin, stanza)
origin.send(st.error_reply(stanza, "cancel", "bad-request"));
return true;
end
+
+ local form = stanza:get_child("x", "jabber:x:data");
+ if form and form.attr.type == "submit" then
+ local fields, errors, present = self:get_voice_form_layout():data(form);
+
+ if fields.FORM_TYPE == "http://jabber.org/protocol/muc#request" then
+ local occupant = self:get_occupant_by_real_jid(stanza.attr.from);
+ local event = {
+ room = self;
+ origin = origin;
+ stanza = stanza;
+ fields = fields;
+ occupant = occupant;
+ };
+ if occupant.role == "moderator" then
+ module:fire_event("muc-voice-response", event);
+ else
+ module:fire_event("muc-voice-request", event);
+ end
+ return true;
+ end
+ end
end
end