# HG changeset patch # User Kim Alvefur # Date 1508471140 -7200 # Node ID f84f566dea58631ca32795ebbecc29d2aeb4a0c5 # Parent 5e98d62f3f9bd0a5e23385aef2046eb06cb56d28 MUC: Reuse the same dataform for voice requests diff -r 5e98d62f3f9b -r f84f566dea58 plugins/muc/moderated.lib.lua --- a/plugins/muc/moderated.lib.lua Fri Oct 20 05:45:03 2017 +0200 +++ b/plugins/muc/moderated.lib.lua Fri Oct 20 05:45:40 2017 +0200 @@ -8,8 +8,6 @@ -- local st = require "util.stanza"; -local dataform = require "util.dataforms"; - local function get_moderated(room) return room._data.moderated; @@ -51,40 +49,13 @@ 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 form = event.room:get_voice_form_layout() + local formdata = { + ["muc#jid"] = event.stanza.attr.from; + ["muc#roomnick"] = event.occupant.nick; + }; - local message = st.message({ type = "normal"; from = event.room.jid }):add_child(form:form()):up(); + local message = st.message({ type = "normal"; from = event.room.jid }):add_child(form:form(formdata)):up(); event.room:broadcast(message, function (_, occupant) return occupant.role == "moderator"; diff -r 5e98d62f3f9b -r f84f566dea58 plugins/muc/muc.lib.lua --- a/plugins/muc/muc.lib.lua Fri Oct 20 05:45:03 2017 +0200 +++ b/plugins/muc/muc.lib.lua Fri Oct 20 05:45:40 2017 +0200 @@ -780,6 +780,7 @@ function room_mt:get_voice_form_layout() -- luacheck: ignore 212/self local form = dataform.new({ + title = "Voice Request"; { name = "FORM_TYPE"; type = "hidden"; @@ -788,18 +789,24 @@ { name = "muc#jid"; type = "jid-single"; + label = "User ID"; }, { name = "muc#roomnick"; type = "text-single"; + label = "Room Nickname"; }, { name = "muc#role"; type = "text-single"; + label = "Requested Role"; + value = "participant"; }, { name = "muc#request_allow"; type = "boolean"; + label = "Grant voice to this person?"; + value = false; } });