Diff

plugins/muc/muc.lib.lua @ 8851:ab5f678f1376

MUC: Support MUC voice requests and approvals in moderated rooms (closes #655) (thanks to Lance Stout)
author Kim Alvefur <zash@zash.se>
date Fri, 20 Oct 2017 05:19:25 +0200
parent 8843:041ddc670934
child 8852:5e98d62f3f9b
line wrap: on
line diff
--- a/plugins/muc/muc.lib.lua	Fri Jun 01 08:47:07 2018 +0200
+++ b/plugins/muc/muc.lib.lua	Fri Oct 20 05:19:25 2017 +0200
@@ -778,6 +778,34 @@
 	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 @@
 			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